Jump to content

[Help] Custom event doesn't work


Kazafka

Recommended Posts

Posted (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 by VaporZ
  • Moderators
Posted

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)

 

  • Thanks 1
Posted
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!

  • Like 1

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