Dice Posted March 25, 2013 Share Posted March 25, 2013 addEventHandler( "onPlayerWasted", getRootElement(), function( totalammo, killer, killerWeapon, bodypart ) if isElementWithinColShape ( source, arena ) then local detection = isElementWithinColShape ( source, arena ) local detectionKiller = isElementWithinColShape ( killer, arena ) if detection then if close == 1 then local dx, dy, dz = unpack(randspawn[math.random(#randspawn)]) setTimer ( setElementPosition, 5000, 1, source, dx, dy, dz ) setTimer ( setElementHealth, 5000, 1, killer, 200 ) setTimer ( setElementRotation, 5000, 1, source, 0, 0, 180 ) else setTimer ( setElementPosition, 5000, 1, source, 577.92224121094, -2621.6677246094, 1378.0678710938 ) setTimer ( setElementHealth, 5000, 1, killer, 200 ) setTimer ( setElementRotation, 5000, 1, source, 0, 0, 180 ) end end end end ) What happens here is, if a player get's killed then fill the killers HP to 200 because it is 200. But timer is unreliable, can I embed onPlayerSpawn ? into this? and when I do and try to use the variable killer in it it says it is a nil value. How can I do it this way instead of timers. Link to comment
Castillo Posted March 25, 2013 Share Posted March 25, 2013 You want to set the health of the killer to 200% when the player that got killed spawns? Link to comment
Dice Posted March 25, 2013 Author Share Posted March 25, 2013 yes it's an arena type thing. but I think onPlayerSpawn would be better use of cpu and ram instead of setting a timer everytime a person dies. Link to comment
Castillo Posted March 25, 2013 Share Posted March 25, 2013 Yes, it'll be more efficient. local killers = { } addEventHandler ( "onPlayerWasted", getRootElement(), function ( totalammo, killer, killerWeapon, bodypart ) if isElementWithinColShape ( source, arena ) then local detection = isElementWithinColShape ( source, arena ) local detectionKiller = isElementWithinColShape ( killer, arena ) if detection then local x, y, z = unpack ( ( close == 1 and randspawn [ math.random ( #randspawn ) ] ) or { 577.92224121094, -2621.6677246094, 1378.0678710938 } ) setTimer ( function ( thePlayer, dx, dy, dz ) if ( isElement ( thePlayer ) ) then setElementPosition ( thePlayer, dx, dy, dz ) setPedRotation ( thePlayer, 180 ) end end ,5000, source, x, y, z ) killers [ source ] = killer end end end ) addEventHandler ( "onPlayerSpawn", root, function ( ) if ( isElement ( killers [ source ] ) ) then setElementHealth ( killers [ source ], 200 ) end killers [ source ] = nil end ) Not tested. Link to comment
Dice Posted March 25, 2013 Author Share Posted March 25, 2013 ok I will test this, thanks a lot. Link to comment
Dice Posted March 25, 2013 Author Share Posted March 25, 2013 Question what if someone who has nothing to do with the arena spawns, and killer [ source ] is an element willl that effect the killers [ source ] Link to comment
Castillo Posted March 25, 2013 Share Posted March 25, 2013 The player that died is inserted on the table inside the function that checks if is in the arena, so it shouldn't happen what you said. 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