waleedrt Posted May 13, 2016 Posted May 13, 2016 well, i need to set time between commands like outputchatbox that appear when player is spamming or player can only say one thing every 5 sec. i don't know what should i use.
Feher Posted May 13, 2016 Posted May 13, 2016 Hey, use the setTimer() and the isTimer() functions. You can find a list of functions at the wikipedia.
waleedrt Posted May 13, 2016 Author Posted May 13, 2016 so , i have checked it and here what i did function healer(playerSource) if isTimer (wlaa ) then cancelEvent(healer) else money=getPlayerMoney ( playerSource ) if money<3000 then outputChatBox ("Server : You Don't have enough money",playerSource ,255,0,0) return else takePlayerMoney ( playerSource , 3000 ) setElementHealth ( playerSource , getElementHealth ( playerSource )+100 ) outputChatBox ("You Got 100 HP" , playerSource, 21 , 241 , 32 , true ) setTimer(healer,300,3) end end end addCommandHandler ( "hp", healer ) addEvent ("onPlayerDamage",playerSource, function (playerSource) setTimer (healer) end) and its not working and i have no idea what i did
waleedrt Posted May 13, 2016 Author Posted May 13, 2016 function healer(playerSource) money=getPlayerMoney ( playerSource ) if money<3000 then outputChatBox ("Server : You Don't have enough money",playerSource ,255,0,0) return else takePlayerMoney ( playerSource , 3000 ) setElementHealth ( playerSource , getElementHealth ( playerSource )+100 ) outputChatBox ("You Got 100 HP" , playerSource, 21 , 241 , 32 , true ) end end addCommandHandler ( "hp", healer ) if anyone can help me to make this scrip don't work after 3 sec when player get damage that would be great
swedishboy Posted May 13, 2016 Posted May 13, 2016 function healer(playerSource) money = getPlayerMoney ( playerSource ) if money >= 3000 then takePlayerMoney ( playerSource , 3000 ) setElementHealth ( playerSource , 100 ) outputChatBox ("You Got 100 HP" , playerSource, 21 , 241 , 32 , true ) else outputChatBox ("Server : You Don't have enough money",playerSource ,255,0,0) end end addCommandHandler ( "hp", healer )
waleedrt Posted May 13, 2016 Author Posted May 13, 2016 function healer(playerSource) money = getPlayerMoney ( playerSource ) if money >= 3000 then takePlayerMoney ( playerSource , 3000 ) setElementHealth ( playerSource , 100 ) outputChatBox ("You Got 100 HP" , playerSource, 21 , 241 , 32 , true ) else outputChatBox ("Server : You Don't have enough money",playerSource ,255,0,0) end end addCommandHandler ( "hp", healer ) are u trying to help me or what cuz I don't see any defiance between my script and this script
BEN. Posted May 13, 2016 Posted May 13, 2016 function healer( playerSource ) money = getPlayerMoney ( playerSource ) health = getElementHealth ( playerSource ) if money >= 3000 and health < 100 then takePlayerMoney ( playerSource , 3000 ) setElementHealth ( playerSource , 100 ) outputChatBox ("You got 100 health" , playerSource, 21 , 241 , 32 , true ) elseif money >= 3000 and health >= 100 then outputChatBox("Your health already: "..health,playerSource) elseif money < 3000 then outputChatBox("Your don't have enough money",playerSource) end end addCommandHandler ( "hp", healer )
waleedrt Posted May 13, 2016 Author Posted May 13, 2016 try this ye its working but i wanted it to stop working for 3 sec if the player get damage
waleedrt Posted May 13, 2016 Author Posted May 13, 2016 what do you want to stop? the function. i mean players can't use this scrip if they got damaged within 3 sec
waleedrt Posted May 13, 2016 Author Posted May 13, 2016 ye, i have tried to use this and its not working function healer(playerSource) if isTimer (wlaa ) then cancelEvent(healer) else money=getPlayerMoney ( playerSource ) if money<3000 then outputChatBox ("Server : You Don't have enough money",playerSource ,255,0,0) return else takePlayerMoney ( playerSource , 3000 ) setElementHealth ( playerSource , getElementHealth ( playerSource )+100 ) outputChatBox ("You Got 100 HP" , playerSource, 21 , 241 , 32 , true ) setTimer(healer,300,3) end end end addCommandHandler ( "hp", healer ) addEvent ("onPlayerDamage",playerSource, function (playerSource) setTimer (healer) end)
BEN. Posted May 13, 2016 Posted May 13, 2016 addEvent ("onPlayerDamage",playerSource, function (playerSource) setTimer (healer) end) ?
waleedrt Posted May 13, 2016 Author Posted May 13, 2016 doesn't work , I have tried like 30 times and failed.
pa3ck Posted May 13, 2016 Posted May 13, 2016 (edited) local playerDamages = {} function healer( playerSource ) local lastPlayerDamage = playerDamages[playerSource] or 0 if lastPlayerDamage == 0 or lastPlayerDamage + 3000 <= getTickCount() then local money = getPlayerMoney ( playerSource ) local health = getElementHealth ( playerSource ) if money >= 3000 and health < 100 then takePlayerMoney ( playerSource , 3000 ) setElementHealth ( playerSource , 100 ) outputChatBox ("You got 100 health" , playerSource, 21 , 241 , 32 , true ) elseif money >= 3000 and health >= 100 then outputChatBox("Your health already: "..health,playerSource) elseif money < 3000 then outputChatBox("Your don't have enough money",playerSource) end else outputChatBox("This function is on cooldown.",playerSource) end end addCommandHandler ( "hp", healer ) function playerDamage ( attacker, weapon, bodypart ) playerDamages[source] = getTickCount() end addEventHandler ( "onPlayerDamage", root, playerDamage ) Something like that should work Edited May 13, 2016 by Guest
swedishboy Posted May 13, 2016 Posted May 13, 2016 You forgot a ''then'' in line 6.. And in line 4 change playerDamage to playerDamages
pa3ck Posted May 13, 2016 Posted May 13, 2016 Yea, not used to the "then" in the if's after C#, thanks.
Gravestone Posted May 14, 2016 Posted May 14, 2016 You need to define 'wlaa' timer. And why are you adding an event onPlayerDamage while it already exists? Try this: function healer(playerSource) if isTimer (wlaa) then return outputChatBox("Server: Please wait 3 seconds before you re-fill your HP again", playerSource, 255, 0, 0) else local money = getPlayerMoney ( playerSource ) if (money < 3000) then outputChatBox ("Server: You don't have enough money",playerSource, 255, 0, 0) return else takePlayerMoney ( playerSource , 3000 ) setElementHealth ( playerSource , getElementHealth ( playerSource )+100 ) outputChatBox ("You got 100 HP" , playerSource, 21 , 241 , 32 , true ) timer() end end end addCommandHandler ( "hp", healer ) function timer() wlaa = setTimer(healer, 3000, 1) end addEventHandler("onPlayerDamage", root, timer) The script is server sided btw.
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