Forum

> > CS2D > Scripts > Buy menu in lua?
Forums overviewCS2D overview Scripts overviewLog in to reply

English Buy menu in lua?

24 replies
Page
To the start Previous 1 2 Next To the start

old Buy menu in lua?

Refresh
User Off Offline

Quote
Asking again. I want to make a buy menu lua. It shall be like if you press the button at a block( for example, a crate), you can buy stuff like Night vision, AK47, etc.. but it shall only work for CTs( I will use it on a zombie map). I would be even happy with a sample script. Thanks.
edited 2×, last 13.02.11 04:02:15 pm

old Re: Buy menu in lua?

DC
Admin Off Offline

Quote
aww this title is still pretty pointless. please try to explain WHAT lua script. otherwise it's too generic. every third guy here wants to have a Lua script. imagine everyone would choose a title like this one...

a 100 times better title would be for example "Lua Buy Menu Script" or something like it. short. not generic. explaining what you actually want.

is it so hard to choose a good title?!

edit: ah finally. thanks for editing!

old Re: Buy menu in lua?

DannyDeth
User Off Offline

Quote
Ok, now we can reply
However, first I need to know what the button's id is, or I can't actually figure out what button is being pressed on the map

old Re: Buy menu in lua?

DannyDeth
User Off Offline

Quote
The id of the button you press. Well, is it like F2 or F3, or are you talking about a button on a map?

old Re: Buy menu in lua?

Ice-cream16
User Off Offline

Quote
I remember this function on mg_multigame_final.
When you press button at the block, you can buy hat.
Try search it in multigame script

old Re: Buy menu in lua?

DannyDeth
User Off Offline

Quote
Here is a quick sample code, if you cannot fit all the weps in that you want, make the last button 'more' and then make it called another function which made another menu8 with more weapons. However that will create some seriously complex code eventually
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
addhook("usebutton","buy_menu")
function buy_menu(id,x,y)
	if x == bX and y == bY then
		menu(id,"Buy Menu,AK47 | 3000$, M4A1 | 5000$, ETC | 1988$")
	end
end

addhook("menu","buy_menu2")
function buy_menu2(id,title,button)
	if title == "Buy Menu" then
		loadstring("buy_button"..button.."(id)") --this executes the function 'buy_button[the_buttons_id](the_persons_id) --
	end
end

function buy_button1(p-id) -- This would be for the first button, the AK47 --
	if player(p-id,"money") <= 3000 then
		parse("setmoney "..p-id.." "..(player(p-id,"money")-3000))
		parse("equip "..p-id.." 30") -- For more ids, see nest code block --
end

function buy_button2(p-id) -- This would be for the second button, the M4A1 --
	if player(p-id,"money") <= 5000 then
		parse("setmoney "..p-id.." "..(player(p-id,"money")-5000))
		parse("equip "..p-id.." 32") -- For more ids, see nest code block --
end

And here are the weapon ids, incase you dont know them:
More >
edited 1×, last 13.02.11 03:58:48 pm

old Re: Buy menu in lua?

J4x
User Off Offline

Quote
Just replace bX and bY with the button x and y ( to see the button x and y use the map editor.)
1
if x == bX and y == bY

old Re: Buy menu in lua?

DannyDeth
User Off Offline

Quote
Well the tile can be modified by changing this:
1
if x == bX and y == bY then
bX becomes the X of the button and bY the Y of button. ( in tiles ).

And the buy button, well:
1
menu(id,"Buy Menu,AK47 | 3000$, M4A1 | 5000$, ETC | PRICE")
You just put the name and then the price. The 'Buy Menu' part is the title of the menu. So you can change that but then you need to change this part from the function 'buy_menu2':
1
if title == "Buy Menu" then
otherwise it won't work.

Then what you do is you put the name of the item, and then a |, and then the price. Thats how i did it, atleast.

Then what you need to do is count the button and name the function buy_button[INSERT_BUTTON_NO_HERE] function accordingly.

It's actually pretty complex thanks to my use of 'loadstring', but you would probably see what it does easily, right?

old Re: Buy menu in lua?

Refresh
User Off Offline

Quote
Well... I tried it, but the console says it has an error:

LUA ERROR: sys/lua/zombie.lua:15: ')' expected near '-'

so what?

old Re: Buy menu in lua?

DannyDeth
User Off Offline

Quote
Well, you know where it says p-id, change those things to p_id, a '-' sign is signalling a minus so change that and I think it will work

old Re: Buy menu in lua?

Refresh
User Off Offline

Quote
Edit: No. No, no, noo! Everything seems to be cool but if I want to buy something, nothing happens. I don't even loose my money.

Here is the modified code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
addhook("menu","buy_menu2")
function buy_menu2(id,title,button)
     if title == "Buy Menu" then
          loadstring("buy_button"..button.."(id)") --this executes the function 'buy_button[the_buttons_id](the_persons_id) --
     end
end

function buy_button1(p_id)
     if player(p_id,"money") <= 5500 then
          parse("setmoney "..p_id.." "..(player(p_id,"money")-5500))
          parse("equip "..p_id.." 30")
     end
end

function buy_button2(p_id)
     if player(p_id,"money") <= 5000 then
          parse("setmoney "..p_id.." "..(player(p_id,"money")-5000))
          parse("equip "..p_id.." 32")
     end
end

function buy_button3(p_id)
     if player(p_id,"money") <= 4000 then
          parse("setmoney "..p_id.." "..(player(p_id,"money")-4000))
          parse("equip "..p_id.." 10")
     end
end

function buy_button5(p_id)
     if player(p_id,"money") <= 1000 then
          parse("setmoney "..p_id.." "..(player(p_id,"money")-1000))
          parse("equip "..p_id.." 3")
     end
end

function buy_button7(p_id)
     if player(p_id,"money") <= 10000 then
          parse("setmoney "..p_id.." "..(player(p_id,"money")-10000))
          parse("equip "..p_id.." 59")
     end
end
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview