/ban command error
#1

Here is the code:
Код:
CMD:ban(playerid, params[])
{
   	if(PlayerInfo[playerid][pAdmin] < 3)
	{
    new id;
    new string[128];
    if(sscanf(params, "us[50]", id))return SendClientMessage(playerid, -1, "usage: /ban [id] ");
    if(IsPlayerConnected(id))
		{
  			if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "invalid player");
			format(string,sizeof(string),"admin '%s' has banned '%s' ",GetName(playerid),GetName(id));
		 	SendClientMessageToAll(COLOR_RED,string);
  			SetTimerEx("Banned",200,false,"d", id);
   			return SendClientMessage(playerid,COLOR_RED,"You have been banned by Admin!");
	    }
		else return  SendClientMessage(playerid, COLOR_RED, "The player is not in the server!");
	}
	else return SendClientMessage(playerid, COLOR_RED, "YOu need to be 3 level admin!");
}
Here is the error:
Код:
C:\Users\Ivailo\Desktop\Iordan\Servers\ALFA GAME ROLEPLAY\gamemodes\AG-RP.pwn(446) : error 017: undefined symbol "GetName"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
Reply
#2

Well it's more than obvious, you haven't defined GetName
Edit: if you are lazy as f**k like me add this under your functions:

pawn Код:
stock GetName(playerid)
{
    GetPlayerName(playerid, GetName,sizeof (GetName));
    return GetName;
}
Reply
#3

You have not defined the 'GetName'.

pawn Код:
CMD:ban(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] < 3)
    {
         new id;
         new string[128];
         if(sscanf(params, "us[50]", id))return SendClientMessage(playerid, -1, "usage: /ban [id] ");
         if(IsPlayerConnected(id))
        {
                new MyName[MAX_PLAYER_NAME+4], HisName[MAX_PLAYER_NAME+4];
                GetPlayerName(playerid, MyName, sizeof(MyName);
                GetPlayerName(id, HisName, sizeof(HisName);
        if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "invalid player");
        format(string,sizeof(string),"admin '%s' has banned '%s' ",MyName(playerid), HisName(id));
        SendClientMessageToAll(COLOR_RED,string);
        SetTimerEx("Banned",200,false,"d", id);
        return SendClientMessage(playerid,COLOR_RED,"You have been banned by Admin!");
        }
        else return  SendClientMessage(playerid, COLOR_RED, "The player is not in the server!");
    }
    else return SendClientMessage(playerid, COLOR_RED, "You need to be 3 level admin!");
}
This must work.
Reply
#4

I recommend you not to use that useless stock everyone uses for getting the player's name because in case you need to use the name 5 times in a command (an example), you're going to call GetPlayerName 5 times.. the worst method I've ever seen.

Get it once and use it!

pawn Код:
#define GetName(%0) User_Name[%0]

// global:
new
    User_Name[ MAX_PLAYERS ][ MAX_PLAYER_NAME ]
;

// OnPlayerConnect:
GetPlayerName( playerid, User_Name[ playerid ], MAX_PLAYER_NAME );
Reply
#5

Quote:
Originally Posted by iPrivate
Посмотреть сообщение
You have not defined the 'GetName'.

pawn Код:
CMD:ban(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] < 3)
    {
         new id;
         new string[128];
         if(sscanf(params, "us[50]", id))return SendClientMessage(playerid, -1, "usage: /ban [id] ");
         if(IsPlayerConnected(id))
        {
                new MyName[MAX_PLAYER_NAME+4], HisName[MAX_PLAYER_NAME+4];
                GetPlayerName(playerid, MyName, sizeof(MyName);
                GetPlayerName(id, HisName, sizeof(HisName);
        if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "invalid player");
        format(string,sizeof(string),"admin '%s' has banned '%s' ",MyName(playerid), HisName(id));
        SendClientMessageToAll(COLOR_RED,string);
        SetTimerEx("Banned",200,false,"d", id);
        return SendClientMessage(playerid,COLOR_RED,"You have been banned by Admin!");
        }
        else return  SendClientMessage(playerid, COLOR_RED, "The player is not in the server!");
    }
    else return SendClientMessage(playerid, COLOR_RED, "You need to be 3 level admin!");
}
This must work.
It don't work i have 6 errors:
Код:
C:\Users\Ivailo\Desktop\Iordan\Servers\ALFA GAME ROLEPLAY\gamemodes\AG-RP.pwn(447) : error 001: expected token: ",", but found ";"
C:\Users\Ivailo\Desktop\Iordan\Servers\ALFA GAME ROLEPLAY\gamemodes\AG-RP.pwn(448) : error 001: expected token: ",", but found ";"
C:\Users\Ivailo\Desktop\Iordan\Servers\ALFA GAME ROLEPLAY\gamemodes\AG-RP.pwn(450) : error 012: invalid function call, not a valid address
C:\Users\Ivailo\Desktop\Iordan\Servers\ALFA GAME ROLEPLAY\gamemodes\AG-RP.pwn(450) : warning 215: expression has no effect
C:\Users\Ivailo\Desktop\Iordan\Servers\ALFA GAME ROLEPLAY\gamemodes\AG-RP.pwn(450) : error 001: expected token: ";", but found ")"
C:\Users\Ivailo\Desktop\Iordan\Servers\ALFA GAME ROLEPLAY\gamemodes\AG-RP.pwn(450) : error 029: invalid expression, assumed zero
C:\Users\Ivailo\Desktop\Iordan\Servers\ALFA GAME ROLEPLAY\gamemodes\AG-RP.pwn(450) : fatal error 107: too many error messages on one line

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


6 Errors.
Reply
#6

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
I recommend you not to use that useless stock everyone uses for getting the player's name because in case you need to use the name 5 times in a command (an example), you're going to call GetPlayerName 5 times.. the worst method I've ever seen.

Get it once and use it!

pawn Код:
#define GetName(%0) User_Name[%0]

// global:
new
    User_Name[ MAX_PLAYERS ][ MAX_PLAYER_NAME ]
;

// OnPlayerConnect:
GetPlayerName( playerid, User_Name[ playerid ], MAX_PLAYER_NAME );
OT: I didn't know it's that bad. So thank you for the advice!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)