BieHDC Posted August 28, 2013 Share Posted August 28, 2013 Hello, i would like to know what would be the best way to store a element(player), that changes often? i describe you what i mean: If somebody hitted a specific player (in my case the victim), he should be stored as last hitter. If in some secounds another player hitted the "victim" then he should be stored as last hitter, until the victim is wasted. and then the last hitter get some money. I dont want you to script for me, i only wanna know what i should use. Maybe SERIAL, or PlayerName(may cause problems with getting him later again i think), or what ever... What would be the best function? Link to comment
Castillo Posted August 28, 2013 Share Posted August 28, 2013 Use a table, each time a player damages, store it on that table in a format: table [ victim ] = attacker, then on wasted, you check if the player that died is on that table. Link to comment
BieHDC Posted August 28, 2013 Author Share Posted August 28, 2013 maybe i should post the script the server recives the data from client! No NIL or fails > TESTED function whokilledvic ( thehitted ) local thehitter = source if (thehitter) ~= (victimvehicle) then --if the hitter is not the victim if (thehitted) == (victimvehicle) then --if the hitted vehicle is the victim --Here should be the data saved set lastest hitter = getVehicleOccupant(thehitter) --the clientside sends the vehicle not the player end end end addEvent ( "whowasit", true ) addEventHandler ( "whowasit", root, whokilledvic ) function isthevictimkilled() if isElement( victim2 ) then if ( isPedDead ( victim2 ) ) then --get the lastest hitter end end end addEventHandler ( "onPlayerWasted", root, isthevictimkilled ) Link to comment
Castillo Posted August 28, 2013 Share Posted August 28, 2013 Store that data on a table the way I mentioned above. Link to comment
BieHDC Posted August 28, 2013 Author Share Posted August 28, 2013 sorry i am not so experienced with tables yet can you pls write how to store and how to get? Link to comment
Castillo Posted August 28, 2013 Share Posted August 28, 2013 You must define a global table: local lastHit = { } Then when you're going to store it: lastHit [ thehitted ] = thehitter Then to obtain that when they die: local lastHitter = lastHit [ source ] Link to comment
BieHDC Posted August 28, 2013 Author Share Posted August 28, 2013 ok that will work maybe EDIT: i have done something wrong? line 20: bad argument @ getVehicleOccupant Edit2: why not use getPlayerSerial and getPlayerFromSerial? lastHit = { } function whokilledvic ( thehitted ) local thehitter = source if (thehitter) ~= (victimvehicle) then if (thehitted) == (victimvehicle) then lastHit [ thehitted ] = thehitter outputChatBox( " Data Stored! ", root ) --i get this check output end end end addEvent ( "whowasit", true ) addEventHandler ( "whowasit", root, whokilledvic ) function isthevictimkilled() if isElement( victim2 ) then if ( isPedDead ( victim2 ) ) then lastHitter = lastHit [ source ] hittername = getPlayerName(getVehicleOccupant(lastHitter)) --bad argument @ getVehicleOccupant outputChatBox(" The last hitter was " ..hittername , root ) end end end addEventHandler ( "onPlayerWasted", root, isthevictimkilled ) Link to comment
Moderators IIYAMA Posted August 28, 2013 Moderators Share Posted August 28, 2013 lastHit = { } local function whokilledvic ( thehitted ) local thehitter = source if thehitter ~= victimvehicle then if thehitted == victimvehicle then lastHit [ thehitted ] = thehitter outputChatBox( " Data Stored! ", root ) --i get this check output end end end addEvent ( "whowasit", true ) addEventHandler ( "whowasit", root, whokilledvic ) --- what is victim2 ? local function isthevictimkilled() if isElement( victim2 ) then if isPedDead ( victim2 ) then local lastHitter = lastHit [ source ] if lastHitter then -- check if there is data from the table local player = getVehicleOccupant(lastHitter) if player then -- check if there is a player in the vehicle local hittername = getPlayerName(player) --bad argument @ getVehicleOccupant outputChatBox(" The last hitter was " ..hittername , root ) end end end end end addEventHandler ( "onPlayerWasted", root, isthevictimkilled ) I fixed some of the code, but I think it is more handy to use the player as key and the vehicle as data. this code I posted will not work, because you can't find players within a table with only vehicles as key. You have now: lastHit[vehicle]= player But I will recommend you to create the table like this: lastHit[player]= vehicle Because vehicles can be replaced, and the table can be cleared with the event: "onPlayerQuit". Link to comment
BieHDC Posted August 29, 2013 Author Share Posted August 29, 2013 at first: victim2 is victim because i get my victim with getRandomPlayer() and if i use victim i get bad argument, but if i do victim2 = victim then it works isPedDead(victim) > bad argument isPedDead(victim2) > it works and i have victim global, so i think its a little bug which can be solved with this the secound: i have stored the hitter now as player, but i get bad argument @ getPlayerName line 21 lastHit = { } function whokilledvic ( thehitted ) local thehitter = source if (thehitter) ~= (victimvehicle) then if (thehitted) == (victimvehicle) then thelastone = getVehicleOccupant(thehitter) lastHit [ thehitted ] = thelastone outputChatBox( " Data Stored! ", root ) end end end addEvent ( "whowasit", true ) addEventHandler ( "whowasit", root, whokilledvic ) function isthevictimkilled() if isElement( victim2 ) then if ( isPedDead ( victim2 ) ) then local lastHitter = lastHit [ source ] local hittername = getPlayerName(lastHitter) --here is the bad argument outputChatBox(" The last hitter was " ..hittername , root ) end end end addEventHandler ( "onPlayerWasted", root, isthevictimkilled ) Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now