Forum

> > CS2D > Scripts > Lua Request
Forums overviewCS2D overview Scripts overviewLog in to reply

English Lua Request

12 replies
To the start Previous 1 Next To the start

old Lua Request

LuaNewBie
User Off Offline

Quote
Hello us
Today , i will request you a code , let's see !

I want the script that allow only person who has paid money to enter the entrance way in specific x , y coordinate.

1
money(id)

and who hasn't paid money can't enter the entrance way and then return to previous tile.

Thank you for your help .

old Re: Lua Request

Tobey
User Off Offline

Quote
As I think that you want to learn Lua, show me what you recently did. I won't give you the code at all because most likely you won't learn from it. If you have problems at a certain point... tell us.

old Re: Lua Request

LuaNewBie
User Off Offline

Quote
user Tobey has written
As I think that you want to learn Lua, show me what you recently did. I won't give you the code at all because most likely you won't learn from it. If you have problems at a certain point... tell us.


Well , i have problems at this point that is i can't write value in table or something about table that as well then i am here to ask you all but i can only write Arrays however i am not as well at Arrays too.

old Re: Lua Request

Tobey
User Off Offline

Quote
you should know if you would need this. Some questions to you:

What hooks would you use?
How would you check the cash/price for the travel?
How to send someone to another position then?
How to reset if he doesn't have enough cash?

some tip, you can ask the players money by:

1
player(id,money)==1000

concerning that id is the ID of the player in the server and money the in-built table you would like to refer to.

old Re: Lua Request

LuaNewBie
User Off Offline

Quote
user Tobey has written
you should know if you would need this. Some questions to you:

What hooks would you use?
How would you check the cash/price for the travel?
How to send someone to another position then?
How to reset if he doesn't have enough cash?

some tip, you can ask the players money by:

1
player(id,money)==1000

concerning that id is the ID of the player in the server and money the in-built table you would like to refer to.


user Tobey has written
What hooks would you use?


This is why i ask you all , maybe move or movetile hook

user Tobey has written
How would you check the cash/price for the travel?


1
if money[id] >= 500 then

user Tobey has written
How to send someone to another position then?


This is why i ask you all , this case i don't really know

user Tobey has written
How to reset if he doesn't have enough cash?


This is why i ask you all , this case i don't really know too.

At least if you can give me only example i will improve it myself.

old Re: Lua Request

Gaios
Reviewer On Online

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Teleport = {
	x = {100},
	y = {100},
}

Move = {
	x = {1},
	y = {1},
}

if money[id]>=500 then
	local x=player(id,"tilex")
	local y=player(id,"tiley")
	if x==Move.x[1] and y==Move.y[1] then
		parse('setpos '..id..' '..Teleport.x[1]..' '..Teleport.y[1]..')
		money[id]=money[id]-100
	end
end

old Re: Lua Request

Tobey
User Off Offline

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

1
if x==30 and y==50 then

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

old Re: Lua Request

omg
User Off Offline

Quote
method separates the new programmers from the good programmers
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview