Kazafka Posted January 19, 2020 Share Posted January 19, 2020 (edited) Today, I've made a event, for checking if player have mooved. At first, after success of detecting players' moovement, it was displaying a message for player, who have mooved.Then, I tried to trigger the event, and the problems started. Any idea? Code's here: ----------------------------------------- ---------------VaporZ (c)---------------- ----------------------------------------- toggleOnPlayerMove = true addEventHandler("onResourceStart", root, function() if(toggleOnPlayerMove == true) then addEvent("onPlayerMove", true) setTimer( function() for _, player in ipairs(getElementsByType("player")) do local x, y, z = getElementPosition(player) setTimer( function() local x_, y_, z_ = getElementPosition(player) if(x ~= x_) and (y ~= y_) and (z ~= z_) then triggerEvent("onPlayerMove", root, player) end end, 1, 1) end end, 1, 0) end end) function dispMsg(player) outputChatBox("You've mooved!", player, math.random(1, 255), math.random(1, 255), math.random(1, 255), true) end addEventHandler("onPlayerMove", root, dispMsg) It is just giving me no errors and no message. Idk wut is wrong. Edited January 19, 2020 by VaporZ Link to comment
JeViCo Posted January 19, 2020 Share Posted January 19, 2020 try to use addEvent function below the toggleOnPlayerMove variable 1 Link to comment
Moderators IIYAMA Posted January 19, 2020 Moderators Share Posted January 19, 2020 Line 7: use resourceRoot instead of root. Else the code will be executed for every starting resource. Minimal timer delay should be 50. (Atleast that was a problem I had in the past) Don't create timers within loops. Don't create timers within timers. (Dangerous) 1 Link to comment
Kazafka Posted January 19, 2020 Author Share Posted January 19, 2020 5 minutes ago, JeViCo said: try to use addEvent function below the toggleOnPlayerMove variable Alright, thanks bro! Just now, IIYAMA said: Line 7: use resourceRoot instead of root. Else the code will be executed for every starting resource. Minimal timer delay should be 50. (Atleast that was a problem I had in the past) Don't create timers within loops. Don't create timers within timers. (Dangerous) Already solved, but thanks for your advance, too! 1 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