SA-MP Forums Archive
[HELP]In This Command - 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: [HELP]In This Command (/showthread.php?tid=614029)



[HELP]In This Command - Immortal99 - 03.08.2016

Can someone help me fix this /kickall cmd ?

My Code:

Код:
CMD:kickall(playerid,params[])
{
        if (adlvl[playerid] < 6) return 0;
        new string[1000];
        format(string,sizeof(string),""COLOR_BLUE"{FF0000}[SERVER]:{FFFFFF} Admin\"%s (%d)\" has kicked all players except admins",GetName(playerid),playerid);
      	SendClientMessageToAll(-1,string);
		for(new i=0; i < MAX_PLAYERS; i++)
		{
			if (adlvl[playerid] < 5)
        	{	Kick(i);	}
        }
		return 1;
}
My Error:

Код:
C:\Users\xavie\Desktop\Elite Gaming Server 0.3.7-R2\gamemodes\EliteGaming.pwn(23801) : error 001: expected token: "-string end-", but found "-identifier-"
C:\Users\xavie\Desktop\Elite Gaming Server 0.3.7-R2\gamemodes\EliteGaming.pwn(23801) : warning 215: expression has no effect
C:\Users\xavie\Desktop\Elite Gaming Server 0.3.7-R2\gamemodes\EliteGaming.pwn(23801) : error 001: expected token: ";", but found "-string-"
C:\Users\xavie\Desktop\Elite Gaming Server 0.3.7-R2\gamemodes\EliteGaming.pwn(23801) : warning 215: expression has no effect
C:\Users\xavie\Desktop\Elite Gaming Server 0.3.7-R2\gamemodes\EliteGaming.pwn(23801) : error 017: undefined symbol "GetName"
C:\Users\xavie\Desktop\Elite Gaming Server 0.3.7-R2\gamemodes\EliteGaming.pwn(23801) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.



Re: [HELP]In This Command - Luicy. - 03.08.2016

PHP код:
CMD:kickall(playerid,params[])
{
    if (
adlvl[playerid] < 6) return 0;
    new 
string[144], namr[MAX_PLAYER_NAME];
    
GetPlayerName(playerid24namr);
    
format(string,sizeof(string),""COLOR_BLUE"{FF0000}[SERVER]:{FFFFFF} Admin %s (%d) has kicked all players except admins",namr,playerid);
    
SendClientMessageToAll(-1,string);
    for(new 
0MAX_PLAYERSi++)
        if (
adlvl[playerid] < 5)
            
Kick(i);
    return 
1;

If there's still errors, tell me the exact line.


Re: [HELP]In This Command - AndySedeyn - 03.08.2016

Is COLOR_BLUE defined as an embedded color code? Also, you don't need 1000 cells in this case! You're wasting a lot of memory there.


Re: [HELP]In This Command - WhiteGhost - 03.08.2016

Код:
stock GetName(playerid)
{
    new Name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, Name, sizeof(Name));
    return Name;
}


CMD:kickall(playerid,params[])
{
   new string[100];
   if (adlvl[playerid] < 6) return 0;
   for(new i=0; i < MAX_PLAYERS; i++)
   {
   	Kick(i);
   }
   format(string,sizeof(string),"{FF0000}[SERVER]:{FFFFFF} Admin\"%s (%d)\" has kicked all players except admins",GetName(playerid),playerid);
   SendClientMessageToAll(-1,string);
   return 1;
}



Re: [HELP]In This Command - Luicy. - 03.08.2016

Quote:
Originally Posted by WhiteGhost
Посмотреть сообщение
Код:
stock GetName(playerid)
{
    new Name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, Name, sizeof(Name));
    return Name;
}


CMD:kickall(playerid,params[])
{
   new string[100];
   if (adlvl[playerid] < 6) return 0;
   for(new i=0; i < MAX_PLAYERS; i++)
   {
   if (adlvl[playerid] < 5)
   {
   	Kick(i);
   }
   format(string,sizeof(string),"{FF0000}[SERVER]:{FFFFFF} Admin\"%s (%d)\" has kicked all players except admins",GetName(playerid),playerid);
   SendClientMessageToAll(-1,string);
   return 1;
}
Just saying, you should never format a string in a loop, we already know format() is slow, imagine format the same thing for all players online, that's just waste of CPU.
And, why bother sending a message if you're kicking everyone first xD.


Re: [HELP]In This Command - JustMe.77 - 03.08.2016

Here's the missing stock, add it somewhere in the script

stock GetName(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
return name;
}

Edit:

Oh, to late


Re: [HELP]In This Command - K0P - 03.08.2016

Ok let me explain whats wrong in simple words:

In most scripts the color defines which start from the word "COLOR" are the pawn colors like this one "0xFFFFFFFF",and the ones which start from "COL_" are hex codes if im not wrong,they are like "{FFFFFF}"

The functions like "SendClientMessage" use the "COLOR" defines,and in dialogs you have to use that "COL_" one otherwise you will get errors.

And the other error for the function GetName(playerid):

Код:
stock GetName(playerid)
{
    new Name[50];
    GetPlayerName(playerid, Name, sizeof(Name));
    return Name;
}
And you loop wont check the admin level because there you are using "adlvl[playerid] < 5",it should be "adlvl[i] < 5"

Also you should optimize the loop a bit otherwise you will face server lag or even crashes:

Код:
for(new i = 0; i < MAX_PLAYERS; i++)
{
    if(IsPlayerConnected(i))
    {
        if(adlvl[i] < 5)
        {
            Kick(i);
        }
    }
}



Re: [HELP]In This Command - Konstantinos - 03.08.2016

Two notes:

- foreach/y_iterate or player pools (added in 0.3.7) are both recommended than the standard way.
- As of 0.3x, you need to delay the kick if you want the player who got kicked to see a message/dialog etc.

Quote:
Originally Posted by K0P
Посмотреть сообщение
Also you should optimize the loop a bit otherwise you will face server lag or even crashes
Loops don't crash.