ID 0 Bug
#1

Whenever i kick someone, it shows ID 0's name.. here's the code: Hoping someone can fix it! :P

Код:
CMD:kick(playerid, params[])
    {
        if(PlayerInfo[playerid][pAdmin] > 0) {
            new PID; //define the playerid we wanna kick
            new reason[64]; //the reason, put into a string
            new str[128]; //a new message string
            new Playername[MAX_PLAYER_NAME], Adminname[MAX_PLAYER_NAME]; //defines the function with the playername we wanna get
            GetPlayerName(playerid, Adminname, sizeof(Adminname)); //defines the function with the adminname we wanna get
            GetPlayerName(PID, Playername, sizeof(Playername));
            if(sscanf(params, "us[64]", PID,reason)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /kick [playerid] [reason]"); //tell sscanf if the parameters/the syntax is written wrong to return a message (PID and the reason used here)

            if(!IsPlayerConnected(PID)) // if the ID is wrong or not connected, return a message! (PID used here)
                return SendClientMessage(playerid, COLOR_GREY, "That player is not connected.");

            format(str, sizeof(str), "%s has been kicked by administrator %s for reason: %s ", Playername, Adminname, reason); //format the string we've defined to send the message, playername and adminname are used to receive the information about the names
        	SendClientMessageToAll(COLOR_RED, str); //send that message to all
        	Kick(PID); //kick the playerid we've defined

        }
        else //if he has not got the permissions
        {
            SendClientMessage(playerid, COLOR_GREY, "You have to be level 1 to use that command."); //return this message
        }
        return 1;
    }
Reply
#2

Update your sscanf include and plugin. That should work.
Reply
#3

Get the name after the sscanf part.
Reply
#4

You didn't open or close that if(!IsPlayerConnected(PID)).

Get used to open and close those if with { and }.

To sum up what you wrote:
if player is not conected then show the message with his name on it. (Not actually possible to retrieve the name of someone who does not exist).

Fix:

Код:
CMD:kick(playerid, params[])
    {
        if(PlayerInfo[playerid][pAdmin] > 0) 
		{
            new PID; //define the playerid we wanna kick
            new reason[64]; //the reason, put into a string
            new str[128]; //a new message string
            new Playername[MAX_PLAYER_NAME], Adminname[MAX_PLAYER_NAME]; //defines the function with the playername we wanna get
            GetPlayerName(playerid, Adminname, sizeof(Adminname)); //defines the function with the adminname we wanna get
            GetPlayerName(PID, Playername, sizeof(Playername));
            if(sscanf(params, "us[64]", PID,reason))
			{
				return SendClientMessage(playerid, COLOR_GREY, "USAGE: /kick [playerid] [reason]"); //tell sscanf if the parameters/the syntax is written wrong to return a message (PID and the reason used here)
			}
			else
			{
	            if(!IsPlayerConnected(PID)) // if the ID is wrong or not connected, return a message! (PID used here)
				{
	                return SendClientMessage(playerid, COLOR_GREY, "That player is not connected.");
				}
				else
				{
					format(str, sizeof(str), "%s has been kicked by administrator %s for reason: %s ", Playername, Adminname, reason); //format the string we've defined to send the message, playername and adminname are used to receive the information about the names
					SendClientMessageToAll(COLOR_RED, str); //send that message to all
					Kick(PID); //kick the playerid we've defined
				}
			}
		}
        else //if he has not got the permissions
        {
            SendClientMessage(playerid, COLOR_GREY, "You have to be level 1 to use that command."); //return this message
        }
        return 1;
    }
This should be enough to fix that. I used Notepad++ to check that all brackets are opened and closed.

Greetings.
Reply
#5

use a stocked function like this

Cuz this returns the name of that id

pawn Код:
stock PlayerName(playerid)
{
     new name[24];
     GetPlayerName(playerid,name,sizeof(name));
     return name;
}
instead of "name" in that format of string put "PlayerName(player1)"

NOTE: if u want your players name who use this command put "PlayerName(playerid)" if u want to get a other players name to that player Do this "PlayerName(player1)" or the var u use for kick/ban
Reply
#6

it still does the same thing. It only shows the name when it's ID 0. It doesn't show any name when it's not ID 0
Reply
#7

Replace that
pawn Код:
new pID;
by
pawn Код:
new pID = strval(params);
cuz its a string value in the case of strval(params);
and string value can be anything less than 0 or more than 0 or 0 itself

And The case of getting playerid less than 0 you have already put a code that if the player is conncted as -1 , -2 are invalid / not connected players it will provide error
Reply
#8

C:\Users\Noah\Desktop\DM Server\gamemodes\NewDMNoah.pwn(889) : error 017: undefined symbol "PID"
C:\Users\Noah\Desktop\DM Server\gamemodes\NewDMNoah.pwn(890) : error 017: undefined symbol "PID"
C:\Users\Noah\Desktop\DM Server\gamemodes\NewDMNoah.pwn(896) : error 017: undefined symbol "PID"
C:\Users\Noah\Desktop\DM Server\gamemodes\NewDMNoah.pwn(904) : error 017: undefined symbol "PID"
C:\Users\Noah\Desktop\DM Server\gamemodes\NewDMNoah.pwn(884) : warning 204: symbol is assigned a value that is never used: "pID"
Reply
#9

pawn Код:
new PID = strval(params);
the Variables should Match
Reply
#10

I don't understand what you are saying lol.
Reply


Forum Jump:


Users browsing this thread: 7 Guest(s)