Forum

> > CS2D > Scripts > Player is moving?
Forums overviewCS2D overview Scripts overviewLog in to reply

English Player is moving?

6 replies
To the start Previous 1 Next To the start

old Player is moving?

Zeik
User Off Offline

Quote
Can you know if a player is moving somehow? I didn't find a way... The idle value also detects other actions, not just "not movement".

I thought of checking constantly the location of the player and if it changes, but it would be very laggy I guess.

old Re: Player is moving?

Zeik
User Off Offline

Quote
But I need to check if a player is moving to use it as a condition

Thanks anyway

Edit:
I found a way:
1
2
3
4
5
6
7
addhook("second","check")
function check()
	for id = 1, 32 do
			chX[id]=player(id,"tilex")
			chY[id]=player(id,"tiley")
	end
end
So, to check if the player moved, I compare chX and chY with the actual position given by player("tileX/Y")

Is not really accurate but it works.

I tried with "ms100" but it's too quick, so when comparing they will always be equal.
Maybe the "ms100" could work when comparing with pixels position
edited 3×, last 29.12.13 10:06:21 pm

old Re: Player is moving?

Pagyra
User Off Offline

Quote
Do not be so lazy - try to give some work for your brain. Change your code as this:
1
2
3
4
5
6
7
addhook("move","check")
function check()
     for id = 1, 32 do
               chX[id]=player(id,"x")
               chY[id]=player(id,"y")
     end
end

old Re: Player is moving?

Avo
User Off Offline

Quote
@user Pagyra: How about:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
chX, chY = {}, {}
addhook("move","OnMove")
function OnMove(id)
	--// your remaining code here

	chX[id] = player(id,"x")
	chY[id] = player(id,"y")
end

--// simple true/false function checking if player is moving or not
IsMoving = function(id)
	chX[id] = chX[id] or -100
	chY[id] = chY[id] or -100
	if chX[id] ~= player(id,"x") or chY[id] ~= player(id,"y") then
		return true
	end
	return false
end
Note: it's not tested.

old Re: Player is moving?

EngiN33R
Moderator Off Offline

Quote
user Zeik has written
But I need to check if a player is moving to use it as a condition

Are you sure of it? You could move the action that you need performed on player movement into a separate function, say, onMoveAction(id), and then you can just call it from a move hook, if not simply attach a move hook to it. To me, that seems to be the most effective way that doesn't involve any workarounds.

old Re: Player is moving?

Zeik
User Off Offline

Quote
LOL Pagyra, I feel like an idiot now!, I didn't realize I could use the move hook , sorry VADemon, you were right
Instead of the pixel's position, I'll use the tile's position.

Thank you all who answered
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview