Forum

> > CS2D > Scripts > Shop Script Doesnt Work Right!
Forums overviewCS2D overview Scripts overviewLog in to reply

English Shop Script Doesnt Work Right!

7 replies
To the start Previous 1 Next To the start

old Shop Script Doesnt Work Right!

RAIGEKI
User Off Offline

Quote
Hello Dear us Commnunity !
I need help with my script (detail).
Undzwar I have a script where it is pressed at a certain position of the button on a shop window appears.
And as far as I have everything (3 selection options).
Merely the problem is it only works the first Buying opportunity!
What is wrong?
Here is the excerpt
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
addhook("menu","buymenu")
function buymenu(id,title,buton)
if title=="What do you want to buy?" then
if buton==1 then
if (player(id,"money")>=300) then
parse("setmoney "..id.." "..player(id,"money")-300)
msg('©000128000You Bought A Grenade!')
parse('equip '..id..' 51')
parse('setweapon '..id..' 51')
parse('sv_sound2 '..id..' jonrpg/woosh.wav')
elseif buton==2 then
if (player(id,"money")>=700) then
parse("setmoney "..id.." "..player(id,"money")-700)
msg('©000128000You Bought A Grenade!')
parse('equip '..id..' 51')
parse('setweapon '..id..' 51')
parse('sv_sound2 '..id..' jonrpg/woosh.wav')
elseif buton==3 then
if (player(id,"money")>=1200) then
parse("setmoney "..id.." "..player(id,"money")-1200)
msg('©000128000You Bought A Grenade!')
parse('equip '..id..' 51')
parse('setweapon '..id..' 51')
parse('sv_sound2 '..id..' jonrpg/woosh.wav')
end
end
end
end
end
Thank You!!

old Re: Shop Script Doesnt Work Right!

_Yank
User Off Offline

Quote
Tabs....

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
addhook("menu","buymenu")
function buymenu(id,title,buton)
	if title=="What do you want to buy?" then
		if buton==1 then
			if (player(id,"money")>=300) then
				parse("setmoney "..id.." "..player(id,"money")-300)
				msg('©000128000You Bought A Grenade!')
				parse('equip '..id..' 51')
				parse('setweapon '..id..' 51')
				parse('sv_sound2 '..id..' jonrpg/woosh.wav')
			end
		elseif buton==2 then
			if (player(id,"money")>=700) then
				parse("setmoney "..id.." "..player(id,"money")-700)
				msg('©000128000You Bought A Grenade!')
				parse('equip '..id..' 51')
				parse('setweapon '..id..' 51')
				parse('sv_sound2 '..id..' jonrpg/woosh.wav')
			end
		elseif buton==3 then
			if (player(id,"money")>=1200) then
				parse("setmoney "..id.." "..player(id,"money")-1200)
				msg('©000128000You Bought A Grenade!')
				parse('equip '..id..' 51')
				parse('setweapon '..id..' 51')
				parse('sv_sound2 '..id..' jonrpg/woosh.wav')
			end
		end
	end
end

old Re: Shop Script Doesnt Work Right!

RAIGEKI
User Off Offline

Quote
user _Yank has written
Tabs....

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
addhook("menu","buymenu")
function buymenu(id,title,buton)
	if title=="What do you want to buy?" then
		if buton==1 then
			if (player(id,"money")>=300) then
				parse("setmoney "..id.." "..player(id,"money")-300)
				msg('©000128000You Bought A Grenade!')
				parse('equip '..id..' 51')
				parse('setweapon '..id..' 51')
				parse('sv_sound2 '..id..' jonrpg/woosh.wav')
			end
		elseif buton==2 then
			if (player(id,"money")>=700) then
				parse("setmoney "..id.." "..player(id,"money")-700)
				msg('©000128000You Bought A Grenade!')
				parse('equip '..id..' 51')
				parse('setweapon '..id..' 51')
				parse('sv_sound2 '..id..' jonrpg/woosh.wav')
			end
		elseif buton==3 then
			if (player(id,"money")>=1200) then
				parse("setmoney "..id.." "..player(id,"money")-1200)
				msg('©000128000You Bought A Grenade!')
				parse('equip '..id..' 51')
				parse('setweapon '..id..' 51')
				parse('sv_sound2 '..id..' jonrpg/woosh.wav')
			end
		end
	end
end

really?
Thanks Man!

old Re: Shop Script Doesnt Work Right!

_Yank
User Off Offline

Quote
Tabs should help you but the problem was not tabs. I said tabs because makes the script understand easier.
The problem is you forgot to add an end.

old Re: Shop Script Doesnt Work Right!

KimKat
GAME BANNED Off Offline

Quote
If you have a Lua script with no tabbing and much lines of code such as if statements and perhaps also switches and so on. Then it's most likely the case that the script fails to properly run well.
The basics of tabbing. In code a tab is done like this.
1
\t = "	"

old Re: Shop Script Doesnt Work Right!

EngiN33R
Moderator Off Offline

Quote
user KimKat has written
If you have a Lua script with no tabbing and much lines of code such as if statements and perhaps also switches and so on. Then it's most likely the case that the script fails to properly run well.

Unlike some other languages, Lua doesn't care about tabbing. However, if you have a script with no tabbing and lots of code it's likely you missed something - like in this case.

user KimKat has written
The basics of tabbing. In code a tab is done like this.
1
\t = "	"

In Lua code that isn't possible and will give you an error. Please don't advise others on Lua unless you have a good understanding of it yourself.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview