[Help]/kick
#1

I am getting these 3 errors:
pawn Код:
C:\Users\Nilanjay\Desktop\SERVER\gamemodes\16.pwn(301) : error 035: argument type mismatch (argument 1)
C:\Users\Nilanjay\Desktop\SERVER\gamemodes\16.pwn(303) : error 033: array must be indexed (variable "pID")
C:\Users\Nilanjay\Desktop\SERVER\gamemodes\16.pwn(306) : error 035: argument type mismatch (argument 1)
Code
pawn Код:
CMD:kick(playerid, params[])
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "[ERROR]:You need to an admin!");
    new pID[25];
    new reason[80];
    new string[128];
    new PlayerName[MAX_PLAYER_NAME], AdminName[MAX_PLAYER_NAME];
    GetPlayerName(pID, PlayerName, sizeof(PlayerName));//301
    GetPlayerName(playerid, AdminName, sizeof(AdminName));
    if(pID == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "[ERROR]:Invalid player id!");//303
    format(string, sizeof(string), "[SERVER]: %s has been kicked by %s. Reason: %s", PlayerName, AdminName, reason);
    SendClientMessageToAll(COLOR_RED, string);
    Kick(pID);//306
    return 1;
}
Reply
#2

pawn Код:
new pID[25];
The hell is pID? If you want to create a kick command with a param, may I suggest:
https://sampforum.blast.hk/showthread.php?tid=120356
Reply
#3

Use sscanf for getting the player's ID and you got those errors because you declared pID as array which should be an integer.
pawn Код:
CMD:kick(playerid, params[])
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "[ERROR]:You need to an admin!");
    new pID, reason[80];
    if (sscanf(params, "rs[80]", pID, reason)) return SendClientMessage(playerid, COLOR_RED, "Usage: /kick <ID/Part Of Name> <Reason>");
    if(pID == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "[ERROR]:Invalid player id!");
    new string[128], PlayerName[MAX_PLAYER_NAME], AdminName[MAX_PLAYER_NAME];
    GetPlayerName(pID, PlayerName, sizeof(PlayerName));
    GetPlayerName(playerid, AdminName, sizeof(AdminName));
    format(string, sizeof(string), "[SERVER]: %s has been kicked by %s. Reason: %s", PlayerName, AdminName, reason);
    SendClientMessageToAll(COLOR_RED, string);
    Kick(pID);
    return 1;
}
If you want the player who will be kicked to see the message, then use a timer (example can be found here (at the bottom of the page): https://sampwiki.blast.hk/wiki/Kick).
Reply
#4

Thanks for the help.

I got a question about sscanf? What is the use of sscanf apart from getting player's ID?
Reply
#5

Quote:
Originally Posted by nilanjay
Посмотреть сообщение
I am getting these 3 errors:
pawn Код:
C:\Users\Nilanjay\Desktop\SERVER\gamemodes\16.pwn(301) : error 035: argument type mismatch (argument 1)
C:\Users\Nilanjay\Desktop\SERVER\gamemodes\16.pwn(303) : error 033: array must be indexed (variable "pID")
C:\Users\Nilanjay\Desktop\SERVER\gamemodes\16.pwn(306) : error 035: argument type mismatch (argument 1)
Code
pawn Код:
CMD:kick(playerid, params[])
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "[ERROR]:You need to an admin!");
    new pID[25];
    new reason[80];
    new string[128];
    new PlayerName[MAX_PLAYER_NAME], AdminName[MAX_PLAYER_NAME];
    GetPlayerName(pID, PlayerName, sizeof(PlayerName));//301
    GetPlayerName(playerid, AdminName, sizeof(AdminName));
    if(pID == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "[ERROR]:Invalid player id!");//303
    format(string, sizeof(string), "[SERVER]: %s has been kicked by %s. Reason: %s", PlayerName, AdminName, reason);
    SendClientMessageToAll(COLOR_RED, string);
    Kick(pID);//306
    return 1;
}
1. pID should not be an array, 2. pID is never assigned any value here.

pawn Код:
CMD:kick(playerid, params[])
{
    if(!IsPlayerAdmin(playerid))
        return SendClientMessage(playerid, COLOR_RED, "[ERROR]: You need to be an admin!");
       
    new pID, reason[80];
    if (sscanf(params, "ds", pID, reason))
        return SendClientMessage(playerid, COLOR_RED, "Usage: /kick [ID] [reason]");
   
    new string[128], PlayerName[MAX_PLAYER_NAME], AdminName[MAX_PLAYER_NAME];
    if (!GetPlayerName(pID, PlayerName, sizeof(PlayerName)))
        return SendClientMessage(playerid, COLOR_RED, "[ERROR]: Invalid player ID!");
    GetPlayerName(playerid, AdminName, sizeof(AdminName));

    format(string, sizeof(string), "[SERVER]: %s has been kicked by %s. Reason: %s", PlayerName, AdminName, reason);
    SendClientMessageToAll(COLOR_RED, string);

    return Kick(pID);
}
And sscanf can always be used to retrieve a certain format of data from a string.

I hope this helps.
Reply
#6

Quote:
Originally Posted by Madd92
Посмотреть сообщение
1. pID should not be an array, 2. pID is never assigned any value here.

pawn Код:
CMD:kick(playerid, params[])
{
    if(!IsPlayerAdmin(playerid))
        return SendClientMessage(playerid, COLOR_RED, "[ERROR]: You need to be an admin!");
       
    new pID, reason[80];
    if (sscanf(params, "ds", pID, reason))
        return SendClientMessage(playerid, COLOR_RED, "Usage: /kick [ID] [reason]");
   
    new string[128], PlayerName[MAX_PLAYER_NAME], AdminName[MAX_PLAYER_NAME];
    if (!GetPlayerName(pID, PlayerName, sizeof(PlayerName)))
        return SendClientMessage(playerid, COLOR_RED, "[ERROR]: Invalid player ID!");
    GetPlayerName(playerid, AdminName, sizeof(AdminName));

    format(string, sizeof(string), "[SERVER]: %s has been kicked by %s. Reason: %s", PlayerName, AdminName, reason);
    SendClientMessageToAll(COLOR_RED, string);

    return Kick(pID);
}
And sscanf can always be used to retrieve a certain format of data from a string.

I hope this helps.
As he said.. new pID[25]; will be treated as a string. You don't need any array size for integers.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)