Forum

> > CS2D > Scripts > Two "if" Statements
Forums overviewCS2D overview Scripts overviewLog in to reply

English Two "if" Statements

10 replies
To the start Previous 1 Next To the start

old Two "if" Statements

ExecL
User Off Offline

Quote
I'm having a problem with this script, i'm trying to make two "if" statements but it's not working I've tried doing this

1
2
3
4
5
6
7
8
9
addhook("serveraction","menu")
function menu(id,act)
     if act == 1 then
     if rank(admin,id) then
   menu(id,"Menu,button,button,button,button,button")
else
	 msg2(id,"You don't have permisson to do that!")
     end
end

On line 4 is where the problem is, if i take away the code on line 4 it all works.

When i start the server up it just crashes if line 4 is there.

old Re: Two "if" Statements

MikuAuahDark
User Off Offline

Quote
just use "and" operation
1
2
3
4
5
6
7
8
addhook("serveraction","menu")
function menu(id,act)
	if act == 1 and rank("admin",id) then
		menu(id,"Menu,button,button,button,button,button")
	else
		msg2(id,"You don't have permisson to do that!")
   	end
end

old Re: Two "if" Statements

ExecL
User Off Offline

Quote
user MikuAuahDark has written
just use "and" operation
1
2
3
4
5
6
7
8
addhook("serveraction","menu")
function menu(id,act)
	if act == 1 and rank("admin",id) then
		menu(id,"Menu,button,button,button,button,button")
	else
		msg2(id,"You don't have permisson to do that!")
   	end
end


It did't not work

old Re: Two "if" Statements

EngiN33R
Moderator Off Offline

Quote
You lack one end.

1
2
3
4
5
6
7
8
9
10
addhook("serveraction","menu")
function menu(id,act)
     if act == 1 then
          if rank(admin,id) then
               menu(id,"Menu,button,button,button,button,button")
          else
               msg2(id,"You don't have permisson to do that!")
          end
     end
end

I'm not sure why user MikuAuahDark's didn't work though. Are you sure your rank function works well?

old Re: Two "if" Statements

ExecL
User Off Offline

Quote
user EngiN33R has written
You lack one end.

1
2
3
4
5
6
7
8
9
10
addhook("serveraction","menu")
function menu(id,act)
     if act == 1 then
          if rank(admin,id) then
               menu(id,"Menu,button,button,button,button,button")
          else
               msg2(id,"You don't have permisson to do that!")
          end
     end
end


I'm not sure why user MikuAuahDark's didn't work though. Are you sure your rank function works well?


Heres the whole code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
admin = {72075}

function rank(table,id)
     for _, u in ipairs(table) do
          if player(id,"usgn")== u then
               return true
          end
     end
     return false
end

addhook("serveraction","menu")
function menu(id,act)
     if act == 1 and if rank(admin,id) then
                    menu(id,"Menu,button,button,button,button,button")
          else
               msg2(id,"You don't have permisson to do that!")
          end
     end
end

old Re: Two "if" Statements

EngiN33R
Moderator Off Offline

Quote
No, you did it wrong! You only need to write if once, and then just connect them with and. So:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
admin = {72075}

function rank(table,id)
     for _, u in ipairs(table) do
          if player(id,"usgn")== u then
               return true
          end
     end
     return false
end

addhook("serveraction","menu")
function menu(id,act)
     if act == 1 and rank(admin,id) then
               menu(id,"Menu,button,button,button,button,button")
          else
               msg2(id,"You don't have permisson to do that!")
          end
     end
end

old Re: Two "if" Statements

ExecL
User Off Offline

Quote
user EngiN33R has written
No, you did it wrong! You only need to write if once, and then just connect them with and. So:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
admin = {72075}

function rank(table,id)
     for _, u in ipairs(table) do
          if player(id,"usgn")== u then
               return true
          end
     end
     return false
end

addhook("serveraction","menu")
function menu(id,act)
     if act == 1 and rank(admin,id) then
               menu(id,"Menu,button,button,button,button,button")
          else
               msg2(id,"You don't have permisson to do that!")
          end
     end
end


CS2D just crashes when i start up my server

Run it on yours.

old Re: Two "if" Statements

EngiN33R
Moderator Off Offline

Quote
There was an extra end that I did not notice.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
admin = {72075}

function rank(table,id)
	for _, u in ipairs(table) do
		if player(id,"usgn")== u then
			return true
		end
	end
	return false
end

addhook("serveraction","menu")
function menu(id,act)
	if act == 1 and rank(admin,id) then
		menu(id,"Menu,button,button,button,button,button")
	else
		msg2(id,"You don't have permisson to do that!")
	end
end

Tested to work.

old Re: Two "if" Statements

ExecL
User Off Offline

Quote
ahh, i tested it and when i press f2 it says "You don't have permisson to do that" the admin system is not working, damn it.

old Re: Two "if" Statements

Alistaire
User Off Offline

Quote
function menu(id, TITLE, button)
Not function menu(id, button). That's not how it works.

Your function now checks if the title is 1, not even a string.

old Re: Two "if" Statements

krabob
User Off Offline

Quote
@user Alistaire:

user Alistaire has written
function menu(id, TITLE, button)
Not function menu(id, button). That's not how it works.

Your function now checks if the title is 1, not even a string.


user ExecL has written
addhook("serveraction","menu")


Just a confusion with the names, menu(id,act) is right as the hook is 'serveraction'
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview