WiBox Posted June 28, 2018 Share Posted June 28, 2018 Timer10 = setTimer( function () time0 = 1 for _,plrs in ipairs(getElementsByType("player")) do if ( getElementDimension (plrs) == 0 ) then if ( not addCommandHandler("usemedkit", usethemedkit) ) then addCommandHandler("usemedkit", usethemedkit) addCommandHandler("acceptmedkit", healOthers) addEventHandler("meds.giveMedKit", root, giveMedKit) addEventHandler("meds.useMedKitOnOther", root, usemedkitanother) end if ( addCommandHandler("usemedkit", usethemedkit) ) then killTimer(Timer10) end if ( getElementDimension (plrs) == 336 ) then if ( addCommandHandler("usemedkit", usethemedkit) ) then killTimer(Timer10) end if ( not addCommandHandler("usemedkit", usethemedkit) ) then resetTimer(Timer10) end if ( addCommandHandler("usemedkit", usethemedkit) ) then killTimer(Timer10) end timer0 = timer0 - 1 if ( timer0 < 0 ) then killTimer(Timer10) end end end end end, 1000, 0) I made that script but my problem is it's saying in console: addEventHandler ['meds.useMedKit with this function is already handled], I tried like 6 times fix it so it stop spamming in the console but it isn't working.. Can someone help please? I just need a way to stop the spams in my console.. I tried killTimer but didn't work, I appreciate who help and thanks. Link to comment
Z4Zy Posted June 28, 2018 Share Posted June 28, 2018 what did you trying to do ?? if player in dimension 0 then he allowed to use the functions else he can not use that functions. Isn't it ?? Link to comment
WiBox Posted June 28, 2018 Author Share Posted June 28, 2018 I made a script which disable medkits in dimension 336. the thing is, it work but it spam that addEventHandler ['meds.useMedKit with this function is already handled] I want a way for I stop that spam, those spam come from the 2 lines 9, 10. Link to comment
Mr.Loki Posted June 28, 2018 Share Posted June 28, 2018 Why do you have that inside of a timer? This is what you're doing function usethemedkit() --code end addCommandHandler("usemedkit", usethemedkit) addCommandHandler("usemedkit", usethemedkit) addCommandHandler("usemedkit", usethemedkit)........ and it will keep adding command handlers to the same functions over and over if you want to disable a function in a dimension just check the player's dimension when they use the command. 1 Link to comment
WiBox Posted June 28, 2018 Author Share Posted June 28, 2018 (edited) That's why I'm trying to kill the Timer, I just want it too add one time the command handler if it wasn't created.. I need a way that, if the command handler already created then the timer get destroyed, any hints please? Edited June 28, 2018 by SSKE Link to comment
Mr.Loki Posted June 28, 2018 Share Posted June 28, 2018 Then just add the commands don't put it in a timer. function name(player) if getElementDimension(player) == 0 then -- only execute if the player's dimension is 0 --code end end addCommandHandler("usemedkit", name) -- or function name(player) if getElementDimension(player) ~= 336 then -- only execute if the player's dimension is not 336 --code end end addCommandHandler("usemedkit", name) 1 Link to comment
WiBox Posted June 28, 2018 Author Share Posted June 28, 2018 Man I made a Timer so It work automaticly, I want to do that without use a command or should I use a EventHandler? Link to comment
WiBox Posted June 28, 2018 Author Share Posted June 28, 2018 (edited) Dude I'll explain from the beginning, I made a code which if the player go back to the main dimension it re add: addCommandHandler("usemedkit", usethemedkit)addCommandHandler("acceptmedkit", healOthers)addEventHandler("meds.giveMedKit", root, giveMedKit)addEventHandler("meds.useMedKitOnOther", root, usemedkitanother) Those 4 I remove them with a command and I can back them with a command, but if he goes back to the main dimension I want for those 4 get added automatically. That's all Edited June 28, 2018 by SSKE Link to comment
Mr.Loki Posted June 28, 2018 Share Posted June 28, 2018 I know what you meant and i gave you my answer and it's still the same. There is no need to remove the event and command handlers. You can simply use function checks. Link to comment
WiBox Posted June 28, 2018 Author Share Posted June 28, 2018 (edited) You used command handler to back them.. If the player used a command for leave the dimension 336 before I use the command for back his medkits.. how should I back his medkit? Won't work like you told me.. Timer10 = setTimer( function () time0 = 1 for _,plrs in ipairs(getElementsByType("player")) do if ( getElementDimension (plrs) == 0 ) then if ( not addCommandHandler("usemedkit", usethemedkit) ) then addCommandHandler("usemedkit", usethemedkit) addCommandHandler("acceptmedkit", healOthers) addEventHandler("meds.giveMedKit", root, giveMedKit) addEventHandler("meds.useMedKitOnOther", root, usemedkitanother) end if ( addCommandHandler("usemedkit", usethemedkit) ) then killTimer(Timer10) end if ( getElementDimension (plrs) == 336 ) then if ( addCommandHandler("usemedkit", usethemedkit) ) then killTimer(Timer10) end if ( not addCommandHandler("usemedkit", usethemedkit) ) then resetTimer(Timer10) end if ( addCommandHandler("usemedkit", usethemedkit) ) then killTimer(Timer10) end timer0 = timer0 - 1 if ( timer0 < 0 ) then killTimer(Timer10) end end end end end, 1000, 0) I made the code and it worked! But I just need to stop the spam which come from the lines 9 and 10. I need a way to kill the timer once the commandhandler and event handler get added.. https://imgur.com/a/nHDP3Nv This spam I mean.. Edited June 28, 2018 by SSKE Link to comment
Z4Zy Posted June 28, 2018 Share Posted June 28, 2018 In line 9 and 10, you have added root element to the event, means, when this for loop run it's first time, event already added to all players. So no need to add that event again to other. So I suggest to change the argument 2 of event handlers in line 9 and 10 to plrs. And what about the using of local variable called "executed" ?? local executed = false -- executed is false when resource starts -- Timer10 = setTimer( function () time0 = 1 for _,plrs in ipairs(getElementsByType("player")) do if ( getElementDimension (plrs) == 0 ) then if ( executed == false ) then addCommandHandler("usemedkit", usethemedkit) addCommandHandler("acceptmedkit", healOthers) addEventHandler("meds.giveMedKit", root, giveMedKit) addEventHandler("meds.useMedKitOnOther", root, usemedkitanother) executed = true end if ( executed ) then killTimer(Timer10) end if ( getElementDimension (plrs) == 336 ) then if ( executed ) then killTimer(Timer10) end if ( executed == false ) then resetTimer(Timer10) end if ( executed ) then killTimer(Timer10) end timer0 = timer0 - 1 if ( timer0 < 0 ) then killTimer(Timer10) end end end end end, 1000, 0) 1 Link to comment
WiBox Posted June 28, 2018 Author Share Posted June 28, 2018 Thanks for your help @DeadthStrock but it didn't work. I found the broken part of my code, but for I fix it I need the answer on that topic: Thanks for you two helping me 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