Getting an NPCs ID. - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Getting an NPCs ID. (
/showthread.php?tid=203044)
Getting an NPCs ID. -
willsuckformoney - 25.12.2010
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.
Re: Getting an NPCs ID. -
propilot - 25.12.2010
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 ;'(
Re: Getting an NPCs ID. -
willsuckformoney - 25.12.2010
No, that didn't help me. Anything else? :S
Re: Getting an NPCs ID. -
Mauzen - 25.12.2010
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.
Re: Getting an NPCs ID. -
Infamous - 25.12.2010
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;
}
Re: Getting an NPCs ID. -
willsuckformoney - 25.12.2010
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");
?
Re: Getting an NPCs ID. -
Infamous - 25.12.2010
Well that would work I guess, but if you have more than one NPC then they will all be set to skinid 2.