OnPlayerText - 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: OnPlayerText (
/showthread.php?tid=643671)
OnPlayerText -
MasterCodez - 25.10.2017
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
Re: OnPlayerText -
maksicnm - 25.10.2017
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;
}
Re: OnPlayerText -
MasterCodez - 25.10.2017
I mean when player say playerid in chat
Re: OnPlayerText -
kingmk - 25.10.2017
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".
Re: OnPlayerText -
MasterCodez - 25.10.2017
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
Re: OnPlayerText -
Danisoni - 25.10.2017
*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;
}