Loops
#1
i'm currently making a Away-From-Keyboard plugin but i need to check if the player moves. i made this loop:
   PlayerMoved = 0
	repeat
		if not( X == Player:GetPosX() ) and ( Y == Player:GetPosY() ) and ( Z == Player:GetPosZ()) then
			PlayerMoved = 1
			Player:SetName( Name[Player:GetName()] )
			Server:SendMessage( Player:GetColor() .. Player:GetName() .. cChatColor.White .. " is back")
		end
		LOG("TEST")
	until PlayerMoved == 1
but once it starts it never stops. even if i walk. and it kind of destroys the server becouse the server is only working on the loop. does anyone know how to fix it?
btw the X and Y and Z are coordinates that are put in once the player uses /afk

I also used:
while not( X == Player:GetPosX() ) and ( Y == Player:GetPosY() ) and ( Z == Player:GetPosZ()) do
			Player:SetName( Name[Player:GetName()] )
			Server:SendMessage( Player:GetColor() .. Player:GetName() .. cChatColor.White .. " is back")
end
Reply
Thanks given by:
#2
Instead of creating a loop, which blocks all server logic, check per tick or better yet use the on player moved function
Reply
Thanks given by: NiLSPACE
#3
there is no HOOK_PLAYER_MOVED hook there only is HOOK_PLAYER_MOVING but that activates even when you didn't move
Reply
Thanks given by:
#4
Still you shouldn't do the checking in a loop, because nothing changes within that loopTongue You must let the server update the player positions first by returning in your function
Reply
Thanks given by:
#5
_MOVED or _MOVING, doesn't really matter for you here. Just use that callback, inside it check if the player has moved more than 0.01 blocks away from their "/afk" position and if so, break the afk.

And welcome to the very first of your threading issues Smile
Reply
Thanks given by: NiLSPACE




Users browsing this thread: 1 Guest(s)