SetPlayerName only works once per user?
#1

Alright, Some I'm trying to make it so that when a person connects, it makes turns their name to GUEST[playerid], which works. Until they login on which I want it to change it back to normal.

OnPlayerConnect
Код:
// Setting the player's name into pInfo
GetPlayerName(playerid, pInfo[playerid][name],MAX_PLAYER_NAME);
	
// Setting a placeholder name until they register or login
new temporaryname[MAX_PLAYER_NAME];
format(temporaryname, MAX_PLAYER_NAME, "Guest[%d]", playerid);
SetPlayerName(playerid, temporaryname);
This works, but when it runs this code, it doesn't change the player's name back to normal

Код:
new namestring[MAX_PLAYER_NAME];
format(namestring, MAX_PLAYER_NAME, "%s", pInfo[playerid][name]);
SetPlayerName(playerid, namestring);

Whats wrong here or can the name only be changed once?
Reply
#2

I don't think you can make an enumeration like that.

pawn Код:
enum PlayerInfo
{
   name[24];
}

new pInfo[MAX_PLAYERS][PlayerInfo];
I assume you have something like that. I think that is invalid. You could store the player's name in a file in response to their id. I can help with that if that's what you want.
Reply
#3

Quote:
Originally Posted by backwardsman97
I don't think you can make an enumeration like that.

pawn Код:
enum PlayerInfo
{
  name[24];
}

new pInfo[MAX_PLAYERS][PlayerInfo];
I assume you have something like that. I think that is invalid. You could store the player's name in a file in response to their id. I can help with that if that's what you want.
No, actually it stores the name perfectly,

Код:
if(samp_mysql_num_rows() == 0)
{
format(str, 128, "{SERVER} The name '%s' is not registered, if you want to register it use /REGISTER <PASSWORD>", pInfo[playerid][name]);
} else {
format(str, 128, "{SERVER} The name '%s' is registered, if you want to login use /LOGIN <PASSWORD>", pInfo[playerid][name]);
samp_mysql_fetch_row(mysqlid);
pInfo[playerid][mysql]         	= strval(mysqlid);
}
Shows the name flawlessly


And my pInfo is set up like this

// Enumerating variables
enum PLAYER_DATA_ARRAY{
mysql,
name,
loggedin
}
new pInfo[MAX_PLAYERS][PLAYER_DATA_ARRAY];



ADDON:
Ran a blank gamemode with this change

Код:
public OnPlayerConnect(playerid)
{
	SetPlayerName(playerid, "Test1");
	SetPlayerName(playerid, "Test2");
	return 1;
}
The name was Test2, so something must be wrong with the script. Either that or a name can only be changed when it's OnPlayerConnect

Reply
#4

Instead of
pawn Код:
new namestring[MAX_PLAYER_NAME];
format(namestring, MAX_PLAYER_NAME, "%s", pInfo[playerid][name]);
SetPlayerName(playerid, namestring);
Try
pawn Код:
SetPlayerName(playerid,pInfo[playerid][name]);
Reply
#5

Quote:
Originally Posted by backwardsman97
Instead of
pawn Код:
new namestring[MAX_PLAYER_NAME];
format(namestring, MAX_PLAYER_NAME, "%s", pInfo[playerid][name]);
SetPlayerName(playerid, namestring);
Try
pawn Код:
SetPlayerName(playerid,pInfo[playerid][name]);
I tried that, it didn't work either, thats why I tried changing it around, maybe copying the name from the enumeration would work, but neither case worked.
Reply
#6

pawn Код:
enum PLAYER_DATA_ARRAY
{
    name
}

new pInfo[MAX_PLAYERS][PLAYER_DATA_ARRAY];


public OnPlayerCommandText(playerid,cmdtext[])
{
    if(!strcmp(cmdtext,"/test",true))
    {
      GetPlayerName(playerid,pInfo[playerid][name],24);
      SetPlayerName(playerid,"Bob");
      SetPlayerName(playerid,pInfo[playerid][name]);
      return 1;
    }
    return 0;
}
I went in game and did that and it worked fine. It changed my name to bob then back to backwards97.
Reply
#7

So then whats wrong with the script? It should work perfectly by that logic.
Reply
#8

Removed
Reply
#9

Quote:
Originally Posted by ♣ ⓐⓢⓢ
Removed
Anybody had any luck with this?
Reply
#10

Try printing the name variable a few times throughout the code and see if or when it changes.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)