-- LUA Script -- local attackstart = 150 local attackend = 189 local damageframestart = 160 local damageframeend = 189 local lastroar = 0 local lastswipe = 0 local roar_start = 642 local roar_end = 680 local mainroar = 0 function ai_fastmurkscreamer_init(e) ai_soldier_pathindex[e] = -1; ai_soldier_state[e] = "idle"; CharacterControlLimbo(e) SetAnimationFrames(1,37) LoopAnimation(e) end function ai_fastmurkscreamer_main(e) SetSoundVolume(100) SetEntityHealth(e,100) PlayerDist = GetPlayerDistance(e) EntObjNo = g_Entity[e]['obj'] if ai_soldier_state[e] == "idle" then if ai_soldier_pathindex[e] == -1 then ai_soldier_pathindex[e] = -2 PathIndex = -1 PathPointIndex = -1 pClosest = 99999 for pa = 1, AIGetTotalPaths(), 1 do for po = 1 , AIGetPathCountPoints(pa), 1 do pDX = g_Entity[e]['x'] - AIPathGetPointX(pa,po) pDZ = g_Entity[e]['z'] - AIPathGetPointZ(pa,po) pDist = math.sqrt(math.abs(pDX*pDX)+math.abs(pDZ*pDZ)) if pDist < pClosest and pDist < 200 then pClosest = pDist PathIndex = pa PathPointIndex = po end end -- po end -- pa if PathIndex > -1 then ai_soldier_pathindex[e] = PathIndex ai_path_point_index[e] = PathPointIndex CharacterControlArmed(e) SetCharacterToWalk(e) ModulateSpeed(e,1.0) SetAnimationSpeed(e,1.5) ai_path_point_direction[e] = 1 ai_path_point_max[e] = AIGetPathCountPoints(ai_soldier_pathindex[e]) end end if ai_soldier_pathindex[e] > -1 then ai_patrol_x[e] = AIPathGetPointX(ai_soldier_pathindex[e],ai_path_point_index[e]) ai_patrol_z[e] = AIPathGetPointZ(ai_soldier_pathindex[e],ai_path_point_index[e]) AIEntityGoToPosition(EntObjNo,ai_patrol_x[e],ai_patrol_z[e]) tDistX = g_Entity[e]['x'] - ai_patrol_x[e] tDistZ = g_Entity[e]['z'] - ai_patrol_z[e] DistFromPath = math.sqrt(math.abs(tDistX*tDistX)+math.abs(tDistZ*tDistZ)) if DistFromPath < 50 then if ai_path_point_direction[e] == 1 then ai_path_point_index[e] = ai_path_point_index[e] + 1 if ( ai_path_point_index[e] > ai_path_point_max[e] ) then ai_path_point_index[e] = ai_path_point_max[e] - 1 ai_path_point_direction[e] = 0 end else ai_path_point_index[e] = ai_path_point_index[e] - 1 if ( ai_path_point_index[e] < 1 ) then ai_path_point_index[e] = 2 ai_path_point_direction[e] = 1 end end end end end if (PlayerDist < 1000 and ai_soldier_state[e] == "idle" and g_Entity[e]['plrvisible'] == 1) or (PlayerDist < 100 and ai_soldier_state[e] == "idle") then RotateToPlayer(e) if GetTimer(e) > lastroar then if lastroar==0 then -- roar when we see player for first time chooseidle=math.random(1,2) if chooseidle == 1 then SetAnimationFrames(roar_start,roar_end) end if chooseidle == 2 then SetAnimationFrames(roar_start,roar_end) end PlayAnimation(e) ModulateSpeed(e,0.8) SetAnimationSpeed(e,0.8) PlaySound(e,0) ai_soldier_state[e] = "roar" end end end if ai_soldier_state[e]=="roar" then -- handle roar sequence and scream sound if (GetAnimationFrame(e)=roar_start) or (GetAnimationFrame(e)>=roar_end) then ai_soldier_state[e] = "idle" end if lastroar==0 and ((GetAnimationFrame(e)=roar_start) or (GetAnimationFrame(e)>=roar_end)) then lastroar=GetTimer(e)+4000 mainroar = 1 end else if PlayerDist < 1000 then -- while visible in range RotateToPlayer(e) if PlayerDist < 125 then -- attack if close enough if ai_soldier_state[e]~="attack" then if GetAnimationFrame(e)attackend then AIEntityStop(EntObjNo) ai_soldier_state[e] = "attack" CharacterControlLimbo(e) randomattack=math.random(1,2) if randomattack == 1 then attackstart=150 attackend=189 damageframestart=160 damageframeend=189 end if randomattack == 2 then attackstart=190 attackend=279 damageframestart=200 damageframeend=279 end SetAnimationFrames(attackstart,attackend) PlayAnimation(e) SetAnimationSpeed(e,1.2) end end if ai_soldier_state[e]=="attack" then if GetAnimationFrame(e)>damageframestart and GetAnimationFrame(e) lastswipe then lastswipe= GetTimer(e)+1000 PlaySound(e,1) randomdamage=math.random(20,40) HurtPlayer(e,randomdamage) end end end if GetAnimationFrame(e)>attackend-2 then if PlayerDist < 125 then -- quickly attack again ai_soldier_state[e] = "attackagain" SetAnimationFrames(attackstart-1,attackstart-1) PlayAnimation(e) end end end else -- not close enough, so roam moves to player if ai_soldier_state[e]~="roam" and mainroar == 1 then ai_soldier_state[e] = "roam" CharacterControlUnarmed(e) ModulateSpeed(e,1.5) SetAnimationSpeed(e,1.2) SetCharacterToRun(e) end rndx=math.random(1,360) rndz=math.random(1,360) rndx2=math.sin(rndx)*30 rndz2=math.cos(rndz)*30 AIEntityGoToPosition(EntObjNo,g_PlayerPosX+rndx2,g_PlayerPosZ+rndz2) end else -- if not in attack range, revert to idle if PlayerDist >= 1000 and ai_soldier_state[e] ~= "idle" then ai_soldier_state[e] = "idle" CharacterControlLimbo(e) SetAnimationFrames(1,37) LoopAnimation(e) ModulateSpeed(e,1.0) SetAnimationSpeed(e,1.0) end end end end function ai_fastmurkscreamer_exit(e) SetCharacterSound(e,"Murkscreamer") PlayCharacterSound(e,"onDeath") ai_soldier_state[e] = "dead" ModulateSpeed(e,1.0) CharacterControlLimbo(e) SetAnimationSpeed(e,1.0) SetAnimationFrames(476,544) PlayAnimation(e) CollisionOff(e) end