• Ragdoll player at 15HP
    3 replies, posted
I'm making a script where when a player reaches 15 HP, they are turned into a ragdoll. How would I do this? Ive got: [CODE]function GAMEMODE:EntityTakeDamage( v, dmginfo ) print("Damage Registered") print(v) if(v:IsPlayer()) then if(v:Health() - dmginfo:GetDamage() < 15) then v.Ragdolled = true if not (v.Ragdolled) then local ragdoll = ents.Create( "prop_ragdoll" ) ragdoll.ragdolledPly = v ragdoll:SetPos( v:GetPos() ) local velocity = v:GetVelocity() ragdoll:SetAngles( v:GetAngles() ) ragdoll:SetModel( v:GetModel() ) ragdoll:Spawn() ragdoll:Activate() v:SetParent( ragdoll ) local j = 1 while true do local phys_obj = ragdoll:GetPhysicsObjectNum( j ) if phys_obj then phys_obj:SetVelocity( velocity ) j = j + 1 else break end end end v:StripWeapons() v:Spectate( OBS_MODE_CHASE ) v:SpectateEntity( ragdoll ) end end return dmginfo end[/CODE] But this is not working. I kill the player but the ragdoll does not appear until I !Slay myself
You are setting "Ragdolled" to true and then creating the ragdoll only IF "Ragdolled" is false. Thats impossible to pass Do Ragdolled = true AFTER you create the ragdoll
[QUOTE=Exho;46378967]You are setting "Ragdolled" to true and then creating the ragdoll only IF "Ragdolled" is false. Thats impossible to pass Do Ragdolled = true AFTER you create the ragdoll[/QUOTE] Thanks, that works perfectly. Now, I can't have the model removed once the player respawns. [CODE]function GAMEMODE:EntityTakeDamage( v, dmginfo ) print("Damage Registered") print(v) if(v:IsPlayer()) then if(v:Health() - dmginfo:GetDamage() < 15) then if not (v.Ragdolled) then local ragdoll = ents.Create( "prop_ragdoll" ) ragdoll.ragdolledPly = v ragdoll:SetPos( v:GetPos() ) local velocity = v:GetVelocity() ragdoll:SetAngles( v:GetAngles() ) ragdoll:SetModel( v:GetModel() ) ragdoll:Spawn() ragdoll:Activate() v:SetParent( ragdoll ) local j = 1 while true do local phys_obj = ragdoll:GetPhysicsObjectNum( j ) if phys_obj then phys_obj:SetVelocity( velocity ) j = j + 1 else break end end end v:StripWeapons() v:AllowFlashlight( false ) v:Spectate( OBS_MODE_CHASE ) v:SpectateEntity( ragdoll ) v.Ragdolled = true end end return dmginfo end function RemoveModel( ply ) ply.Ragdolled = false v:SetParent() v:UnSpectate() v.ragdoll:Remove() end hook.Add("PlayerSpawn", RemoveModel) function Gsd( v ) v:DisallowSpawning( false ) local ragdoll = v.ragdoll if not ragdoll:IsValid() then else local pos = ragdoll:GetPos() pos.z = pos.z + 15 -- So they don't end up in the ground ULib.spawn( v, true ) v:SetPos( pos ) v:SetVelocity( ragdoll:GetVelocity() ) local yaw = ragdoll:GetAngles().yaw v:SetAngles( Angle( 0, yaw, 0 ) ) end return end hook.Add("PlayerDeath", Gsd) [/CODE] Any ideas?
in RemoveModel v doesn't exist, replace it with ply
Sorry, you need to Log In to post a reply to this thread.