Jump to content

WiBox

Recommended Posts

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
    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

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

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...