Closed MichaelAceAnderson closed 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.
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
Because you are using wrong .stopdelay
, it should be 0 or more.
No, the NPC doesn't stop after moving to the player, but before Should I upload a video ?
Should I upload a video ?
Yes please.
Try to debug this: add printf("something");
after the FCNPC_GoToPlayer
and FCNPC_Stop
calls.
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..
Solved.
When I call FCNPC_GoToPlayer, the NPC runs but doesn't move until the player he goes to stops moving