Jump to content

OnPedWasted issue


Sergei

Recommended Posts

Hello.

I have started playing around LUA and MTA recently and I have already got to one problem. I wanted to make that if you kill ped with headshot (bodypart 9) it would take its head of. It has never wanted to work, so I added this little debug line to OnPedWasted callback.

function wastedped(ammo, attacker, weapon, bodypart)
outputChatBox(""..tostring(ammo).." and "..tostring(attacker).." and "..tostring(weapon).." and "..tostring(bodypart).."")
end
addEventHandler("onPedWasted",getRootElement(),wastedped)

It always gets me ammo (0), attacker (userdata: 00000***), weapon (false), bodypart (false). I wonder who it is possible that weapon and bodypart can be false, since it should return integer and not boolean (at least what wiki says)

Regards

Link to comment

Hello.

I have started playing around LUA and MTA recently and I have already got to one problem. I wanted to make that if you kill ped with headshot (bodypart 9) it would take its head of. It has never wanted to work, so I added this little debug line to OnPedWasted callback.

function wastedped(ammo, attacker, weapon, bodypart)
outputChatBox(""..tostring(ammo).." and "..tostring(attacker).." and "..tostring(weapon).." and "..tostring(bodypart).."")
end
addEventHandler("onPedWasted",getRootElement(),wastedped)

It always gets me ammo (0), attacker (userdata: 00000***), weapon (false), bodypart (false). I wonder who it is possible that weapon and bodypart can be false, since it should return integer and not boolean (at least what wiki says)

Regards

Link to comment

Try using the clientside "onClientPedWasted" event instead. The server event may not be passing along the arguments properly, but the clientside event does work correctly and is indeed used for resources such as deathmessages.

Edit: this was incorrect, but I did expect the client event to work with scripted peds. :(

Edited by Guest
Link to comment

Try using the clientside "onClientPedWasted" event instead. The server event may not be passing along the arguments properly, but the clientside event does work correctly and is indeed used for resources such as deathmessages.

Edit: this was incorrect, but I did expect the client event to work with scripted peds. :(

Edited by Guest
Link to comment

If I use onClientPedWasted I still get usless values -> nil, false and false; it should return element and two integers as wiki says :/

function pedwaswasted(killer,weapon,bodypart)
outputDebugString(""..tostring(killerid).." and "..tostring(weapon).." and "..tostring(bodypart).."")
end
addEventHandler("onClientPedWasted",getRootElement(),pedwaswasted)

Link to comment

If I use onClientPedWasted I still get usless values -> nil, false and false; it should return element and two integers as wiki says :/

function pedwaswasted(killer,weapon,bodypart)
outputDebugString(""..tostring(killerid).." and "..tostring(weapon).." and "..tostring(bodypart).."")
end
addEventHandler("onClientPedWasted",getRootElement(),pedwaswasted)

Link to comment

Well "killer" does not match "killerid" so the first return will be nil.

Have you tried testing this on a player or just using createPed? While the function is a ped function, its functionality may only work with other players due to factors such as hit feedback from the client end.

A better test would be either get a second player, or kill yourself with a grenade/car/fall/drowning. They all have their own "weapon" id's, and some may have bodypart ones as well.

You can see some code examples for "onPedWasted" (turns out it works fine :P) in the "killmessages" resource, which you should already have or you can look at it at: http://code.google.com/p/multitheftauto ... lmessages/

Look at the definitions.lua for translating weapon id's (it's got the obscure ones that are not actually weapons that are therefore not listed on the wiki, such as run over by a vehicle or drowning) and killmessages_server.lua for the onPedWasted event handler and called function.

Most of the client code is just handling the GUI display and not relevant to your task.

Link to comment

Well "killer" does not match "killerid" so the first return will be nil.

Have you tried testing this on a player or just using createPed? While the function is a ped function, its functionality may only work with other players due to factors such as hit feedback from the client end.

A better test would be either get a second player, or kill yourself with a grenade/car/fall/drowning. They all have their own "weapon" id's, and some may have bodypart ones as well.

You can see some code examples for "onPedWasted" (turns out it works fine :P) in the "killmessages" resource, which you should already have or you can look at it at: http://code.google.com/p/multitheftauto ... lmessages/

Look at the definitions.lua for translating weapon id's (it's got the obscure ones that are not actually weapons that are therefore not listed on the wiki, such as run over by a vehicle or drowning) and killmessages_server.lua for the onPedWasted event handler and called function.

Most of the client code is just handling the GUI display and not relevant to your task.

Link to comment

I have tried out onClientPedDamage, onClientPedWasted and onPedWasted and it seems that only onClientPedDamage works.

EDIT: Hmm, I have jsut realized that onClientPedDamage gives 'nil' value for source while other parameters are okay.

function clientpeddamage(attacker,weapon,bodypart,loss)
--outputDebugString("onClientPedDamage called! Bodypart:"..tostring(bodypart).." Attacker:"..tostring(attacker).." Weapon:"..tostring(weapon).." Loss:"..tostring(loss).."")
if(bodypart == 9) then
setPedHeadless(source,true)
killPed(source) --ERROR: attempt to call global 'killPed' (a nil value)
end
end
addEventHandler("onClientPedDamage",getRootElement(),clientpeddamage)

Link to comment

I have tried out onClientPedDamage, onClientPedWasted and onPedWasted and it seems that only onClientPedDamage works.

EDIT: Hmm, I have jsut realized that onClientPedDamage gives 'nil' value for source while other parameters are okay.

function clientpeddamage(attacker,weapon,bodypart,loss)
--outputDebugString("onClientPedDamage called! Bodypart:"..tostring(bodypart).." Attacker:"..tostring(attacker).." Weapon:"..tostring(weapon).." Loss:"..tostring(loss).."")
if(bodypart == 9) then
setPedHeadless(source,true)
killPed(source) --ERROR: attempt to call global 'killPed' (a nil value)
end
end
addEventHandler("onClientPedDamage",getRootElement(),clientpeddamage)

Link to comment
As I stated above, the problem looks to be that those events currently only seem to work correctly on real players, not scripted peds.

Those events are there mainly because of peds. For players there are separate events.

Every player is a ped. Not every ped is a player.

Link to comment
As I stated above, the problem looks to be that those events currently only seem to work correctly on real players, not scripted peds.

Those events are there mainly because of peds. For players there are separate events.

Every player is a ped. Not every ped is a player.

Link to comment
As I stated above, the problem looks to be that those events currently only seem to work correctly on real players, not scripted peds.

Those events are there mainly because of peds. For players there are separate events.

Every player is a ped. Not every ped is a player.

That's why it's needed that ped events work properly.

Link to comment
As I stated above, the problem looks to be that those events currently only seem to work correctly on real players, not scripted peds.

Those events are there mainly because of peds. For players there are separate events.

Every player is a ped. Not every ped is a player.

That's why it's needed that ped events work properly.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...