• New to Making Lua, Trying to Spawn Ragdoll
    7 replies, posted
Hey guys. So I'm just trying to make a script where when I press the key H, it spawns a ragdoll and my player turns invisible. Here's my code: local counter = 0 hook.Add("PlayerButtonDown", "FunnyAssRagdoll", function(ply, key) if ply:IsValid() and ply:IsSuperAdmin() then if ply:Alive() then if (key == KEY_H and counter == 0) then  counter = 1 ply:CreateRagdoll() ply:DrawShadow(false) ply:DrawShadow(false) ply:SetMaterial("models/effects/vol_light001") ply:SetRenderMode(RENDERMODE_TRANSALPHA) local activeweapon = ply:GetActiveWeapon() if IsValid(activeweapon) then ply:GetActiveWeapon():SetRenderMode(RENDERMODE_TRANSALPHA) ply:GetActiveWeapon():SetMaterial("models/effects/vol_light001") if ply:GetActiveWeapon():GetClass() == "gmod_tool" then ply:DrawWorldModel(false) else ply:DrawWorldModel(true) end end elseif (key == KEY_H and counter == 1) then counter = 0 ply:DrawShadow(true) ply:SetMaterial(" ") ply:SetRenderMode(RENDERMODE_NORMAL) local activeweapon = ply:GetActiveWeapon() if IsValid(activeweapon) then ply:GetActiveWeapon():SetRenderMode(RENDERMODE_NORMAL) ply:GetActiveWeapon():SetMaterial(" ") if ply:GetActiveWeapon():GetClass() == "gmod_tool" then ply:DrawWorldModel(false) else ply:DrawWorldModel(true) end end end else ply:ChatPrint("You're not alive!") end end end) But when I run it and press H, my ragdoll spawns as usual, and I am turned invisible. But so is my ragdoll! I've tried so many things, I tried spawning a ragdoll using ent.Create and it really didn't work doing that lmao. Just spawned a ragdoll with no velocity and in a t-pose. It does everything, like turns on and off, but when the ragdoll spawns and I'm supposed to be invisible, my ragdoll it too. Not sure why. Thanks in advance for any help!
Bump? lol
I'm too inebriated to actually think about this right now so here's my advice: go onto the workshop, search for "ragdoll" and find an addon that looks similar to what you want to do. Unpack/decompile that using gmad and look at the code.
lmao, ight. Thanks tho.
dont bump a thread thats literally 2 HOURS old....
ply:IsValid() -- it's always valid if (key == KEY_H and counter == 0) then elseif (key == KEY_H and counter == 1) then -- this can be optimized, both of this statements have key == KEY_H ply:DrawShadow(false) ply:DrawShadow(false) -- you have this function twice Your ragdoll is invisible because it is parented to player entity, so whenever you change player the ragdoll will have same properties. You don't need to make player invisible, just make ply:CreateRagdoll() and then ply:Spawn() to become player
New to Making Lua Why are all these lua newbs attempting crazy things? Just go watch some of the thousands of youtube videos on GLua then come back? Also, ply:CreateRagdoll is a function used for death, and will only ever spawn ONE ragdoll then delete the previous (P.S. These ragdolls are CLIENTLY created from my knowledge) ALLSOOO, why don't you just use GM/DoPlayerDeath then create your specials after they die, then make it so they cannot respawn by using GM/PlayerDeathThink until it's time too. Also use ents.Create( "prop_ragdoll" ), this way you can make a nice and pretty ragdoll ~:) You can also create a volume light prop after they die, remove collision and place it above the ragdoll.
Im asking myself that every day
Sorry, you need to Log In to post a reply to this thread.