Check if player was run over?

Hey there!

I’m working on a script for a server, and basically what i’m trying to accomplish is:
If a player gets run over by a vehicle, ragdoll for 5 seconds.

But the thing i need is a way to check that the player was hit by a MOVING car. How would i check that?

Thanks!

Something like this should be helpful



hook.Add("OnTakeDamage","CarSMASH", function( dmginfo )
   if dmginfo:GetDamageType( )== 1 and dmginfo:GetAttacker( ):GetClass()=="CAR" and dmginfo:GetAttacker():GetVelocity():Length()>1 then
      --do stuff
   end
end)


If (damagetype is crush damage AND the attacker is the car AND the car’s velocity in length (speed) is greater than 1) then do stuff.

Thanks! Love you lots <3

Leaving the thread open incase i need something.

There’s only one problem, anti prop-kill. because of that, the player wont take damage, and the script will probbably not work right?

The hook should still be called. Your anti kill script probably uses the same hook but returns 0

hmm, then i dont know what’s wrong, because the script doesn’t seem to be working. Before i put print(“test”) in the --do stuff line(obviously i deleted the comment) but it didn’t seem to work.

Try this to see what it looks like.



hook.Add("OnTakeDamage","CarSMASH", function( dmginfo )
   MsgN("Type: "..dmginfo:GetDamageType( ))
   MsgN("Attacker: "..dmginfo:GetAttacker( ):GetClass())
   MsgN("Vel Len: "..dmginfo:GetAttacker():GetVelocity():Length())
end)


tried putting that hook on a blank lua in the autorun folder, still not printing those 3 messages to the console.

That’s weird and someone is having a similar problem. I’ll look into it later today when I have a chance.

[editline]24th September 2013[/editline]

My bad I used the wrong hook. http://wiki.garrysmod.com/page/GM/EntityTakeDamage is what it should be.

Will this work?
[lua]
hook.Add(“EntityTakeDamage”,“CarSMASH”, function( dmginfo )
MsgN("Type: "…dmginfo:GetDamageType( ))
MsgN("Attacker: "…dmginfo:GetAttacker( ):GetClass())
MsgN("Vel Len: "…dmginfo:GetAttacker():GetVelocity():Length())
end)
[/lua]

Timers and hooks are my weaknesses in LUA

Look at the page example, it now returns entity AND damageinfo.
hook.Add(“hook”,“unique name”, function(entity, info) end)

Ah i think i got it. Thanks!

[editline]24th September 2013[/editline]

script is working! But obviously because there is no check if it’s car damage, it print everytime the player gets damaged to the console. Now i guess i need to mess around with the if untill it works!

In my experience there have been a ton of crash issues with ragdolls, be it exploits or mistakes in them moving quickly etc.

i did
[lua]
if dmginfo:GetAttacker( ):GetClass()==“CAR” then
[/lua]
but it’s not working. same if i use the whole 3 checks. Where is the list of classes?

The point of the debug script was to allow you to figure it out. I don’t know what type of “car” you are using, so I can’t help with that.

Yeah i got it working now! Thanks so much for all your help! You deserve a big star <3

Closing the thread