Getting an NPCs ID.
#5

This is not made by me but I find it very useful.

Code:
new NPCID = GetPlayerIDFromName("Dave");
Code:
stock GetPlayerIDFromName(const playername[], partofname=0)
{
    new i;
    new playername1[64];
    for (i=0;i<MAX_PLAYERS;i++)
    {
        if (IsPlayerConnected(i))
        {
            GetPlayerName(i,playername1,sizeof(playername1));
            if (strcmp(playername1,playername,true)==0)
            {
                return i;
            }
        }
    }
    new correctsigns_userid=-1;
    new tmpuname[128];
    new hasmultiple=-1;
    if(partofname)
    {
        for (i=0;i<MAX_PLAYERS;i++)
        {
            if (IsPlayerConnected(i))
            {
                GetPlayerName(i,tmpuname,sizeof(tmpuname));

                if(!strfind(tmpuname,playername1[partofname],true, 0))
                {
                    hasmultiple++;
                    correctsigns_userid=i;
                }
                if (hasmultiple>0)
                {
                    return -2;
                }
            }
        }
    }
    return correctsigns_userid;
}
Reply


Messages In This Thread
Getting an NPCs ID. - by willsuckformoney - 25.12.2010, 22:22
Re: Getting an NPCs ID. - by propilot - 25.12.2010, 22:27
Re: Getting an NPCs ID. - by willsuckformoney - 25.12.2010, 22:44
Re: Getting an NPCs ID. - by Mauzen - 25.12.2010, 22:54
Re: Getting an NPCs ID. - by Infamous - 25.12.2010, 22:55
Re: Getting an NPCs ID. - by willsuckformoney - 25.12.2010, 23:02
Re: Getting an NPCs ID. - by Infamous - 25.12.2010, 23:05

Forum Jump:


Users browsing this thread: 2 Guest(s)