ziggi / FCNPC

FCNPC - Fully Controllable NPC
Apache License 2.0
138 stars 31 forks source link

NPC not moving at player while player moving #132

Closed MichaelAceAnderson closed 6 years ago

MichaelAceAnderson commented 6 years ago

When I call FCNPC_GoToPlayer, the NPC runs but doesn't move until the player he goes to stops moving

ziggi commented 6 years ago

NPC movement will stops when the NPC has come to the player. It's exactly what the function should do. If you want to see how to implement FollowPlayer function, you should take a look at the bg.pwn filterscript.

MichaelAceAnderson commented 6 years ago

public FCNPC_OnUpdate(npcid)
{
    if(!FCNPC_IsValid(npcid)) return 0;

    new Float:AimX,Float:AimY,Float:AimZ,
    Float:FollowX,Float:FollowY,Float:FollowZ;

    if(IsPlayerConnected(NPCInfo[npcid][AimID])) GetPlayerPos(NPCInfo[npcid][AimID],AimX,AimY,AimZ);
    if(IsPlayerConnected(NPCInfo[npcid][FollowID])) GetPlayerPos(NPCInfo[npcid][FollowID],FollowX,FollowY,FollowZ);

    if(IsPlayerConnected(NPCInfo[npcid][AimID])) 
    {
        if(!FCNPC_IsAiming(npcid) && !FCNPC_IsMovingAtPlayer(npcid,NPCInfo[npcid][FollowID]) && GetPlayerDistanceFromPoint(npcid,AimX,AimY,AimZ) <= 20.0) FCNPC_AimAtPlayer(npcid,NPCInfo[npcid][AimID],true);
        else if(FCNPC_IsAiming(npcid) && FCNPC_IsMovingAtPlayer(npcid,NPCInfo[npcid][FollowID])) FCNPC_StopAim(npcid);
    }

    if(IsPlayerConnected(NPCInfo[npcid][FollowID])) 
    {
        if(!FCNPC_IsMoving(npcid) && GetPlayerDistanceFromPoint(npcid,FollowX,FollowY,FollowZ) > 10.0) FCNPC_GoToPlayer(npcid, NPCInfo[npcid][FollowID], FCNPC_MOVE_TYPE_SPRINT, FCNPC_MOVE_SPEED_SPRINT, true, .radius = 0.0, .setangle = true, .dist_offset = 0.0, .dist_check = 0.0, .stopdelay = -1);
        else if(!IsPlayerInAnyVehicle(NPCInfo[npcid][FollowID]) && FCNPC_IsMoving(npcid) && GetPlayerDistanceFromPoint(npcid,FollowX,FollowY,FollowZ) < 2.0) FCNPC_Stop(npcid);
    }
    return 1;
}

Here's my code, I don't really get why they have the animation without moving at the player when he moves

ziggi commented 6 years ago

Because you are using wrong .stopdelay, it should be 0 or more.

MichaelAceAnderson commented 6 years ago

No, the NPC doesn't stop after moving to the player, but before Should I upload a video ?

ziggi commented 6 years ago

Should I upload a video ?

Yes please.

MichaelAceAnderson commented 6 years ago

http://adrienspy.ml/perso/video/?video=FCNPC.mp4

ziggi commented 6 years ago

Try to debug this: add printf("something"); after the FCNPC_GoToPlayer and FCNPC_Stop calls.

MichaelAceAnderson commented 6 years ago

I changed my code to


public FCNPC_OnUpdate(npcid)
{
    if(!FCNPC_IsValid(npcid)) return 0;

    new Float:AimX,Float:AimY,Float:AimZ,
    Float:FollowX,Float:FollowY,Float:FollowZ;

    if(IsPlayerConnected(NPCInfo[npcid][AimID])) GetPlayerPos(NPCInfo[npcid][AimID],AimX,AimY,AimZ);
    if(IsPlayerConnected(NPCInfo[npcid][FollowID])) GetPlayerPos(NPCInfo[npcid][FollowID],FollowX,FollowY,FollowZ);

    if(IsPlayerConnected(NPCInfo[npcid][AimID])) 
    {
        if(!FCNPC_IsAiming(npcid) && !FCNPC_IsMovingAtPlayer(npcid,NPCInfo[npcid][FollowID]) && GetPlayerDistanceFromPoint(npcid,AimX,AimY,AimZ) <= 20.0) FCNPC_AimAtPlayer(npcid,NPCInfo[npcid][AimID],true);
        else if(FCNPC_IsAiming(npcid) && FCNPC_IsMovingAtPlayer(npcid,NPCInfo[npcid][FollowID])) FCNPC_StopAim(npcid);
    }

    if(IsPlayerConnected(NPCInfo[npcid][FollowID])) 
    {
        if(!FCNPC_IsMoving(npcid) && GetPlayerDistanceFromPoint(npcid,FollowX,FollowY,FollowZ) > 10.0)
        {
            FCNPC_GoToPlayer(npcid, NPCInfo[npcid][FollowID], FCNPC_MOVE_TYPE_SPRINT, FCNPC_MOVE_SPEED_SPRINT, true, .radius = 0.0, .setangle = true, .dist_offset = 0.0, .dist_check = 1.5, .stopdelay = 250);
            printf("FCNPC GoToPlayer Called");
        }
        else 
        {
            if(!IsPlayerInAnyVehicle(NPCInfo[npcid][FollowID]) && FCNPC_IsMoving(npcid) && GetPlayerDistanceFromPoint(npcid,FollowX,FollowY,FollowZ) < 2.0)
            {
                FCNPC_Stop(npcid);
                printf("FCNPC Stop Called");
            }
        }
    }
    return 1;
}

And it works..

ziggi commented 6 years ago

Solved.