SA-MP Forums Archive
HELP - instead of name shows 68 - 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 - instead of name shows 68 (/showthread.php?tid=567619)



HELP - instead of name shows 68 - Denis1 - 15.03.2015

Here's my code:

Код:
stock GetPlayerNameEx(playerid) {
	new pName[MAX_PLAYER_NAME];
	GetPlayerName(playerid, pName, sizeof(pName));
	if(strfind(pName, "_", true)) {
		strreplace(pName, "_", " ");
	}
	return pName;
}



public OnPlayerText(playerid, text[]) {
	new string[128];
	format(string, sizeof(string), "%d says: %s", GetPlayerNameEx(playerid), text);
	SendClientMessage(playerid, L_RED_COLOR, string);
}
Whenever I go in-game, instead of my name which was "Denis_Test" at that time, it showed 68. Might I know what is the problem here?


Re: HELP - instead of name shows 68 - HY - 15.03.2015

pawn Код:
public OnPlayerText(playerid, text[]) {
    new string[128];
    format(string, sizeof(string), "%s says: %s", GetPlayerNameEx(playerid), text);
    SendClientMessage(playerid, L_RED_COLOR, string);
}
name it's a string, not an interger.


Re: HELP - instead of name shows 68 - DeitY - 15.03.2015

"%d says: %s"

change %d to %s.

oops hy was faster ;d


Re: HELP - instead of name shows 68 - Denis1 - 15.03.2015

Fixed! Did not use the proper placeholder. The result is fine, but is there another easier way of doing my code or have I chosen the correct path?


Re: HELP - instead of name shows 68 - HazardouS - 15.03.2015

I guess you could store the formatted name (without the underscore) in a variable when the player connects and just use that variable in your code instead of calling strfind and strreplace every time the player types something in chat.


Re: HELP - instead of name shows 68 - Vince - 15.03.2015

Save the name in a variable when they connect so you don't have to call the function all the time.

Edit: ^ faster.


Re: HELP - instead of name shows 68 - Denis1 - 15.03.2015

I've tried to follow your words but I received a few errors. Here's what I did:

I've created a variable (pName) into an enumerator (pInfo).
I added the following lines inside the OnPlayerConnect callback:

Код:
public OnPlayerConnect(playerid) {
	GetPlayerName(playerid, savedplayerdata[playerid][pName], sizeof(savedplayerdata[playerid][pName]));
	strreplace(savedplayerdata[playerid][pName], "_", " ");
	return savedplayerdata[playerid][pName];
}
and

Код:
public OnPlayerText(playerid, text[]) {
	new string[128];
	format(string, sizeof(string), "%s says: %s", savedplayerdata[playerid][pName], text);
	SendClientMessage(playerid, L_RED_COLOR, string);
}
I received the expected token ";' type of errors. can't quote as I'm not home at the moment.


Re: HELP - instead of name shows 68 - Denis1 - 15.03.2015

Sorry for double post - it actually is not possible because a public function cannot return a string. I think I'll simply stick to my code until I find a solution.


Respuesta: HELP - instead of name shows 68 - admantis - 15.03.2015

You don't need to return anything else than 1 in this case. Simply, do this:
pawn Код:
public OnPlayerConnect(playerid) {
    GetPlayerName(playerid, savedplayerdata[playerid][pName], sizeof(savedplayerdata[playerid][pName]));
    strreplace(savedplayerdata[playerid][pName], "_", " "); // be careful here! if you save the name, for example using this variable, you will have problems.
    return 1;
}