English Buy menu doesnt work

8 replies
Goto Page
To the start Previous 1 Next To the start
09.09.13 02:08:16 pm
Up
alex72super
User
Offline Off
Hello i made a buy menu but its doenst work:

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
addhook("serveraction","lol")
function lol(id,act)
     if act == 1
          menu(id,"Buy Guns,Deagle,M3,M4A1,AWP") then
     end
end

addhook("serveraction","ki")
function ki(id,act)
      if act == 2
           menu(id,"Buy HP,Bandage,Medikit")
      end
end

if title=="Deagle" then
if buton==1 then
     if player(id,"money")>=600 then
          parse("equip "..id.." 3")
          msg2(id,"©000000255You bought a Deagle!@C")
          parse("setmoney "..id.." "..(player(id,"money")-600))
     else
          msg2(id,"©255000000You Don't have enough money!@C")
          end
     end
end


Can anyone help?
09.09.13 02:13:49 pm
Up
brofistmsia
User
Offline Off
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
42
43
44
45
46
47
48
49
50
addhook('serveraction','serveraction_buymenu')
function serveraction_buymenu(id,act)
     if act==1 then
          menu(id,'Buy guns,Weapon')
     end
end

addhook('menu','menu_buymenu')
function menu_buymenu(id,title,buton)
     if title=='Buy guns' then
          if buton==1 then
               menu(id,'Weapon,Deagle|$100,M3|$100,M4A1|$100,AWP|$100')
          end
     end
     if title=='Weapon' then
          if buton==1 then
               if player(id,'money')>=100 then
                    parse('setmoney '..id..' '..player(id,'money')-100)
                    parse('equip '..id..' 3')
                    parse('setweapon '..id..' 3')
               else
                    msg('©255000000Money is low@C')
               end
          elseif buton==2 then
               if player(id,'money')>=100 then
                    parse('setmoney '..id..' '..player(id,'money')-100)
                    parse('equip '..id..' 10')
                    parse('setweapon '..id..' 10')
               else
                    msg('©255000000Money is low@C')
               end
          elseif buton==3 then
               if player(id,'money')>=100 then
                    parse('setmoney '..id..' '..player(id,'money')-100)
                    parse('equip '..id..' 32')
                    parse('setweapon '..id..' 32')
               else
                    msg('©255000000Money is low@C')
               end
          elseif buton==4 then
               if player(id,'money')>=100 then
                    parse('setmoney '..id..' '..player(id,'money')-100)
                    parse('equip '..id..' 35')
                    parse('setweapon '..id..' 35')
               else
                    msg('©255000000Money is low@C')
               end
          end
     end
end


one example for guns, the others, i have no time to write it, press f2. i just learn this 1 month ago

Admin/mod comment:

Edited your post to include code indentation. Do yourself and all of us a favour and tab your code. /EngiN33R
09.09.13 02:18:22 pm
Up
GrizzlyAtlas
User
Offline Off
there is a couple of times when you state a condition after an if but you don't compliment it with a then, I am not very experienced, I have only programmed a little in java so far, so tell my if I´m wrong.
for example:
if act == 1 then
menu(id,"Buy Guns,Deagle,M3,M4A1,AWP")
else...
09.09.13 02:28:51 pm
Up
brofistmsia
User
Offline Off
Just use my code as a guide...
09.09.13 02:30:12 pm
Up
Rainoth
Moderator
Offline Off
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
addhook("serveraction","lol")
function lol(id,b)
     if b == 1 then
          menu(id,"Buy Guns,Deagle,M3,M4A1,AWP")
     elseif b == 2 then
          menu(id,"Buy HP,Bandage,Medikit")
     end
end

addhook("menu","potato")
function potato(id,t,b)
local cash = player(id,"money")
     if t=="Buy Guns" then
          if b==1 then
                   if cash>=600 then
                         parse("equip "..id.." 3")
                         msg2(id,"©000000255You bought a Deagle!@C")
                         parse("setmoney "..id.." "..(player(id,"money")-600))
                    else
                         msg2(id,"©255000000You Don't have enough money!@C")
                    end
               end
     end
end


Don't use multiple hooks of same type. Add "then" for every "if" always check the name of menu you're making, use elseif instead of making another hook.

Sorry for tabbing, can't do it properly in reply.
edited 1×, last 09.09.13 02:58:45 pm
MAL • DeviantArt • For Wallpaper Engine users • Check YT for playlists... •
09.09.13 02:45:00 pm
Up
alex72super
User
Offline Off
Thank you all !

I am still learning lua and now im trying to do a zombie survival script thanks everyone

LUA ERROR: sys/lua/autorun/serveraction.lua:4: 'then' expected near 'menu'

Didnt work

EDIT2: Using user brofistmsia script it worked you'll be credited
edited 2×, last 09.09.13 02:55:05 pm
09.09.13 02:46:22 pm
Up
brofistmsia
User
Offline Off
So use your one as sure, ok. I try.
09.09.13 03:16:07 pm
Up
Dynamite07
User
Offline Off
Idea: would you like "cs2d cmd strip" so you cant have more than 1 pistol or 1 primary gun...
09.09.13 06:46:52 pm
Up
alex72super
User
Offline Off
user Dynamite07 has written:
Idea: would you like "cs2d cmd strip" so you cant have more than 1 pistol or 1 primary gun...


If you help me do it i would like that, im still learning lua and right now im making a script to use with the map(the map is done).
To the start Previous 1 Next To the start