Showing Incorrect playername
#1

Hello guys,

I created this command, to set faction rank.


It does it jobs, It gives the correct player the rank, But I make a new 2 new strings, 1st of send Faction rank 4+ Client message, and second one to log it in a file,

My problem is,

When i use the command, for example, /givefam 4 5

It gives playerid 4, the rank 5, which is good but in message it shows the playername of other player like ID 0 or ID 1 (which ever is earlier) Its not showing the playername of the other player id (target id), Its showing name of the player whose id is earlier, 0 or 1...

My Codes -

Код:
CMD:givefam(playerid, params[])
{
	if(PlayerInfo[playerid][pFacrank] >= 4 || IsPlayerAdmin(playerid))//checks if the player is high enough rank
	{
	    new targetid, rank, string[128];//establishes a player to use the command on, the rank you want to set, and some words to tell the players the actions used on them.
	    new banString[128], pgstaff[24], newpgmember[24], GiveFamstring[128];
        GetPlayerName(playerid, pgstaff, 24);
        GetPlayerName(targetid, newpgmember, 24);
	    if(sscanf(params, "ui", targetid, rank)) return SendClientMessage(playerid, COLOR_RED, "Usage: /givefam [playerid][rank]");//checks if the command was typed correctly
	    if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_RED, "That player is not connected!");//if the player id typed is not connected it will state that to you.
		if(rank < 1 || rank > 6) return SendClientMessage(playerid, COLOR_RED,"Rank must be 1 - 6");//checks if the rank number typed is above or below the correct numbers
		PlayerInfo[targetid][pFacrank] = rank;//sets the players rank to the rank you choose
	    SendClientMessage(targetid, COLOR_LIGHTBLUE, "Welcome to family!");//states that the players rank was changed
	    format(string, sizeof(string), "You have Received family Rank %d!", rank);
	    SendClientMessage(targetid, COLOR_GREEN, string);//states that the players rank was changed
	    format(banString, 128, "{663300}[ ACTION]{9999ff} %s has given  rank {33cc33}%d {9999ff}to %s .", pgstaff, rank, newpgmember);
		for(new i = 0; i < MAX_PLAYERS; i++)
		{
			if(PlayerInfo[i][pFacrank] >= 4)
				SendClientMessage(i, COLOR_WHITE, banString);         //goes through all the players checking who is and isint in faction 1
		}
	    format(GiveFamstring, 128, "[ ACTION] %s  has given  rank %d to %s .", pgstaff, rank, newpgmember);
	    GiveFamLog(GiveFamstring);
	    SendClientMessage(playerid, COLOR_LIGHTBLUE, " rights have been given to the player!");//states that the players rank was changed
	}
	else //if the player is not the correct rank it will display this message below
	{
	    SendClientMessage(playerid, COLOR_RED, "You re a retard! Permission denied!");
	}
    return 1;
}

CMD:takefam(playerid, params[])
{
	if(PlayerInfo[playerid][pFacrank] >= 4 || IsPlayerAdmin(playerid))//checks if the player is high enough rank
	{
	    new targetid, string[128];//establishes a player to use the command on, the rank you want to set, and some words to tell the players the actions used on them.
	    new banString[128], pgstaff[24], newpgmember[24], GiveFamstring[128];
        GetPlayerName(playerid, pgstaff, 24);
        GetPlayerName(targetid, newpgmember, 24);
	    if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_RED, "Usage: /takefam [playerid]");//checks if the command was typed correctly
	    if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_RED, "That player is not connected!");//if the player id typed is not connected it will state that to you.
		PlayerInfo[targetid][pFacrank] = 0;//sets the players rank to the rank you choose
	    SendClientMessage(targetid, COLOR_LIGHTBLUE, "HOLA!");//states that the players rank was changed
	    format(string, sizeof(string), "You have been kicked out of family!");
	    SendClientMessage(targetid, COLOR_GREEN, string);//states that the players rank was changed
	    SetPlayerHealth(targetid, 0);
	    format(banString, 128, "{663300}[ ACTION]{9999ff} %s has kicked {99ccff}%s {9999ff}out of family!", pgstaff, newpgmember);
		for(new i = 0; i < MAX_PLAYERS; i++)
		{
			if(PlayerInfo[i][pFacrank] >= 4) // >=4
				SendClientMessage(i, COLOR_WHITE, banString);         //goes through all the players checking who is and isint in faction 1
		}
	    format(GiveFamstring, 128, "[ ACTION] %s  has kicked %s out of  family!", pgstaff, newpgmember);
	    GiveFamLog(GiveFamstring);
	    SendClientMessage(playerid, COLOR_LIGHTBLUE, "rights have been taken from the player!");//states that the players rank was changed
	    WankRec[targetid] =0;
	}
	else //if the player is not the correct rank it will display this message below
	{
	    SendClientMessage(playerid, COLOR_RED, "You re a retard! Permission denied!");
	}
    return 1;
}
Reply
#2

You GetPlayerName before sscanf, "GetPlayerName(targetid, newpgmember, 24)" must be after getting targetid

PHP код:
if(sscanf(params"ui"targetidrank)) return SendClientMessage(playeridCOLOR_RED"Usage: /givefam [playerid][rank]");//checks if the command was typed correctly
GetPlayerName(targetidnewpgmember24); 
Reply
#3

This line:

PHP код:
GetPlayerName(targetidnewpgmember24); 
You have to set under the sscanf Code

Otherwise targetid is always 0
Reply
#4

Quote:
Originally Posted by Shinja
Посмотреть сообщение
You GetPlayerName before sscanf, "GetPlayerName(targetid, newpgmember, 24)" must be after getting targetid

PHP код:
if(sscanf(params"ui"targetidrank)) return SendClientMessage(playeridCOLOR_RED"Usage: /givefam [playerid][rank]");//checks if the command was typed correctly
GetPlayerName(targetidnewpgmember24); 
This should fix your issue.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)