[Release] Toggle Ragdoll

roleplay
release
scripting
toggle
ragdoll

#1

So here’s a script that … toggles Ragdoll obviously.
There are 2 versions
One of them require you to type /rag in chat to toggle the script
The other can be toggled by pressing the key (U)

DOWNLOAD

Ragdoll Toggle via key "U"
Ragdoll Toggle via cmd “/rag”

OR

_resource.lua

-- Toggle Ragdoll written by JAF
-- Made for www.lacountyrp.com
-- Version 1.0.0

resource_manifest_version '77731fab-63ca-442c-a67b-abc70f28dfa5'

-- Add a client script 
client_script 'client.lua'

(Toggle Via Key “U”)
client.lua

local ragdoll = false
function setRagdoll(flag)
  ragdoll = flag
end
Citizen.CreateThread(function()
  while true do
    Citizen.Wait(0)
    if ragdoll then
      SetPedToRagdoll(GetPlayerPed(-1), 1000, 1000, 0, 0, 0, 0)
    end
  end
end)

ragdol = true
RegisterNetEvent("Ragdoll")
AddEventHandler("Ragdoll", function()
	if ( ragdol ) then
		setRagdoll(true)
		ragdol = false
	else
		setRagdoll(false)
		ragdol = true
	end
end)

Citizen.CreateThread(function()
 	while true do
 		Citizen.Wait(100)
 		if ( IsControlPressed(2, 303) ) then  --change key here
 			TriggerEvent("Ragdoll", source)
 		end
 	end
end)

(Toggle via command “/rag”)
client.lua

local ragdoll = false
function setRagdoll(flag)
  ragdoll = flag
end
Citizen.CreateThread(function()
  while true do
    Citizen.Wait(0)
    if ragdoll then
      SetPedToRagdoll(GetPlayerPed(-1), 1000, 1000, 0, 0, 0, 0)
    end
  end
end)

ragdol = true
RegisterNetEvent("Ragdoll")
AddEventHandler("Ragdoll", function()
	if ( ragdol ) then
		setRagdoll(true)
		ragdol = false
	else
		setRagdoll(false)
		ragdol = true
	end
end)

RegisterCommand("rag", function(source, args, raw) --change command here
    TriggerEvent("Ragdoll")
end, false) --False, allow everyone to run it(thnx @Havoc)

Enjoy!


#2

Might want to change that :stuck_out_tongue:


#3

yeah hahah thanks for pointing that out


#4

No problem :slight_smile:


#5

i cant use /rag to ragdoll no errors pop up or anything it just doesnt ragdoll me
[edit] nvm how do i unragdoll?
[edit2] nvm found out how sorry about that


#6

How do I add this with the ESX framework? Do I need a __resource.lua file?


#7

what would be the number to be 1 on the number pad to press?


#8

Any way to remove the buttons on the controller from triggering it?


#9

just use the /rag script one that he made.


#10

Is there a List of these keys? I really wanna change it To F6…


#11

Replace the client.lua with the following code…

local ragdoll = false
function setRagdoll(flag)
  ragdoll = flag
end
Citizen.CreateThread(function()
  while true do
    Citizen.Wait(0)
    if ragdoll then
      SetPedToRagdoll(GetPlayerPed(-1), 1000, 1000, 0, 0, 0, 0)
    end
  end
end)

ragdol = true
RegisterNetEvent("Ragdoll")
AddEventHandler("Ragdoll", function()
	if ( ragdol ) then
		setRagdoll(true)
		ragdol = false
	else
		setRagdoll(false)
		ragdol = true
	end
end)

Citizen.CreateThread(function()
 	while true do
 		Citizen.Wait(100)
 		if ( IsControlPressed(2, 167) ) then  --change key here
 			TriggerEvent("Ragdoll", source)
 		end
 	end
end)

I changed it for you.

here is the documentation for fivem controls
https://docs.fivem.net/game-references/controls/