Hey guys,
So far, I made a script for enemies in my game (GG one was bugging and sometimes zombies just do nothing).
But in this script, it doesnt calc paths, just go straight to player. So, if a player run from a zombie for example, and quick hide behind a obstacle, zombie keep running look to the player position, and stuck in that obstacle.
What I need: When zombie stuck in obstacle (a command to check if enemie is stuck), then he do a small blink/jump ahead, maybe some animation of smoke appearing and a playsound.
My code is below:
g_new_ai_zombie_state = {}
function new_ai_zombie_init( e )
g_new_ai_zombie_state[ e ] = 0
CharacterControlLimbo( e )
SetAnimationFrames( 493, 494 )
PlayAnimation( e )
end
function new_ai_zombie_main( e )
local Ent = g_Entity[ e ]
local playerDist = GetPlayerDistance( e )
if playerDist < 500 and g_new_ai_zombie_state[ e ] == 0 then -- Starting Animation (Zombie rises)
SetAnimationFrames( 495, 522)
SetAnimationSpeed( e, 1 )
PlayAnimation( e )
g_new_ai_zombie_state[ e ] = 'rising'
PlaySound(e,0)
elseif
g_new_ai_zombie_state[ e ] == 'rising' and
GetAnimationFrame( e ) >= 520 then -- Preparing Second Animation (Run To Player)
g_new_ai_zombie_state[ e ] = 'runtoplayer'
elseif
g_new_ai_zombie_state[ e ] == 'attack' then -- Zombie Attack Player
CharacterControlLimbo( e )
SetAnimationSpeed( e, 2 )
SetAnimationFrames( 2981, 3034 )
LoopAnimation( e )
PlaySound(e,1)
g_new_ai_zombie_state[ e ] = 'attacking'
elseif
g_new_ai_zombie_state[ e ] == 'attacking' and playerDist >= 100 then -- If player get out of range, zombie chases again
g_new_ai_zombie_state[ e ] = 'runtoplayer'
elseif
GetAnimationFrame( e ) >= 3010 and GetAnimationFrame(e) <= 3034 and playerDist <= 100 then -- If player is in range while Zombie is at specific frame animation (Claws near), player got damaged
HurtPlayer( e, 2 )
end
if g_new_ai_zombie_state[ e ] == 'running' and playerDist < 100 then -- Preparing Attack
g_new_ai_zombie_state[ e ] = 'attack'
end
if g_new_ai_zombie_state[ e ] == 'runtoplayer' then -- Zombie runs to Player
SetAnimationFrames( 300, 318)
SetAnimationSpeed( e, 1 )
LoopAnimation( e )
g_new_ai_zombie_state [ e ] = 'running'
end
if g_new_ai_zombie_state [ e ] == 'running' then
RotateToPlayer(e)
MoveForward(e,200)
end