-- LUA Script - precede every function and global member with lowercase name of script ai_zombiework_myframe = 199 ai_zombiework_pressed = 0 ai_zombiework_mode = 1 function ai_zombiework_init(e) --ai_soldier_state[e] = "idle" CharacterControlLimbo(e) StopAnimation(e) Hide(e) end function ai_zombiework_main(e) RotateToPlayer(e) if ai_zombiework_mode==0 then Show(e) -- we can browse the entity animaiton framres if g_Scancode==0 then ai_zombiework_pressed=0 end if ai_zombiework_pressed==0 then if ai_zombiework_myframe > 0 and (g_Scancode==12 or g_Scancode==28) then ai_zombiework_myframe=ai_zombiework_myframe-1 end if g_Scancode==13 or g_Scancode==14 then ai_zombiework_myframe=ai_zombiework_myframe+1 end if g_Scancode==12 or g_Scancode==13 then ai_zombiework_pressed = 1 end end SetAnimationFrame(e,ai_zombiework_myframe) end if ai_zombiework_mode==1 then -- waiting mode PlayerDist = GetPlayerDistance(e) if PlayerDist < 100 then SetAnimationFrames(191,208) PlayAnimation(e) ai_zombiework_mode = 2 Show(e) StartTimer(e) end else if ai_zombiework_mode==2 then -- playing the spawn bit if GetTimer(e) > 500 then CharacterControlUnarmed(e) ai_zombiework_mode = 3 end end end if ai_zombiework_mode==3 then -- attack mode EntObjNo = g_Entity[e]['obj'] AIEntityGoToPosition(EntObjNo,g_PlayerPosX,g_PlayerPosZ) PlayerDist = GetPlayerDistance(e) Prompt ( "PlayerDist=" .. PlayerDist ) if PlayerDist < 50 then ai_zombiework_mode = 4 FreezePlayer() CharacterControlLimbo(e) StopAnimation(e) SetAnimationFrames(196,206) LoopAnimation(e) end end if ai_zombiework_mode==4 then -- zombie eats brain! newx = math.cos(g_PlayerAngY) * -50 newz = math.sin(g_PlayerAngY) * -50 SendMessageF("resetpositionx",e,g_PlayerPosX+newx) SendMessageF("resetpositionz",e,g_PlayerPosZ+newz) --Prompt ( "newx=" .. newx .. " newz=" .. newz .. " g_PlayerPosX=" .. g_PlayerPosX ) end --SetAnimationSpeed(e,0.01) --? Prompt ( "Scancode=" .. g_Scancode .. " Frame=" .. ai_zombiework_myframe .. " Timer" .. GetTimer(e) .. " Mode=" .. ai_zombiework_mode ) end -- old zombie code attackstart = {} attackend = {} damageframestart = {} damageframeend = {} lastroar = {} lastswipe = {} function ai_zombiework_init_old(e) ai_soldier_state[e] = "idle" CharacterControlLimbo(e) SetAnimationFrames(210,234) LoopAnimation(e) ModulateSpeed(e,1.0) SetAnimationSpeed(e,1.0) attackstart[e]=2561 attackend[e]=2600 damageframestart[e]=2570 damageframeend[e]=2590 lastroar[e]=0 lastswipe[e]=0 end function ai_zombiework_main_old(e) PlayerDist = GetPlayerDistance(e) EntObjNo = g_Entity[e]['obj'] if (PlayerDist < 600 and ai_soldier_state[e] == "idle" and g_Entity[e]['plrvisible'] == 1) or (AIGetEntityHeardSound(EntObjNo) == 1 and ai_soldier_state[e] == "idle") or (PlayerDist < 100 and ai_soldier_state[e] == "idle") then RotateToPlayer(e) if GetTimer(e) > lastroar[e] then lastroar[e]= GetTimer(e)+6000 PlaySound(e,0) end end if PlayerDist < 600 and g_Entity[e]['plrvisible']==1 then RotateToPlayer(e) if PlayerDist < 80 and g_Entity[e]['plrvisible']==1 then if ai_soldier_state[e]~="attack" then SetAnimationSpeed(e,1.75) if GetAnimationFrame(e)attackend[e] then AIEntityStop(EntObjNo) ai_soldier_state[e] = "attack" CharacterControlLimbo(e) randomattack=math.random(1,3) if randomattack==1 then attackstart[e]=2561 attackend[e]=2600 damageframestart[e]=2580 damageframeend[e]=2595 end if randomattack==2 then attackstart[e]=2869 attackend[e]=2907 damageframestart[e]=2885 damageframeend[e]=2890 end if randomattack==3 then attackstart[e]=2910 attackend[e]=3023 damageframestart[e]=2950 damageframeend[e]=3010 end SetAnimationFrames(attackstart[e],attackend[e]) PlayAnimation(e) end end if ai_soldier_state[e]=="attack" then SetAnimationSpeed(e,2) if GetAnimationFrame(e)>damageframestart[e] and GetAnimationFrame(e) lastswipe[e] then lastswipe[e]= GetTimer(e)+1600 PlaySound(e,1) end randomdamage=math.random(3,7) HurtPlayer(e,randomdamage) end end if GetAnimationFrame(e)>attackend[e]-1 then CharacterControlUnarmed(e) ai_soldier_state[e] = "roam" randomroam=math.random(1,2) if randomroam == 1 then SetAnimationFrames(2530,2559) end if randomroam == 2 then SetAnimationFrames(2499,2528) end if GetPlayerDistance(e)<80 then ai_soldier_state[e] = "idle" CharacterControlLimbo(e) SetAnimationFrames(1,1) RotateToPlayer(e) end PlayAnimation(e) end end else if ai_soldier_state[e]~="roam" then ai_soldier_state[e] = "roam" CharacterControlUnarmed(e) ModulateSpeed(e,1.0) SetAnimationSpeed(e,1.0) SetCharacterToWalk(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 PlayerDist >= 600 and ai_soldier_state[e] ~= "idle" then ai_soldier_state[e] = "idle" CharacterControlLimbo(e) SetAnimationFrames(210,234) LoopAnimation(e) ModulateSpeed(e,1.0) SetAnimationSpeed(e,1.0) end end --Prompt("ZOMBIEWALK3 : Dist=" .. PlayerDist .. " State=" .. ai_soldier_state[e] .. " Vis=" .. g_Entity[e]['plrvisible'] .. " Frm=" .. GetAnimationFrame(e) ) end function ai_zombiework_exit(e) PlayCharacterSound(e,"onDeath") CollisionOff(e) end