SA-MP Forums Archive
Hmm... Help? Name-Shortcuts - 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: Hmm... Help? Name-Shortcuts (/showthread.php?tid=458803)



Hmm... Help? Name-Shortcuts - cray1100 - 18.08.2013

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...


Re: Hmm... Help? Name-Shortcuts - kamzaf - 18.08.2013

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;
}



Re: Hmm... Help? Name-Shortcuts - cray1100 - 18.08.2013

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]"


Re: Hmm... Help? Name-Shortcuts - Jefff - 18.08.2013

loop + valstr + strfind then strdel + strins + break; = Success


Re: Hmm... Help? Name-Shortcuts - cray1100 - 18.08.2013

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


Re: Hmm... Help? Name-Shortcuts - Jefff - 18.08.2013

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


Re: Hmm... Help? Name-Shortcuts - cray1100 - 18.08.2013

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


Re: Hmm... Help? Name-Shortcuts - Jefff - 18.08.2013

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;
}



Re: Hmm... Help? Name-Shortcuts - cray1100 - 18.08.2013

Thanks bro, it works now... +repped