PDA

View Full Version : Help with player in range of NPC.


Black Wolf
24/08/2012, 04:44 PM
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,2 126.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.

Jstylezzz
24/08/2012, 04:52 PM
I assume this is under OnPlayerText?

also, try
if(!strcmp(text, "browse", true, strlen(text))) instead of 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

Black Wolf
25/08/2012, 03:43 AM
Bump!

Black Wolf
25/08/2012, 11:16 AM
Bump.. Anyone please help

ikkentim
25/08/2012, 11:25 AM
Getthe NPC's position using getplayerpos


Also read the rules! Do not bump this often!

Black Wolf
25/08/2012, 11:27 AM
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..

Black Wolf
26/08/2012, 02:42 AM
BUMP

SuperViper
26/08/2012, 04:12 AM
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'.