04.11.2018, 19:22
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.
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;
}