SA-MP Forums Archive
[Help]/kick - 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]/kick (/showthread.php?tid=512922)



[Help]/kick - nilanjay - 13.05.2014

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;
}



Re: [Help]/kick - Aerotactics - 13.05.2014

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


Re: [Help]/kick - Konstantinos - 13.05.2014

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).


Re: [Help]/kick - nilanjay - 13.05.2014

Thanks for the help.

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


Re: [Help]/kick - Madd92 - 13.05.2014

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.


Re: [Help]/kick - Tingesport - 13.05.2014

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.