Hmm... Help? Name-Shortcuts
#1

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

um there are many ways, one could be by doing the following:

ex:


pawn Код:
stock GetName(playerid)
{
    new pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
    return pName;
}
//then
CMD:getname(playerid, params[])
{
    new string[64];
    format(string,64,"The name of ID: %d is %s", params[1], GetName(params[1]));
    return 1;
}
Reply
#3

Quote:
Originally Posted by kamzaf
Посмотреть сообщение
um there are many ways, one could be by doing the following:

ex:


pawn Код:
stock GetName(playerid)
{
    new pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
    return pName;
}
//then
CMD:getname(playerid, params[])
{
    new string[64];
    format(string,64,"The name of ID: %d is %s", params[1], GetName(params[1]));
    return 1;
}
I meant like, when aplayer is going to use a players name in the chat, like "Hey id0," and it would show as "Hey [name of id 0 here]"
Reply
#4

loop + valstr + strfind then strdel + strins + break; = Success
Reply
#5

Quote:
Originally Posted by Jefff
Посмотреть сообщение
loop + valstr + strfind then strdel + strins + break; = Success
That doesnt help... How to..?
Reply
#6

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

Thats not working, you can type id1 in game and it doesnt send the name or id1... It just sends a blank message
Reply
#8

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

Thanks bro, it works now... +repped
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)