let's assume you have a way with one tile wide, so you need to walk through it. the path is at 30|50 for example.
In this case, we could use both, the move or movetile hook. the move hook does check for pixels, so you would need to divide it by 32 to get the tile which would also work perfectly. The difference between both is that the move hook does also check for shift-walking, silence walking, crouching, no idea how you would like to call it. movetile checks for the tile x|y you're standing at, so we will use it as it fits our needs.
1
addhook("movetile","gatewalk")
so far, this is okay. the movetile hook has 3 parameters: id, x & y. pretty obvious that we need all three so our function is
1
function gatewalk(id,x,y)
so, you would need to check if a player walks on that tile. you can do this with the so called if-condition. as the english word already describes, it checks if something or someone does a certain thing or is reaching a certain state. in our case, we check if a player walks the tile.
you can use the and to add conditions to it without creating a new if-line all the way, so your script still looks clean. the then is implying what will happen next. for the next thing, we should check for the money. let's say you need to pay 250$ to cross the bridge.
1
if player(id,"money")>=250 then
we check if the players money on the tile is bigger than 250, if it is, we continue.
1
parse("setpos "..id.." 320 320")
we're setting the position of the player who entered that tile to 320|320 - in pixels. so he would stay at tile 10|10.
at all, the script looks like this now:
1
2
3
4
5
addhook("move","gatewalk")
function gatewalk(id,x,y)
if x==30 and y==50 then
if player(id,"money")>=250 then
parse("setpos "..id.." 320 320")
However, we need to check if someone doesn't meet these conditions and what would happen to them. As you said, you want them to go back a tile then, so we just make them going one tile lower
1
2
3
4
5
6
7
addhook("move","gatewalk")
function gatewalk(id,x,y)
if x==30 and y==50 then
if player(id,"money")>=250 then
parse("setpos "..id.." 320 320")
else
parse("setpos "..id.." 960 1568")
You need to end functions, loops and condition checks and some few more things in lua. so we need to end all our functions and if-conditions we made.
1
2
3
4
5
6
7
8
9
10
addhook("move","gatewalk")
function gatewalk(id,x,y)
if x==30 and y==50 then
if player(id,"money")>=250 then
parse("setpos "..id.." 320 320")
else
parse("setpos "..id.." 960 1568")
end
end
end
3 ends because we have 1 function and 2 if-conditions.
I didn't check the code at all, so you would have to do that, but I hope it works like that.
edit: oops, I forgot to take the money from the guy then:
1
2
3
4
5
6
7
8
9
10
11
addhook("move","gatewalk")
function gatewalk(id,x,y)
if x==30 and y==50 then
if player(id,"money")>=250 then
parse("setmoney "..id.." "..player(id,"money")-250)
parse("setpos "..id.." 320 320")
else
parse("setpos "..id.." 960 1568")
end
end
end
edited 2×, last 16.09.12 03:22:27 pm