SA-MP Forums Archive
[SOLVED] command with else etc. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [SOLVED] command with else etc. (/showthread.php?tid=119090)



[SOLVED] command with else etc. - security - 06.01.2010

i just started to script again and i tried to do it bymyself and not to take anything of the internet, but my command is little buggy:
Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/acp", cmdtext, true, 10) == 0)
	{
		IsPlayerAdmin(playerid);
		{
			ShowMenuForPlayer(AdminMenu,playerid);
			return 1;
		}
	}
	else SendClientMessage(playerid, 0xFFFFFFFF, "You need to be admin for this command");
	return 0;
}
when i remove:
Код:
else SendClientMessage(playerid, 0xFFFFFFFF, "You need to be admin for this command");
i can use it only as admin with it as admin and normal player, how to change it? i want a message so if you are a player and you do /acp i want a message: "you need to be.." wo can help me? srry for bad english xD


Re: command with else etc. - GTAguillaume - 06.01.2010

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/acp", cmdtext, true,4) == 0) // '/acp' has 4 characters not 10
	{
		if(IsPlayerAdmin(playerid)); //you fogot an 'if'
		{
			ShowMenuForPlayer(AdminMenu,playerid);
			return 1;
		}
		else SendClientMessage(playerid, 0xFFFFFFFF, "You need to be admin for this command");
	}
	//not here lol
	return 0;
}



Re: command with else etc. - ClanDBZVegeta - 06.01.2010

SO Thats how u do it thanks for telling man


Re: command with else etc. - security - 06.01.2010

Quote:
Originally Posted by GTAguillaume
Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/acp", cmdtext, true,4) == 0) // '/acp' has 4 characters not 10
	{
		if(IsPlayerAdmin(playerid)); //you fogot an 'if'
		{
			ShowMenuForPlayer(AdminMenu,playerid);
			return 1;
		}
		else SendClientMessage(playerid, 0xFFFFFFFF, "You need to be admin for this command");
	}
	//not here lol
	return 0;
}
ty


Re: command with else etc. - [03]Garsino - 06.01.2010

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/acp", cmdtext, true, 4) == 0) // Don't use 10 when the command text is 4 in total with "/".
    {
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFFFF, "You need to be admin for this command");
    else
    ShowMenuForPlayer(AdminMenu,playerid);
    return 1;
    }
/*=======================================================================================================================================*/
    }
    return 0;
}



Re: command with else etc. - security - 06.01.2010

both give error ? first post:

Код:
C:\Documents and Settings\Doodaapje\Bureaublad\FS & GM\ADMIN\admin.pwn(47) : error 036: empty statement
C:\Documents and Settings\Doodaapje\Bureaublad\FS & GM\ADMIN\admin.pwn(52) : warning 225: unreachable code
C:\Documents and Settings\Doodaapje\Bureaublad\FS & GM\ADMIN\admin.pwn(52) : error 029: invalid expression, assumed zero
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Errors.

other:


Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/acp", cmdtext, true, 4) == 0) // Don't use 10 when the command text is 4 in total with "/".
{
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFFFFFF, "You need to be admin for this command");
else
ShowMenuForPlayer(AdminMenu,playerid);
return 1;
}
/*=======================================================================================================================================*/
}
return 0;
}



Re: command with else etc. - security - 06.01.2010

Quote:
Originally Posted by security
both give error ? first post:

Код:
C:\Documents and Settings\Doodaapje\Bureaublad\FS & GM\ADMIN\admin.pwn(47) : error 036: empty statement
C:\Documents and Settings\Doodaapje\Bureaublad\FS & GM\ADMIN\admin.pwn(52) : warning 225: unreachable code
C:\Documents and Settings\Doodaapje\Bureaublad\FS & GM\ADMIN\admin.pwn(52) : error 029: invalid expression, assumed zero
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Errors.

other:

Код:


C:\Documents and Settings\Doodaapje\Bureaublad\FS & GM\ADMIN\admin.pwn(53) : warning 209: function "OnPlayerCommandText" should return a value
C:\Documents and Settings\Doodaapje\Bureaublad\FS & GM\ADMIN\admin.pwn(54) : error 010: invalid function or declaration
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
srry for dubble post didnt pressed edit but quote i'm sorry


Re: command with else etc. - [03]Garsino - 06.01.2010

Show me line 54 and 53 ..


Re: command with else etc. - adsy - 06.01.2010

Quote:
Originally Posted by GTAguillaume
Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/acp", cmdtext, true,4) == 0) // '/acp' has 4 characters not 10
	{
		if(IsPlayerAdmin(playerid)); //you fogot an 'if'
		{
			ShowMenuForPlayer(AdminMenu,playerid);
			return 1;
		}
		else SendClientMessage(playerid, 0xFFFFFFFF, "You need to be admin for this command");
	}
	//not here lol
	return 0;
}
alternative

Код:
if(something == something etc etc){
script
}
else
{
script
}
this can also be used
Код:
else if (something == somethingelse etc etc)



Re: command with else etc. - security - 06.01.2010

Quote:
Originally Posted by adsy
Quote:
Originally Posted by GTAguillaume
Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/acp", cmdtext, true,4) == 0) // '/acp' has 4 characters not 10
	{
		if(IsPlayerAdmin(playerid)); //you fogot an 'if'
		{
			ShowMenuForPlayer(AdminMenu,playerid);
			return 1;
		}
		else SendClientMessage(playerid, 0xFFFFFFFF, "You need to be admin for this command");
	}
	//not here lol
	return 0;
}
alternative

Код:
if(something == something etc etc){
script
}
else
{
script
}
this can also be used
Код:
else if (something == somethingelse etc etc)
sorry i dont understand?