Getting an NPCs ID.
#1

Well Started to go back to some NPCs today and was wondering how to get the ID of a NPC.

pawn Code:
public OnPlayerUpdate(playerid)
{
    new Float:x,Float:y,Float:z;
    GetPlayerPos(YOUR_NPC_ID,x,y,z);
    if(IsPlayerInRangeOfPoint(playerid,3.0,x,y,z))
    {
        SendClientMessage(playerid,0xFFFFFFFF,"NPC Says: hello, Im NPC, what can I do for you?");
    }
    return 1;
}
This was posted on one of my old topics on the same thing (3 or 4 months ago). I figured how to get it then just now I forgot. Any type help appreciated.
Reply
#2

R, I am not sure but what I am sure about is that
NCP's start from ID 0- up to how how you made.

Sorry if it didn't help ;'(
Reply
#3

No, that didn't help me. Anything else? :S
Reply
#4

The ID is returned by ConenctNPC, isnt it? Put it into a variable ad you ahve the npcs id.
YOu could also use GetPlayerName and strcmp to check, if it is the bot you need, but that wouldnt work for you your code.
Reply
#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
#6

Gonna try that Infamous, also can't I just do something like this?
pawn Code:
if(IsPlayerNPC(playerid))
{
        SetPlayerSkin(playerid,2);
}
SendClientMessage(playerid,green,"NPC Skin is 2");
?
Reply
#7

Well that would work I guess, but if you have more than one NPC then they will all be set to skinid 2.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)