Forum

> > CS2D > Scripts > Effect ZZZ on Tile X Y.
Forums overviewCS2D overview Scripts overviewLog in to reply

English Effect ZZZ on Tile X Y.

19 replies
To the start Previous 1 Next To the start

old Effect ZZZ on Tile X Y.

Rainoth
Moderator Off Offline

Quote
Is it possible to do it ?
Is there a hook like "on walk" on tile ?
I am making something so that player has to do tons of stuff then dyn_wall disappears and a tile where you can walk appears. When you walk on it you get effect (parse) like add health spd or anything (not like it really matters) I would be very grateful if you could show me "on walk on tile XY" hook if there is one or something that does similar or the same thing. Thank you in advance

old Re: Effect ZZZ on Tile X Y.

Rainoth
Moderator Off Offline

Quote
1
2
3
4
5
6
addhook("movetile","moving")
function moving(id,x,y)
if (player(id,"x")=(tilenumberx) and player(id,"y")=(tilenumbery) then
parse bla bla bla
end
end

Like this ?

Edit : Another question. Is there a trigger hook or something similar ? To trigger triggers on the map ? and do stuff WHEN you trigger something ?
edited 2×, last 25.02.13 08:52:03 pm

old Re: Effect ZZZ on Tile X Y.

Rainoth
Moderator Off Offline

Quote
I read the "movetile" thing but I can't understand it. Just says what I can use, nothing else. Did I write my little hook there correctly ?

old Re: Effect ZZZ on Tile X Y.

Avo
User Off Offline

Quote
Correctly.
Code below will shop message to all players, only if player moves on tile 10,10 where's entity with name "LOL".
1
2
3
4
5
6
7
addhook("movetile","moving")
function moving(id,x,y)
	if x==10 and y==10 and entity(x,y,"name")=="LOL" then
		--code here
		msg("Player with ID "..id.." ("..player(id,"name")..") is on tile X="..x.." Y="..y.." !")
	end
end

old Re: Effect ZZZ on Tile X Y.

Rainoth
Moderator Off Offline

Quote
user Avo has written
Correctly.
Code below will shop message to all players, only if player moves on tile 10,10 where's entity with name "LOL".
1
2
3
4
5
6
7
addhook("movetile","moving")
function moving(id,x,y)
	if x==10 and y==10 and entity(x,y,"name")=="LOL" then
		--code here
		msg("Player with ID "..id.." ("..player(id,"name")..") is on tile X="..x.." Y="..y.." !")
	end
end


What if entity has no name ? I just delete everything after "y==10" in that line ?

old Re: Effect ZZZ on Tile X Y.

Avo
User Off Offline

Quote
1
2
3
4
5
6
7
addhook("movetile","moving")
function moving(id,x,y)
     if x==10 and y==10  then
          --code here
          msg("Player with ID "..id.." ("..player(id,"name")..") is on tile X="..x.." Y="..y.." !")
     end
end

^----Will run even there's no entity on x=10,y=10.

1
2
3
4
5
addhook("movetile","moving")
function moving(id,x,y)
          msg2(id,"You moved on tile: X="..x.." Y="..y)
     end
end

^---- Will show you message with tile coordinates you're moving on.


Two simple examples of using "movetile" hook.

old Re: Effect ZZZ on Tile X Y.

Rainoth
Moderator Off Offline

Quote
Awww Yeah. You're a life saver
But my own code would have worked too, right ?
I'm still gunna use yours since it's with tabs

old Re: Effect ZZZ on Tile X Y.

EngiN33R
Moderator Off Offline

Quote
In response to your last message, no, it wouldn't have worked.

1
2
3
4
5
6
addhook("movetile","moving")
function moving(id,x,y)
if (player(id,"x")=(tilenumberx) and player(id,"y")=(tilenumbery) then -- = is the assignation operator (make foo be bar), == is the evaluation one (is foo equal to bar?). You also didn't close a bracket.
parse bla bla bla
end
end

Also, you don't need to put variables in their own brackets.

I advise you to PM me if you don't understand how to do something in Lua. I'll try to explain clearly and exhaustively. (and patiently, for the most part)

old Re: Effect ZZZ on Tile X Y.

Rainoth
Moderator Off Offline

Quote
user EngiN33R has written
In response to your last message, no, it wouldn't have worked.

1
2
3
4
5
6
addhook("movetile","moving")
function moving(id,x,y)
if (player(id,"x")=(tilenumberx) and player(id,"y")=(tilenumbery) then -- = is the assignation operator (make foo be bar), == is the evaluation one (is foo equal to bar?). You also didn't close a bracket.
parse bla bla bla
end
end

Also, you don't need to put variables in their own brackets.

I advise you to PM me if you don't understand how to do something in Lua. I'll try to explain clearly and exhaustively. (and patiently, for the most part)


so.. Like this ?
1
2
3
4
5
6
addhook("movetile","moving")
function moving(id,x,y)
if (player(id,x)==(tilenumberx) and player(id,y)==(tilenumbery)) then -- = is the assignation operator (make foo be bar), == is the evaluation one (is foo equal to bar?). You also didn't close a bracket.
parse bla bla bla
end
end

Removed (") ; added "=" and added one more ")" Would it work now ?
And ok. I will ask further questions regarding something I don't understand to you. Thanks

old Re: Effect ZZZ on Tile X Y.

EngiN33R
Moderator Off Offline

Quote
This time around you forgot to enclose the second argument to player() in quotes.

And actually, looking at it again, player(id,"x") returns the position in pixels, while you check if it's equal to the tile position. Unless you provide the tile position in pixels, it won't work.

In addition, you don't actually need to use the player() function to get the position, since the movetile hook already provides the position in tiles to which the player has moved.

So basically,

1
2
3
4
5
6
addhook("movetile","moving")
function moving(id,x,y)
	if (x==yourtilex and y==yourtiley) then
		parse("killplayer "..id) -- for example
	end
end

old Re: Effect ZZZ on Tile X Y.

Rainoth
Moderator Off Offline

Quote
user EngiN33R has written
This time around you forgot to enclose the second argument to player() in quotes.

And actually, looking at it again, player(id,"x") returns the position in pixels, while you check if it's equal to the tile position. Unless you provide the tile position in pixels, it won't work.


So if for some reason I wanted to do it with pixels. I'd have to add "*32" to my Tilex and Tiley numbers ? But shouldn't the "movetile" hook use tiles instead of pixels ? (since it contains word "tile" in the name ??) But I can use "player" function if I want to right ? because it might be shorter without it but if you say "movetile hook already provides the position in tiles to which the player has moved" I can understand that not all hooks do that and in some I should use the "player" so I could use it everywhere just to make sure I don't screw up, right ?

old Re: Effect ZZZ on Tile X Y.

EngiN33R
Moderator Off Offline

Quote
user Rainoth has written
So if for some reason I wanted to do it with pixels. I'd have to add "*32" to my Tilex and Tiley numbers ?

Well, if for some reason you wanted to do it with pixels that way, the movement would only get registered if the player stood on that exact pixel.
If you must know >


user Rainoth has written
But shouldn't the "movetile" hook use tiles instead of pixels ? (since it contains word "tile" in the name ??)

It does, it's in my third paragraph.

user EngiN33R has written
the movetile hook already provides the position in tiles


user Rainoth has written
But I can use "player" function if I want to right ?

Yes, but it makes less sense that way - you use a function to get a value that's already provided to you.

user Rainoth has written
because it might be shorter without it but if you say "movetile hook already provides the position in tiles to which the player has moved" I can understand that not all hooks do that and in some I should use the "player" so I could use it everywhere just to make sure I don't screw up, right ?

Well, actually, you should optimize your code. You don't need to use the player() function in this particular case, because the position is already given to you. In other cases you might need to use it. It's situational, you need to recognize what belongs where.

Use paragraphs (double line breaks).

old Re: Effect ZZZ on Tile X Y.

Rainoth
Moderator Off Offline

Quote
Alright. Big thanks. Little question. if I want to parse a trigger it should look something like this
1
parse("trigger TEXT")
right ?

old Re: Effect ZZZ on Tile X Y.

Yates
Reviewer Off Offline

Quote
user EngiN33R has written
It also seems you can't use whitespaces.

I once used alt+255 to get around a same issue. Not sure if it works here though.

old Re: Effect ZZZ on Tile X Y.

Rainoth
Moderator Off Offline

Quote
Whatcha mean by white spaces ? As in when you press Spacebar ? Another question. Can I fuse two hooks somehow ? So when I am on exact tile and do something like (attack2 with certain weapon/spray/say something/etc etc.) ? Do I have to add something to my hook to make it work ?

old Re: Effect ZZZ on Tile X Y.

EngiN33R
Moderator Off Offline

Quote
user Rainoth has written
Whatcha mean by white spaces ? As in when you press Spacebar ?

Yes.

user Rainoth has written
Another question. Can I fuse two hooks somehow ? So when I am on exact tile and do something like (attack2 with certain weapon/spray/say something/etc etc.) ? Do I have to add something to my hook to make it work ?

You can.

This is not exactly what you mentioned, but it's a good demonstration.

1
2
3
4
5
6
addhook("attack","attacks")
addhook("attack2","attacks")

function attacks(id)
	print(player(id,"name").." attacked!")
end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview