Forum

> > CS2D > Scripts > More than 9 classes (trying to add a "Next" button
Forums overviewCS2D overview Scripts overviewLog in to reply

English More than 9 classes (trying to add a "Next" button

17 replies
To the start Previous 1 Next To the start

old More than 9 classes (trying to add a "Next" button

Nori-chan
User Off Offline

Quote
Hello guys!

I'm really noob at LUA, so I tried to create a new class script. But, there's a problem, I have more than 9 classes, so I tried to add a "Next" button, but it seens that it doesn't work.
PS: Please note that I tried to add a "Next" button based on the code that Symp created (Cod4 classes)

Spoiler >

old Re: More than 9 classes (trying to add a "Next" button

Nori-chan
User Off Offline

Quote
user Yates has written
user Avo has written
Dinosaur function?

Stop stealing my crap. Also it's tool, not function.

---

@user Nori-chan: Any errors in the console? If not, what does not work; Does the menu not appear or do the buttons in your second menu not work?


No errors on console.
When I have to choose my class, the "Next" button appears, but if you choose it, the menu closes and you only get your normal respawn weapons (USP.45 or Glock, and a knife)

old Re: More than 9 classes (trying to add a "Next" button

Yates
Reviewer Off Offline

Quote
I see; It's because your menu only has 8 buttons.

This is how a menu is set-up:
1
menu("title,button1,button2,button3,button4,button5,button6,button7,button8,button9")
I guess you counted your title as a button which it is not. So you must check if the button is 8 instead of 9 to forward to another menu. This means your code here:
1
if (sel>=1 and sel<=8) then
Must change to:
1
if (sel>=1 and sel<=7) then

Also your second menu has the same kind of errors, I guess you should count your buttons again and make sure it checks the ones you want it to.

old Re: More than 9 classes (trying to add a "Next" button

Yates
Reviewer Off Offline

Quote
@user Nori-chan: I can also tell you why you spawn with normal weapons. Class 8 does not have any, it's basically empty. So when you click on your next button which is button 8 you are actually clicking on a class selecting one that makes you class 8.
edited 1×, last 28.02.13 07:02:13 pm

old Re: More than 9 classes (trying to add a "Next" button

Nori-chan
User Off Offline

Quote
user Yates has written
I see; It's because your menu only has 8 buttons.

This is how a menu is set-up:
1
menu("title,button1,button2,button3,button4,button5,button6,button7,button8,button9")
I guess you counted your title as a button which it is not. So you must check if the button is 8 instead of 9 to forward to another menu. This means your code here:
1
if (sel>=1 and sel<=8) then
Must change to:
1
if (sel>=1 and sel<=7) then

Also your second menu has the same kind of errors, I guess you should count your buttons again and make sure it checks the ones you want it to.


Fixed what you said, but now when I press "Next", it counts as another class, but the class have the same weapons as the previous class (eg, if I played with the second class before, choosing "Next" will have the same weapons. If "Next" is my first class to play, the weapons are the same from the first class)

old Re: More than 9 classes (trying to add a "Next" button

Yates
Reviewer Off Offline

Quote
Seeing as I don't get what you mean I guess you did it wrong soooo.. Your code looks like this?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
addhook("menu","sample.classes.menu")
function sample.classes.menu(id,menu,sel)
	if (menu=="Select your Class") then
		if (sel>=1 and sel<=7) then
			sample.classes.class[id]=sel
			if (player(id,"health")>0) then
				parse("killplayer "..id)
			end
		elseif (sel==8) then
			menu(id,"Select your class-Page2,Special Ops|FSLK200,Special Ops|SFG,Sniper|Long Range,Pointman|Heavy Hitters,Demolition|Tank Stance,Heavy Gunner|Bipod,Back")
		end
	end
	if (menu=="Select your class-Page2") then
		if (sel>=1 and sel<=9) then
			sample.classes.class[id]=sel+9
			if (player(id,"health")>0) then
				parse("killplayer "..id)
			end
		elseif (sel==6) then
			menu(id,"Select your Class,Assaulter|SFOD-D,Assaulter|Alfa Group,Assaulter|GIGN,Assaulter|Gadsar Nahal,Special Ops|EKO,Special Ops|SFOD-D,Special Ops|KSK,Next")
		end
	end
end
I also fixed your tabbing, it annoyed me.

old Re: More than 9 classes (trying to add a "Next" button

Nori-chan
User Off Offline

Quote
user Yates has written
Seeing as I don't get what you mean I guess you did it wrong soooo.. Your code looks like this?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
addhook("menu","sample.classes.menu")
function sample.classes.menu(id,menu,sel)
	if (menu=="Select your Class") then
		if (sel>=1 and sel<=7) then
			sample.classes.class[id]=sel
			if (player(id,"health")>0) then
				parse("killplayer "..id)
			end
		elseif (sel==8) then
			menu(id,"Select your class-Page2,Special Ops|FSLK200,Special Ops|SFG,Sniper|Long Range,Pointman|Heavy Hitters,Demolition|Tank Stance,Heavy Gunner|Bipod,Back")
		end
	end
	if (menu=="Select your class-Page2") then
		if (sel>=1 and sel<=9) then
			sample.classes.class[id]=sel+9
			if (player(id,"health")>0) then
				parse("killplayer "..id)
			end
		elseif (sel==6) then
			menu(id,"Select your Class,Assaulter|SFOD-D,Assaulter|Alfa Group,Assaulter|GIGN,Assaulter|Gadsar Nahal,Special Ops|EKO,Special Ops|SFOD-D,Special Ops|KSK,Next")
		end
	end
end
I also fixed your tabbing, it annoyed me.


Yes, except about the TAB, it's the same.

old Re: More than 9 classes (trying to add a "Next" button

Yates
Reviewer Off Offline

Quote
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("menu","sample.classes.menu")
function sample.classes.menu(id,title,sel)
     if (title=="Select your Class") then
          if (sel>=1 and sel<=7) then
               sample.classes.class[id]=sel
               if (player(id,"health")>0) then
                    parse("killplayer "..id)
               end
          elseif (sel==8) then
				msg2(id,"menu")
               menu(id,"Select your class-Page2,Special Ops|FSLK200,Special Ops|SFG,Sniper|Long Range,Pointman|Heavy Hitters,Demolition|Tank Stance,Heavy Gunner|Bipod,Back")
          end
     end
     if (title=="Select your class-Page2") then
          if (sel>=1 and sel<=9) then
               sample.classes.class[id]=sel+9
               if (player(id,"health")>0) then
                    parse("killplayer "..id)
               end
          elseif (sel==6) then
               menu(id,"Select your Class,Assaulter|SFOD-D,Assaulter|Alfa Group,Assaulter|GIGN,Assaulter|Gadsar Nahal,Special Ops|EKO,Special Ops|SFOD-D,Special Ops|KSK,Next")
          end
     end
end
There, I fixed it. I tested your code for myself and an error appeared, you have a parameter named the same as a Lua function which will spew out errors depending on what you want to do. So if you want to check a menu name use:
1
if (title == "random_title") then
(The brackets are not really necessary).

I also suggest you add a timer to the menu pop-up on spawn. I killed myself like 10 times just because when I click to spawn I accidentally click on a button.

But so far you seem to understand the basics of CS2D Lua. Keep it up.

old Re: More than 9 classes (trying to add a "Next" button

Nori-chan
User Off Offline

Quote
user Yates has written
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("menu","sample.classes.menu")
function sample.classes.menu(id,title,sel)
     if (title=="Select your Class") then
          if (sel>=1 and sel<=7) then
               sample.classes.class[id]=sel
               if (player(id,"health")>0) then
                    parse("killplayer "..id)
               end
          elseif (sel==8) then
				msg2(id,"menu")
               menu(id,"Select your class-Page2,Special Ops|FSLK200,Special Ops|SFG,Sniper|Long Range,Pointman|Heavy Hitters,Demolition|Tank Stance,Heavy Gunner|Bipod,Back")
          end
     end
     if (title=="Select your class-Page2") then
          if (sel>=1 and sel<=9) then
               sample.classes.class[id]=sel+9
               if (player(id,"health")>0) then
                    parse("killplayer "..id)
               end
          elseif (sel==6) then
               menu(id,"Select your Class,Assaulter|SFOD-D,Assaulter|Alfa Group,Assaulter|GIGN,Assaulter|Gadsar Nahal,Special Ops|EKO,Special Ops|SFOD-D,Special Ops|KSK,Next")
          end
     end
end
There, I fixed it. I tested your code for myself and an error appeared, you have a parameter named the same as a Lua function which will spew out errors depending on what you want to do. So if you want to check a menu name use:
1
if (title == "random_title") then
(The brackets are not really necessary).

I also suggest you add a timer to the menu pop-up on spawn. I killed myself like 10 times just because when I click to spawn I accidentally click on a button.

But so far you seem to understand the basics of CS2D Lua. Keep it up.


Sorry about the error, when I tested it before, I saw no errors.

But anyway, thank you for helping me.
You gonnna be added in the credits as a LUA coder (even if I not release for everyone, I will still have a credit list)

old Re: More than 9 classes (trying to add a "Next" button

Nori-chan
User Off Offline

Quote
Sorry to bother you again, but I was trying to add a page 3 for my weapons.
But I have the same error as before, that The weapons that I choose are the same from the previous class

Spoiler >


Still trying to fix by myself.

EDIT: Nevermid, I Fixed it.
edited 1×, last 28.02.13 08:49:55 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview