Posts: 72
Threads: 11
Joined: Apr 2008
Reputation:
0
Hi all i have question about how to replace string.
when i type "Hello @1 How are you" i want to replace @1 to name of playerid1
Thanks
ps. sorry if my english is bad
Posts: 2,593
Threads: 34
Joined: Dec 2007
pawn Код:
str_replace(const text[])
{
new str[145];
strcat(str,text);
new pos = strfind(str,"@",true);
if(pos != -1)
{
new ids[5];
while((pos = strfind(str,"@",true,pos)) != -1)
{
new playerid;
if(!sscanf(str[pos+1],"i",playerid))
if(0 <= playerid < MAX_PLAYERS && IsPlayerConnected(playerid))
{
new name[MAX_PLAYER_NAME + 1];
GetPlayerName(playerid,name,sizeof(name));
valstr(ids,playerid);
strdel(str,pos,pos+strlen(ids)+1);
strins(str,name,pos);
pos += 3;
}
pos += 1;
}
}
return str;
}
CMD:test(playerid, params[])
{
if(!isnull(params))
SendClientMessageToAll(-1,str_replace(params));
return 1;
}
Posts: 2,593
Threads: 34
Joined: Dec 2007
because its wrong usage? you wanted "Hello @1 How" its better than "HellobasicllswHow"