[Include] Controllable NPC
#45

EDIT: I found a bug in your code:

pawn Code:
stock Npc: GetClosestNPC(playerid) // This function contributes to the above, as said, to chase a player :D
{
        new
        Float: fDistance,
        Float: fHighest,
        Npc: iPlayer = INVALID_CNPC
    ;
    foreachcnpc(npcid)
    {
        fDistance = GetDistanceBetweenPlayerAndNPC(playerid, npcid);
        if(fDistance > fHighest) fHighest = fDistance, iPlayer = Npc: npcid;
    }
    return iPlayer;
}
It was getting the highest distance, not the lowest lol, I lost a lot of time with my GM, I was trying to understand what made my bot not to work good. However that code will work if someone has only 1 CNPC.

The good code is:

pawn Code:
new Float: fDistance,
        Float: fLowest = 10000.0,
        Npc: iPlayer = INVALID_CNPC
    ;
    foreachcnpc(npcid)
    {
        fDistance = GetDistanceBetweenPlayerAndNPC(playerid, npcid);
        if(fDistance < fLowest) fLowest = fDistance, iPlayer = Npc: npcid;
    }
    return iPlayer;
And will work also with 10 npcs
Reply


Messages In This Thread
Controllable NPC - by Lorenc_ - 04.12.2011, 06:06
Respuesta: Controllable NPC - by [Nikk] - 04.12.2011, 06:14
Re: Controllable NPC - by [HiC]TheKiller - 04.12.2011, 06:17
Re: Controllable NPC - by Rudy_ - 04.12.2011, 06:19
Re: Controllable NPC - by System64 - 04.12.2011, 07:02
Re: Controllable NPC - by fiki574 - 04.12.2011, 07:32
Re: Controllable NPC - by Hiddos - 04.12.2011, 10:03
Re: Controllable NPC - by wups - 04.12.2011, 10:26
Re: Controllable NPC - by iPeanut - 04.12.2011, 10:54
Re: Controllable NPC - by erorcun - 04.12.2011, 11:26
Re: Controllable NPC - by Dirkon - 04.12.2011, 12:06
Re: Controllable NPC - by Lorenc_ - 04.12.2011, 19:52
Re: Controllable NPC - by TheArcher - 04.12.2011, 21:52
Re: Controllable NPC - by RyDeR` - 05.12.2011, 15:25
Re: Controllable NPC - by wups - 05.12.2011, 15:36
Re: Controllable NPC - by RyDeR` - 05.12.2011, 15:40
Re: Controllable NPC - by Lorenc_ - 05.12.2011, 20:13
Re: Controllable NPC - by usersamp - 16.01.2012, 19:37
Re: Controllable NPC - by usersamp - 16.01.2012, 21:40
Re: Controllable NPC - by Lorenc_ - 17.01.2012, 00:09
Re: Controllable NPC - by Brian_G - 17.01.2012, 00:13
Re: Controllable NPC - by Deskoft - 17.01.2012, 00:53
Re: Controllable NPC - by Scenario - 17.01.2012, 01:38
Re: Controllable NPC - by SoUrAv - 17.01.2012, 04:13
Re: Controllable NPC - by Lorenc_ - 17.01.2012, 06:10
Re: Controllable NPC - by usersamp - 17.01.2012, 06:37
Re: Controllable NPC - by usersamp - 17.01.2012, 07:06
Re: Controllable NPC - by Niko_boy - 17.01.2012, 08:33
Re: Controllable NPC - by Lorenc_ - 17.01.2012, 08:52
Re: Controllable NPC - by Lorenc_ - 02.04.2012, 13:12
Re: Controllable NPC - by clavador - 02.04.2012, 16:48
Re: Controllable NPC - by [T]HeLLBoY - 02.04.2012, 17:33
Re: Controllable NPC - by Snipa - 29.04.2012, 23:34
Respuesta: Controllable NPC - by [Vector] - 30.04.2012, 05:25
Re: Respuesta: Controllable NPC - by TheArcher - 30.04.2012, 09:42
Re: Controllable NPC - by Juninho_Oakley - 30.04.2012, 15:13
Re: Respuesta: Controllable NPC - by mprofitt - 30.04.2012, 20:15
Re: Respuesta: Controllable NPC - by TheArcher - 30.04.2012, 21:45
Re: Controllable NPC - by Lorenc_ - 30.04.2012, 22:05
Re: Controllable NPC - by Manowar - 09.07.2012, 18:35
Re: Controllable NPC - by TheArcher - 09.07.2012, 18:38
Re: Controllable NPC - by Scarface34 - 24.08.2012, 12:49
Re: Controllable NPC - by Lordzy - 08.12.2012, 08:17
Re: Controllable NPC - by Sasino97 - 08.12.2012, 17:36
Re: Controllable NPC - by Sasino97 - 10.12.2012, 12:42
Re: Controllable NPC - by burnfire - 03.05.2013, 11:27
Respuesta: Controllable NPC - by Swedky - 03.10.2013, 16:22
Re: Controllable NPC - by xF4Life - 06.10.2013, 15:26
Re: Controllable NPC - by iBeast - 06.10.2013, 15:35
Re: Controllable NPC - by Weponz - 02.06.2014, 04:17
Re: Controllable NPC - by Inn0cent - 02.06.2014, 06:08

Forum Jump:


Users browsing this thread: 9 Guest(s)