Posts: 156
Threads: 25
Joined: Jun 2013
Reputation:
0
Well, while in-game at my server, i noticed that taking the time to type a players whole name can have issues... So, how can i make a code so that players can type for ex. "id1" and it would show the player with id 1's name, instead of typing the wholke thing, it is probably something simple that i missed, but i have tried it myself...
Posts: 2,593
Threads: 34
Joined: Dec 2007
loop + valstr + strfind then strdel + strins + break; = Success
Posts: 2,593
Threads: 34
Joined: Dec 2007
pawn Код:
public OnPlayerText(playerid,text[])
{
for(new i,g = GetMaxPlayers(); i != g; i++)
{
if(IsPlayerConnected(i) && i != playerid)
{
new str[7],pos;
format(str,sizeof(str),"ID%d",i);
if((pos = strfind(text,str,true)) != -1)
{
new Nick[MAX_PLAYER_NAME + 1];
GetPlayerName(i,Nick,MAX_PLAYER_NAME);
strdel(text,pos,pos+strlen(str));
strins(text,Nick,pos,128);
break;
}
}
}
return 1;
}
If you are using foreach inc replace that loop
Posts: 156
Threads: 25
Joined: Jun 2013
Reputation:
0
Thats not working, you can type id1 in game and it doesnt send the name or id1... It just sends a blank message
Posts: 2,593
Threads: 34
Joined: Dec 2007
pawn Код:
public OnPlayerText(playerid,text[])
{
for(new i,g = GetMaxPlayers(); i != g; i++)
{
if(IsPlayerConnected(i) && i != playerid)
{
new str[7],pos;
format(str,sizeof(str),"ID%d",i);
if((pos = strfind(text,str,true)) != -1)
{
new strr[128];
new Nick[MAX_PLAYER_NAME + 1];
strcat(strr,text);
GetPlayerName(i,Nick,MAX_PLAYER_NAME);
strdel(strr,pos,pos+strlen(str));
strins(strr,Nick,pos);
SendPlayerMessageToAll(playerid,strr);
return 0;
}
}
}
return 1;
}
Posts: 156
Threads: 25
Joined: Jun 2013
Reputation:
0
Thanks bro, it works now... +repped