OnPlayerText
#1

How i can replace word into playername like this example below

ID 0: PlayerName1
ID 1: PlayerName2

PlayerName2: Welcome id 0 to server >> replace to >> Welcome PlayerName1 to server
Reply
#2

new string[256];
format(string, sizeof(string), "Welcome %s to server!", GetName(playerid));
SendClientMessage(playerid, -1, string);

So, here is the stock GetName:
stock GetName(playerid)
Код HTML:
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    return name;
}
Reply
#3

I mean when player say playerid in chat
Reply
#4

Quote:
Originally Posted by MasterCodez
Посмотреть сообщение
How i can replace word into playername like this example below

ID 0: PlayerName1
ID 1: PlayerName2

PlayerName2: Welcome id 0 to server >> replace to >> Welcome PlayerName1 to server
Try this. This function will replace the ID X in name of player and the message will be send to all players.

Код:
forward ReplaceIDWithName(playerid, text[]);
public ReplaceIDWithName(playerid, text[])
{
       new string[10];
       foreach(new i : Player) //If u use YSI or foreach(Player, i) if not.
       {
              format(string, sizeof(string), "ID %d", playerid);
              if(strfind(text, string, true) != -1)
              {
                     new PlayerName[MAX_PLAYER_NAME];
                     GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
                     strreplace(text, string, PlayerName);
                     SendClientMessageToAll(playerid, text);
                     return 1;
              }
       }
       return 1;
}
How to use?

Код:
OnPlayerText(playerid, text[])
{
       ReplaceIDWithName(playerid, text);
       return 1;
}
Also for strreplace u can use https://sampforum.blast.hk/showthread.php?tid=362764 posted by Slice


If u will type in chat "Welcome ID 10 to server", this will convert text to "Welcome PlayerNameID10 to server".
Reply
#5

Quote:
Originally Posted by kingmk
Посмотреть сообщение
If u will type in chat "Welcome ID 10 to server", this will convert text to "Welcome PlayerNameID10 to server".
Yeah, I mean this. But code not working
Reply
#6

*edit:

Try this:

Код:
stock PlayerName(playerid)
{
    new pname[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pname, sizeof(pname));
    return pname;
}
Код:
public OnPlayerText(playerid, text[])
{
     new str1[64];
     foreach( Player , i ) {
		format(str1, sizeof(str1), "Welcome ID %d to server.", i);
	    if(strfind(str1,text,true) != -1) {
	        format(str1, sizeof(str1), "Welcome %s to server.", PlayerName( i ));
	        SendClientMessage( i, -1, str1 );
	        return 0;
	    }
     }
     return 0;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)