SA-MP Forums Archive
/admins - 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)
+--- Thread: /admins (/showthread.php?tid=608109)



/admins - JXF - 27.05.2016

Код:
C:\Users\Marius\Desktop\GM\gamemodes\GM.pwn(448) : warning 217: loose indentation
C:\Users\Marius\Desktop\GM\gamemodes\GM.pwn(463) : error 030: compound statement not closed at the end of file (started at line 400)
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
Код:
CMD:admins(playerid, params[])
{
	new sendername[MAX_PLAYER_NAME], string[128];

	if(IsPlayerConnected(playerid))
	{
	SCM(pid, -1, "{FF6600}Online {FFFFFF}Admins");
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
	    if(IsPlayerConnected(i))
	    {
	    
	        if(Player[i][pAdmin] == 1338)
	        {
	        GetPlayerName(i, sendername, sizeof(sendername));
	        format(string, sizeof(string), "Server Founder: {FF0000}%s", sendername);
	        SCM(pid, COLOR_WHITE, string);
			}
			if(Player[i][pAdmin] == 1337)
			{
			GetPlayerName(i, sendername, sizeof(sendername));
			format(string, sizeof(string), "Server Manager: {A31818}%s", sendername);
			SCM(pid, COLOR_WHITE, string);
			}
			if(Player[i][pAdmin] == 5)
			{
			GetPlayerName(i, sendername, sizeof(sendername));
			format(string, sizeof(string), "Server Mapper: {0080FF}%s", sendername);
			SCM(pid, COLOR_WHITE, string);
			}
			if(Player[i][pAdmin] == 4)
			{
			GetPlayerName(i, sendername, sizeof(sendername));
			format(string, sizeof(string), "Leader Coordinator: {6633CC}%s", sendername);
			SCM(pid, COLOR_WHITE, string);
			}
			if(Player[i][pAdmin] == 3)
			{
			GetPlayerName(i, sendername, sizeof(sendername));
			format(string, sizeof(string), "Server Guardian: {A173FF}%s", sendername);
			SCM(pid, COLOR_WHITE, string);
			}
			if(Player[i][pAdmin] == 2)
			{
			GetPlayerName(i, sendername, sizeof(sendername));
			format(string, sizeof(string), "Server Moderator: {5CFEADFF}%s", sendername);
			SCM(pid, COLOR_WHITE, string);
			}
			if(Player[i][pAdmin] == 1)
			{
			GetPlayerName(i, sendername, sizeof(sendername));
			format(string, sizeof(string), "Trial Admin: {94FEC9FF}%s", sendername);
			
		}
		else
		{
		    if(!IsPlayerConnected(i))
		    {
				format(string, sizeof(string), "{08FC9A}There are no admins online.");
				SCM(pid, -1, string);
			}
 			return 1;
		}
	}
}
What's the problem?


Re: /admins - izeatfishz - 27.05.2016

Код:
CMD:admins(playerid, params[])
{
	new sendername[MAX_PLAYER_NAME], string[128];

	if(IsPlayerConnected(playerid))
	{
	SCM(pid, -1, "{FF6600}Online {FFFFFF}Admins");
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
	    if(IsPlayerConnected(i))
	    {
	    
	        if(Player[i][pAdmin] == 1338)
	        {
	        	GetPlayerName(i, sendername, sizeof(sendername));
	        	format(string, sizeof(string), "Server Founder: {FF0000}%s", sendername);
	        	SCM(pid, COLOR_WHITE, string);
		}
		if(Player[i][pAdmin] == 1337)
		{
			GetPlayerName(i, sendername, sizeof(sendername));
			format(string, sizeof(string), "Server Manager: {A31818}%s", sendername);
			SCM(pid, COLOR_WHITE, string);
		}
		if(Player[i][pAdmin] == 5)
		{
			GetPlayerName(i, sendername, sizeof(sendername));
			format(string, sizeof(string), "Server Mapper: {0080FF}%s", sendername);
			SCM(pid, COLOR_WHITE, string);
		}
		if(Player[i][pAdmin] == 4)
		{
			GetPlayerName(i, sendername, sizeof(sendername));
			format(string, sizeof(string), "Leader Coordinator: {6633CC}%s", sendername);
			SCM(pid, COLOR_WHITE, string);
		}
		if(Player[i][pAdmin] == 3)
		{
			GetPlayerName(i, sendername, sizeof(sendername));
			format(string, sizeof(string), "Server Guardian: {A173FF}%s", sendername);
			SCM(pid, COLOR_WHITE, string);
		}
		if(Player[i][pAdmin] == 2)
		{
			GetPlayerName(i, sendername, sizeof(sendername));
			format(string, sizeof(string), "Server Moderator: {5CFEADFF}%s", sendername);
			SCM(pid, COLOR_WHITE, string);
		}
		if(Player[i][pAdmin] == 1)
		{
			GetPlayerName(i, sendername, sizeof(sendername));
			format(string, sizeof(string), "Trial Admin: {94FEC9FF}%s", sendername);
		}
		else
		{
			if(!IsPlayerConnected(i))
		        {
				format(string, sizeof(string), "{08FC9A}There are no admins online.");
				SCM(pid, -1, string);
		  	}
 			return 1;
		}
	}
}



Re: /admins - JXF - 27.05.2016

Quote:
Originally Posted by izeatfishz
Посмотреть сообщение
Код:
CMD:admins(playerid, params[])
{
	new sendername[MAX_PLAYER_NAME], string[128];

	if(IsPlayerConnected(playerid))
	{
	SCM(pid, -1, "{FF6600}Online {FFFFFF}Admins");
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
	    if(IsPlayerConnected(i))
	    {
	    
	        if(Player[i][pAdmin] == 1338)
	        {
	        	GetPlayerName(i, sendername, sizeof(sendername));
	        	format(string, sizeof(string), "Server Founder: {FF0000}%s", sendername);
	        	SCM(pid, COLOR_WHITE, string);
		}
		if(Player[i][pAdmin] == 1337)
		{
			GetPlayerName(i, sendername, sizeof(sendername));
			format(string, sizeof(string), "Server Manager: {A31818}%s", sendername);
			SCM(pid, COLOR_WHITE, string);
		}
		if(Player[i][pAdmin] == 5)
		{
			GetPlayerName(i, sendername, sizeof(sendername));
			format(string, sizeof(string), "Server Mapper: {0080FF}%s", sendername);
			SCM(pid, COLOR_WHITE, string);
		}
		if(Player[i][pAdmin] == 4)
		{
			GetPlayerName(i, sendername, sizeof(sendername));
			format(string, sizeof(string), "Leader Coordinator: {6633CC}%s", sendername);
			SCM(pid, COLOR_WHITE, string);
		}
		if(Player[i][pAdmin] == 3)
		{
			GetPlayerName(i, sendername, sizeof(sendername));
			format(string, sizeof(string), "Server Guardian: {A173FF}%s", sendername);
			SCM(pid, COLOR_WHITE, string);
		}
		if(Player[i][pAdmin] == 2)
		{
			GetPlayerName(i, sendername, sizeof(sendername));
			format(string, sizeof(string), "Server Moderator: {5CFEADFF}%s", sendername);
			SCM(pid, COLOR_WHITE, string);
		}
		if(Player[i][pAdmin] == 1)
		{
			GetPlayerName(i, sendername, sizeof(sendername));
			format(string, sizeof(string), "Trial Admin: {94FEC9FF}%s", sendername);
		}
		else
		{
			if(!IsPlayerConnected(i))
		        {
				format(string, sizeof(string), "{08FC9A}There are no admins online.");
				SCM(pid, -1, string);
		  	}
 			return 1;
		}
	}
}
I appreciate that you helped to space my script out, but it doesn't fix anything, lol.


Re: /admins - oMa37 - 27.05.2016

PHP код:
CMD:admins(playeridparams[])
{
    new 
sendername[MAX_PLAYER_NAME], string[128];
    
SCM(pid, -1"{FF6600}Online {FFFFFF}Admins");
    for(new 
0MAX_PLAYERSi++)
    {
        if(
IsPlayerConnected(i))
        {
            if(
Player[i][pAdmin] == 1338)
            {
                
GetPlayerName(isendernamesizeof(sendername));
                
format(stringsizeof(string), "Server Founder: {FF0000}%s"sendername);
                
SCM(pidCOLOR_WHITEstring);
            }
            if(
Player[i][pAdmin] == 1337)
            {
                
GetPlayerName(isendernamesizeof(sendername));
                
format(stringsizeof(string), "Server Manager: {A31818}%s"sendername);
                
SCM(pidCOLOR_WHITEstring);
            }
            if(
Player[i][pAdmin] == 5)
            {
                
GetPlayerName(isendernamesizeof(sendername));
                
format(stringsizeof(string), "Server Mapper: {0080FF}%s"sendername);
                
SCM(pidCOLOR_WHITEstring);
            }
            if(
Player[i][pAdmin] == 4)
            {
                
GetPlayerName(isendernamesizeof(sendername));
                
format(stringsizeof(string), "Leader Coordinator: {6633CC}%s"sendername);
                
SCM(pidCOLOR_WHITEstring);
            }
            if(
Player[i][pAdmin] == 3)
            {
                
GetPlayerName(isendernamesizeof(sendername));
                
format(stringsizeof(string), "Server Guardian: {A173FF}%s"sendername);
                
SCM(pidCOLOR_WHITEstring);
            }
            if(
Player[i][pAdmin] == 2)
            {
                
GetPlayerName(isendernamesizeof(sendername));
                
format(stringsizeof(string), "Server Moderator: {5CFEADFF}%s"sendername);
                
SCM(pidCOLOR_WHITEstring);
            }
            if(
Player[i][pAdmin] == 1)
            {
                
GetPlayerName(isendernamesizeof(sendername));
                
format(stringsizeof(string), "Trial Admin: {94FEC9FF}%s"sendername);
            }
        }
        else
        {
            if(!
IsPlayerConnected(i))
            {
                
format(stringsizeof(string), "{08FC9A}There are no admins online.");
                
SCM(pid, -1string);
            }
        }
    }
    return 
1;




Re: /admins - F1N4L - 27.05.2016

He missed close Brackets

Код:
CMD:admins(playerid, params[])
{
	new sendername[MAX_PLAYER_NAME], string[128];

	if(IsPlayerConnected(playerid))
	{
	SCM(pid, -1, "{FF6600}Online {FFFFFF}Admins");
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
	    if(IsPlayerConnected(i))
	    {
	    
	        if(Player[i][pAdmin] == 1338)
	        {
	        GetPlayerName(i, sendername, sizeof(sendername));
	        format(string, sizeof(string), "Server Founder: {FF0000}%s", sendername);
	        SCM(pid, COLOR_WHITE, string);
			}
			if(Player[i][pAdmin] == 1337)
			{
			GetPlayerName(i, sendername, sizeof(sendername));
			format(string, sizeof(string), "Server Manager: {A31818}%s", sendername);
			SCM(pid, COLOR_WHITE, string);
			}
			if(Player[i][pAdmin] == 5)
			{
			GetPlayerName(i, sendername, sizeof(sendername));
			format(string, sizeof(string), "Server Mapper: {0080FF}%s", sendername);
			SCM(pid, COLOR_WHITE, string);
			}
			if(Player[i][pAdmin] == 4)
			{
			GetPlayerName(i, sendername, sizeof(sendername));
			format(string, sizeof(string), "Leader Coordinator: {6633CC}%s", sendername);
			SCM(pid, COLOR_WHITE, string);
			}
			if(Player[i][pAdmin] == 3)
			{
			GetPlayerName(i, sendername, sizeof(sendername));
			format(string, sizeof(string), "Server Guardian: {A173FF}%s", sendername);
			SCM(pid, COLOR_WHITE, string);
			}
			if(Player[i][pAdmin] == 2)
			{
			GetPlayerName(i, sendername, sizeof(sendername));
			format(string, sizeof(string), "Server Moderator: {5CFEADFF}%s", sendername);
			SCM(pid, COLOR_WHITE, string);
			}
			if(Player[i][pAdmin] == 1)
			{
			GetPlayerName(i, sendername, sizeof(sendername));
			format(string, sizeof(string), "Trial Admin: {94FEC9FF}%s", sendername);
			
		}
		else
		{
		    if(!IsPlayerConnected(i))
		    {
				format(string, sizeof(string), "{08FC9A}There are no admins online.");
				SCM(pid, -1, string);
			}
 			return 1;
		}
	}
}
}
}



Re: /admins - JXF - 27.05.2016

Quote:
Originally Posted by oMa37
Посмотреть сообщение
PHP код:
CMD:admins(playeridparams[])
{
    new 
sendername[MAX_PLAYER_NAME], string[128];
    
SCM(pid, -1"{FF6600}Online {FFFFFF}Admins");
    for(new 
0MAX_PLAYERSi++)
    {
        if(
IsPlayerConnected(i))
        {
            if(
Player[i][pAdmin] == 1338)
            {
                
GetPlayerName(isendernamesizeof(sendername));
                
format(stringsizeof(string), "Server Founder: {FF0000}%s"sendername);
                
SCM(pidCOLOR_WHITEstring);
            }
            if(
Player[i][pAdmin] == 1337)
            {
                
GetPlayerName(isendernamesizeof(sendername));
                
format(stringsizeof(string), "Server Manager: {A31818}%s"sendername);
                
SCM(pidCOLOR_WHITEstring);
            }
            if(
Player[i][pAdmin] == 5)
            {
                
GetPlayerName(isendernamesizeof(sendername));
                
format(stringsizeof(string), "Server Mapper: {0080FF}%s"sendername);
                
SCM(pidCOLOR_WHITEstring);
            }
            if(
Player[i][pAdmin] == 4)
            {
                
GetPlayerName(isendernamesizeof(sendername));
                
format(stringsizeof(string), "Leader Coordinator: {6633CC}%s"sendername);
                
SCM(pidCOLOR_WHITEstring);
            }
            if(
Player[i][pAdmin] == 3)
            {
                
GetPlayerName(isendernamesizeof(sendername));
                
format(stringsizeof(string), "Server Guardian: {A173FF}%s"sendername);
                
SCM(pidCOLOR_WHITEstring);
            }
            if(
Player[i][pAdmin] == 2)
            {
                
GetPlayerName(isendernamesizeof(sendername));
                
format(stringsizeof(string), "Server Moderator: {5CFEADFF}%s"sendername);
                
SCM(pidCOLOR_WHITEstring);
            }
            if(
Player[i][pAdmin] == 1)
            {
                
GetPlayerName(isendernamesizeof(sendername));
                
format(stringsizeof(string), "Trial Admin: {94FEC9FF}%s"sendername);
            }
        }
        else
        {
            if(!
IsPlayerConnected(i))
            {
                
format(stringsizeof(string), "{08FC9A}There are no admins online.");
                
SCM(pid, -1string);
            }
        }
    }
    return 
1;

Cheers.


Re: /admins - Konstantinos - 27.05.2016

Let's optimize it, shall we?

- foreach is recommended for player loops, if you don't want to use it then use atleast GetPlayerPoolSize.
- switch is faster than many if statements
- in order to send a message that no admins are online the loop MUST finish first.
- NEVER use return in loops unless you want to stop them

PHP код:
CMD:admins(playeridparams[]) 
{
    new 
sendername[MAX_PLAYER_NAME], string[128], count;
    
SCM(pid, -1"{FF6600}Online {FFFFFF}Admins");
    for (new 
0GetPlayerPoolSize(); <= ji++) // foreach(new i : Player)
    
{
        if (!
IsPlayerConnected(i)) continue;
        
GetPlayerName(isendernamesizeof(sendername));
        switch (
Player[i][pAdmin])
        {
            case 
1338format(stringsizeof(string), "Server Founder: {FF0000}%s"sendername);
            case 
1337format(stringsizeof(string), "Server Manager: {A31818}%s"sendername);
            case 
5format(stringsizeof(string), "Server Mapper: {0080FF}%s"sendername);
            case 
4format(stringsizeof(string), "Leader Coordinator: {6633CC}%s"sendername);
            case 
3format(stringsizeof(string), "Server Guardian: {A173FF}%s"sendername);
            case 
2format(stringsizeof(string), "Server Moderator: {5CFEADFF}%s"sendername);
            case 
1format(stringsizeof(string), "Trial Admin: {94FEC9FF}%s"sendername);
        }
        
SCM(pid, -1string);
        
count++;
    }
    if (!
countSCM(pid, -1"{08FC9A}There are no admins online.");
    return 
1;




Re: /admins - JXF - 27.05.2016

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Let's optimize it, shall we?

- foreach is recommended for player loops, if you don't want to use it then use atleast GetPlayerPoolSize.
- switch is faster than many if statements
- in order to send a message that no admins are online the loop MUST finish first.
- NEVER use return in loops unless you want to stop them

PHP код:
CMD:admins(playeridparams[]) 
{
    new 
sendername[MAX_PLAYER_NAME], string[128], count;
    
SCM(pid, -1"{FF6600}Online {FFFFFF}Admins");
    for (new 
0GetPlayerPoolSize(); <= ji++) // foreach(new i : Player)
    
{
        if (!
IsPlayerConnected(i)) continue;
        
GetPlayerName(isendernamesizeof(sendername));
        switch (
Player[i][pAdmin])
        {
            case 
1338format(stringsizeof(string), "Server Founder: {FF0000}%s"sendername);
            case 
1337format(stringsizeof(string), "Server Manager: {A31818}%s"sendername);
            case 
5format(stringsizeof(string), "Server Mapper: {0080FF}%s"sendername);
            case 
4format(stringsizeof(string), "Leader Coordinator: {6633CC}%s"sendername);
            case 
3format(stringsizeof(string), "Server Guardian: {A173FF}%s"sendername);
            case 
2format(stringsizeof(string), "Server Moderator: {5CFEADFF}%s"sendername);
            case 
1format(stringsizeof(string), "Trial Admin: {94FEC9FF}%s"sendername);
        }
        
SCM(pid, -1string);
        
count++;
    }
    if (!
countSCM(pid, -1"{08FC9A}There are no admins online.");
    return 
1;

The "there are no admins online" message is not shown
has the loop not finished?
also where could I put the message: "There are currently %d admins online"


Re: /admins - Konstantinos - 27.05.2016

Quote:
Originally Posted by JXF
Посмотреть сообщение
The "there are no admins online" message is not shown
has the loop not finished?
also where could I put the message: "There are currently %d admins online"
It will only be shown if there are no admins online. In your code, it'd be spammed for all the offline players.

Add an alternative of else to the switch just in case:
Код:
...
case 1: format(string, sizeof(string), "Trial Admin: {94FEC9FF}%s", sendername);
default: continue;
and about how many admins:
pawn Код:
if (!count) SCM(pid, -1, "{08FC9A}There are no admins online.");
else
{
    format(string, sizeof(string), "There are currently %d admins online", count);
    SCM(pid, -1, string);
}



Re: /admins - YaQi - 27.05.2016

It's nothing, just you must add (count++) in everyline in an case or in every { }

Example:
Код:
if(Player[i][pAdmin] == 1337)
	{
		GetPlayerName(i, sendername, sizeof(sendername));
		format(string, sizeof(string), "Server Manager: {A31818}%s", sendername);
		SCM(pid, COLOR_WHITE, string);
                count++
	}
Good Luck!