Help with player in range of NPC. -
Black Wolf - 24.08.2012
Hello,
I have a npc in my server and i am using this code.when player comes near npc and will say browse it will open the weap box.
Код:
if(IsPlayerInRangeOfPoint(playerid,2.0,2159.9353,2126.9072,10.8125))
{
if (strfind(text, "browse") != -1)
{
ShowPlayerDialog(playerid, CmdsMenu, DIALOG_STYLE_LIST, "Weapons:","1): UZI, nAK-47, Spray Paint\n2): Tec9, M4, Fire Extinguer\n3): Sniper Rifle, Knife, Silenced Pistol\n4): Deagle, MP5, Sawnoff Shotgun\n5): Parachute", "OK", "ESC");
}
return 1;
}
But that NPC is standing at a fixed position.
But now i maded a walking npc and i want it to detect npc loc and make a range i hope you are getting my point.
Npc will be walking and his range will be keep changing can someone make its code.when player comes near him he gets stopped at the point and when player will say browse (if player in range of npc) will open the dialog box.
Re: Help with player in range of NPC. -
Jstylezzz - 24.08.2012
I assume this is under OnPlayerText?
also, try
pawn Код:
if(!strcmp(text, "browse", true, strlen(text)))
instead of
pawn Код:
if (strfind(text, "browse") != -1)
not sure if this is the problem, but you can always try
my code, will only work if you only say "browse"
your code will check the whole sentence, but i'm not sure how you want it, so thought of posting it
Re: Help with player in range of NPC. -
Black Wolf - 25.08.2012
Bump!
Re: Help with player in range of NPC. -
Black Wolf - 25.08.2012
Bump.. Anyone please help
Re: Help with player in range of NPC. -
ikkentim - 25.08.2012
Getthe NPC's position using getplayerpos
Also read the rules! Do not bump this often!
Re: Help with player in range of NPC. -
Black Wolf - 25.08.2012
If i was knowing how to do that then i wasnt be here i mean i won't be posting this topic.Anyways thnx for the help.Topic is still waiting for codes..
Re: Help with player in range of NPC. -
Black Wolf - 26.08.2012
BUMP
Re: Help with player in range of NPC. -
SuperViper - 26.08.2012
pawn Код:
GetNPCID(npcName[MAX_PLAYER_NAME], bool: ignorecase = false)
{
new npcid = INVALID_PLAYER_ID, npcNameEx[MAX_PLAYER_NAME];
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerNPC(i))
{
GetPlayerName(i, npcNameEx, MAX_PLAYER_NAME);
if(!strcmp(npcName, npcNameEx, ignorecase))
{
npcid = i;
break;
}
}
}
return npcid;
}
new Float: npcPos[3];
GetPlayerPos(GetNPCID("YOUR NPC NAME", true), npcPos[0], npcPos[1], npcPos[2]);
if(IsPlayerInRangeOfPoint(playerid, 2.0, npcPos[0], npcPos[1], npcPos[2]))
{
if(strfind(text, "browse") > -1)
{
ShowPlayerDialog(playerid, CmdsMenu, DIALOG_STYLE_LIST, "Weapons:","1): UZI, nAK-47, Spray Paint\n2): Tec9, M4, Fire Extinguer\n3): Sniper Rifle, Knife, Silenced Pistol\n4): Deagle, MP5, Sawnoff Shotgun\n5): Parachute", "OK", "ESC");
}
return 1;
}
Make sure to replace
'YOUR NPC NAME'.