Forum

> > CS2D > Scripts > Buy menu in lua?
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Buy menu in lua?

24 Antworten
Seite
Zum Anfang Vorherige 1 2 Nächste Zum Anfang

alt Buy menu in lua?

Refresh
User Off Offline

Zitieren
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.
2× editiert, zuletzt 13.02.11 16:02:15

alt Re: Buy menu in lua?

DC
Admin Off Offline

Zitieren
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!

alt Re: Buy menu in lua?

DannyDeth
User Off Offline

Zitieren
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

alt Re: Buy menu in lua?

DannyDeth
User Off Offline

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

alt Re: Buy menu in lua?

Ice-cream16
User Off Offline

Zitieren
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

alt Re: Buy menu in lua?

DannyDeth
User Off Offline

Zitieren
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:
Mehr >
1× editiert, zuletzt 13.02.11 15:58:48

alt Re: Buy menu in lua?

J4x
User Off Offline

Zitieren
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

alt Re: Buy menu in lua?

DannyDeth
User Off Offline

Zitieren
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?

alt Re: Buy menu in lua?

Refresh
User Off Offline

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

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

so what?

alt Re: Buy menu in lua?

DannyDeth
User Off Offline

Zitieren
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

alt Re: Buy menu in lua?

Refresh
User Off Offline

Zitieren
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
Zum Anfang Vorherige 1 2 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht