FCNPC - NPC coming near/going away problem - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: FCNPC - NPC coming near/going away problem (
/showthread.php?tid=660493)
FCNPC - NPC coming near/going away problem -
v1k1nG - 04.11.2018
Hello, I am trying to get more confident with NPCs because I am really amazed by how far FCNPC and FAI are getting to, so I have this to hopefully control my NPCs. Problem is, they don't come to my pos, but keep walking instead and when I get the closest to any of them they attack me once, then try to go away and right after to come back to me in a loop, without attacking anymore.
They are armed with a chainsaw.
PHP Code:
task ZombiesMovementUpdate[400](){ // Is 400 milliseconds good for such things?
new Float:ZCoords[3], Float:PCoords[3], Float:Dist;
foreach(new i : Player){
if(P[i][IsSpawned] == true){
for(new j = 0; j != MAX_ZOMBIES; j++){
if(!FCNPC_IsDead(j)){
FCNPC_GetPosition(j, ZCoords[0], ZCoords[1], ZCoords[2]);
Dist = GetDistanceBetweenPlayers(i,j);
if(IsPlayerInRangeOfPoint(i, 75, ZCoords[0], ZCoords[1], ZCoords[2]) && Zombie[j][IsFollowing] == false && Dist > 1.6){ // Go to player
if(FCNPC_IsPlayingNode(j)){
FCNPC_PausePlayingNode(j);
}
GetPlayerPos(i, PCoords[0], PCoords[1], PCoords[2]);
FCNPC_GoTo(j, PCoords[0], PCoords[1], PCoords[2], MOVE_TYPE_WALK, FCNPC_MOVE_SPEED_AUTO, true);
Zombie[j][IsFollowing] = true; // Only true here in all code
return 1;
}
if(IsPlayerInRangeOfPoint(i, 75, ZCoords[0], ZCoords[1], ZCoords[2]) && Zombie[j][IsFollowing] == true && Dist <= 1.6){ // Attack player
if(FCNPC_IsPlayingNode(j)){
FCNPC_PausePlayingNode(j);
}
FCNPC_MeleeAttack(j);
Zombie[j][IsFollowing] = false; // Setting this boolean to false here and whenever zombies spawn/respawn
return 1;
}
else if(FCNPC_IsPlayingNodePaused(j)){ // Do what zombie was doing before the encounter
FCNPC_ClearAnimations(j);
FCNPC_ResumePlayingNode(j);
}
}
}
}
}
return 1;
}
Re: FCNPC - NPC coming near/going away problem -
Pottus - 04.11.2018
What I would start with is to break down what you are trying to do into control systems.
1.) NPC controller include that has information contained in array/enum ie - update rate, position etc
2.) Create behavioral routines
3.) Sequence behavioral routines for specific NPC types
The problem here is you are trying to do too much with too little and it gets sloppy and unpredictable.
Re: FCNPC - NPC coming near/going away problem -
v1k1nG - 04.11.2018
I think I get your message...
Thanks!