Command Problem.
#1

The code display everything correct but the name is always wrong and set the name to Player ID 0.

Код:
new adminLevel;
new PID;
new name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME];
GetPlayerName(PID, name, sizeof(name));
Код:
format(string, sizeof(string), "[ADMIN]: You have set %s's admin level to %d.", name, adminLevel);
Reply
#2

Get the PID name after sscanf to be sure the PID have a valid id in it
Reply
#3

Isn't that what I have?

Код:
        new adminLevel;
	new PID;
	new name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME];
    	GetPlayerName(PID, name, sizeof(name));

	if(sscanf(params, "ud", PID, adminLevel)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setadmin [playerid] [admin-level]");
	if(!IsPlayerConnected(PID)) return SendClientMessage(playerid, COLOR_WHITE, "Player is not connected");
	PlayerInfo[PID][pAdmin] = adminLevel;

	format(string, sizeof(string), "[ADMIN]: You have set %s's admin level to %d.", name, adminLevel);
	SendClientMessage(playerid, COLOR_SERVER, string);
Reply
#4

um, try this.

Код HTML:
	new
	    PID,
	    adminlevel
	;
	
	if(sscanf(params, "ud", PID, adminlevel)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setadmin [playerid] [admin-level]");
	
	if(!IsPlayerConnected(PID)) return SendClientMessage(playerid, COLOR_WHITE, "Player is not connected");
	
	PlayerInfo[PID][pAdmin] = adminlevel;
	
	new
		name[MAX_PLAYER_NAME],
		string[24 + MAX_PLAYER_NAME]
	;
	
	GetPlayerName(PID, name, MAX_PLAYER_NAME);
	
	format(string, sizeof(string), "[ADMIN]: You have set %s's admin level to %d.", name, adminlevel);
	SendClientMessage(playerid, COLOR_SERVER, string);
Reply
#5

Add this method anywhere in your script:

PHP код:
stock GetName(playerid)
{
    new 
name[64];
    
GetPlayerName(playeridnamesizeof(name));
    return 
name;

and then you can use it anywhere you need to retrieve user's name just like:

PHP код:
format(stringsizeof(string), "[ADMIN]: You have set %s's admin level to %d."GetName(playerid), adminLevel); 
Reply
#6

Quote:
Originally Posted by MyUndiesSmell
Посмотреть сообщение
Isn't that what I have?

Код:
        new adminLevel;
	new PID;
	new name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME];
    	GetPlayerName(PID, name, sizeof(name));

	if(sscanf(params, "ud", PID, adminLevel)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setadmin [playerid] [admin-level]");
	if(!IsPlayerConnected(PID)) return SendClientMessage(playerid, COLOR_WHITE, "Player is not connected");
	PlayerInfo[PID][pAdmin] = adminLevel;

	format(string, sizeof(string), "[ADMIN]: You have set %s's admin level to %d.", name, adminLevel);
	SendClientMessage(playerid, COLOR_SERVER, string);
You get the name after you make the PID variabile that will be always 0 because the code it's executed line after line, so when GetPlayerName(PID, name, sizeof(name)); it's got executed PID is 0 and always 0 in that moment...
You need to put
PHP код:
GetPlayerName(PIDnamesizeof(name)); 
after
PHP код:
if(sscanf(params"ud"PIDadminLevel)) return SendClientMessage(playeridCOLOR_WHITE"USAGE: /setadmin [playerid] [admin-level]");
if(!
IsPlayerConnected(PID)) return SendClientMessage(playeridCOLOR_WHITE"Player is not connected"); 
where the PID get a new value that you specified....
So your code need to look like this:
PHP код:
new adminLevel;
    new 
PID;
    new 
name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME];
    if(
sscanf(params"ud"PIDadminLevel)) return SendClientMessage(playeridCOLOR_WHITE"USAGE: /setadmin [playerid] [admin-level]");
    if(!
IsPlayerConnected(PID)) return SendClientMessage(playeridCOLOR_WHITE"Player is not connected");
       
GetPlayerName(PIDnamesizeof(name));//Here PID is specified and is valid (it's get the value that you enter for [playerid])
    
PlayerInfo[PID][pAdmin] = adminLevel;
    
format(stringsizeof(string), "[ADMIN]: You have set %s's admin level to %d."nameadminLevel);
    
SendClientMessage(playeridCOLOR_SERVERstring); 
I hope that i explained well, it's hard you are not a native english speaker and it's your second language
Or try a code above,they are all corect
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)