WiBox Posted May 31, 2018 Share Posted May 31, 2018 (edited) is there a way I can check if the player is under attack or from last 20 second he was attacked? Edited May 31, 2018 by SSKE Link to comment
AJXB Posted May 31, 2018 Share Posted May 31, 2018 setElementData() setTimer() -- to reset the element data Link to comment
WiBox Posted May 31, 2018 Author Share Posted May 31, 2018 If you can give an example I'll be grateful, because I don't know how to add if the player got damage from less then 20 second... Link to comment
AJXB Posted May 31, 2018 Share Posted May 31, 2018 57 minutes ago, SSKE said: If you can give an example I'll be grateful, because I don't know how to add if the player got damage from less then 20 second... Look for it in the Wiki, I think you'll find your way around. Link to comment
WiBox Posted May 31, 2018 Author Share Posted May 31, 2018 I'm still searching from the time I made this topic but I don't know how the Data i should add on elementdata.. Link to comment
itHyperoX Posted May 31, 2018 Share Posted May 31, 2018 https://wiki.multitheftauto.com/wiki/OnPlayerDamage https://wiki.multitheftauto.com/wiki/SetElementData https://wiki.multitheftauto.com/wiki/SetTimer Link to comment
WiBox Posted May 31, 2018 Author Share Posted May 31, 2018 Thank you~ I'll check them,, Link to comment
itHyperoX Posted May 31, 2018 Share Posted May 31, 2018 If you need help with the code feel free to ask. Link to comment
WiBox Posted May 31, 2018 Author Share Posted May 31, 2018 function DamageUponUsingEventJoining (player) timer3 = setTimer( function (player) local time4 = 20 if ( time4 > 0 ) then for _,localPlayer in ipairs ( getElementsByType("player")) do outputChatBox("If you taked damage from less then 20 seconds you can't join this event!",player, 255, 99, 71) end time4 = time4 - 1 end end, 20000, 0) end addEventHandler("onPlayerDamage", root, DamageUponUsingEventJoining) I could not try it on my self, so I needed to know if it like that because I could not test it... Link to comment
AJXB Posted May 31, 2018 Share Posted May 31, 2018 Try this: -- Server Side damageTimers = {} function handlePlayerDamage ( attacker, weapon, bodypart, loss ) if (attacker) then -- Check if an attacker exists, you might wanna add a check to see if it's a valid player, also check the attacked player (source) if isTimer(damageTimers[source]) then -- Check if there is already a timer to reset the state of that player, happens when the player is damaged again before the 20 seconds are over killTimer(damageTimers[source]) -- Kill the old timer and continue to make a new one end setElementData(source,'damaged',true) -- Mark the player as damaged within the last 20 seconds damageTimers[source] = setTimer( -- Make a timer, we used a table damageTimers[] function() setElementData(source,'damaged',false) -- Mark the player as not damaged within the last 20 seconds AFTER the timer expires (20 seconds) end, 20*1000, 0 ) end end addEventHandler ( "onPlayerDamage", getRootElement (), handlePlayerDamage ) -- addEventHandler to all players Link to comment
WiBox Posted June 1, 2018 Author Share Posted June 1, 2018 Thanks for explaining this to me I appreciate that 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