HELP - instead of name shows 68
#1

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?
Reply
#2

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.
Reply
#3

"%d says: %s"

change %d to %s.

oops hy was faster ;d
Reply
#4

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?
Reply
#5

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.
Reply
#6

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

Edit: ^ faster.
Reply
#7

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.
Reply
#8

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.
Reply
#9

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;
}
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)