Forum

> > CS2D > Scripts > Two "if" Statements
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Two "if" Statements

10 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Two "if" Statements

ExecL
User Off Offline

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

alt Re: Two "if" Statements

MikuAuahDark
User Off Offline

Zitieren
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

alt Re: Two "if" Statements

ExecL
User Off Offline

Zitieren
user MikuAuahDark hat geschrieben
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

alt Re: Two "if" Statements

EngiN33R
Moderator Off Offline

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

alt Re: Two "if" Statements

ExecL
User Off Offline

Zitieren
user EngiN33R hat geschrieben
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

alt Re: Two "if" Statements

EngiN33R
Moderator Off Offline

Zitieren
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

alt Re: Two "if" Statements

ExecL
User Off Offline

Zitieren
user EngiN33R hat geschrieben
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.

alt Re: Two "if" Statements

EngiN33R
Moderator Off Offline

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

alt Re: Two "if" Statements

ExecL
User Off Offline

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

alt Re: Two "if" Statements

Alistaire
User Off Offline

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

alt Re: Two "if" Statements

krabob
User Off Offline

Zitieren
@user Alistaire:

user Alistaire hat geschrieben
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 hat geschrieben
addhook("serveraction","menu")


Just a confusion with the names, menu(id,act) is right as the hook is 'serveraction'
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht