-- LUA Script - precede every function and global member with lowercase name of script + '_main' -- Default script - does nothing. local state = {} local walking = {} local curious = {} local attacking = {} local aggressive = {} local approaching = {} local animationcomplete = {} local hitting = {} local attacktype = {} local xpos = {} local zpos = {} local ypos = {} local setpos = {} local outofbounds = {} local timer = {} local timed = {} local started = {} local monsterpos = {} local maxdistance = {} local rotation = {} local direction = {} local nvolume = {} local maxvolume = {} local minvolume ={} function monster_waypoints_init(e) state[e] = "relaxed" walking[e] = 0 curious[e] = 0 attacking[e] = 0 aggressive[e] = 0 approaching[e] = 0 animationcomplete[e] = 1 hitting[e] = 0 attacktype[e] = 0 xpos[e] = 0 zpos[e] = 0 ypos[e] = 0 setpos[e] = 0 outofbounds[e] = 0 timer[e] = 0 timed[e] = 0 started[e] = 0 monsterpos[e] = 0 maxdistance[e] = 0 rotation[e] = 0 direction[e] = 0 SetSoundVolume(100) maxvolume[e] = 100 minvolume[e] = 1 nvolume[e] = 0 ai_soldier_pathindex[e] = -1 end function monster_waypoints_main(e) --Prompt(GetPlayerDistance(e).." Volume="..nvolume[e]) nvolume[e] = maxvolume[e] - ( GetPlayerDistance(e) / 300.0 ) if nvolume[e] < minvolume[e] then StopSound(e,0) end SetSoundVolume(nvolume[e]) rotation[e] = math.random(-20,20) if setpos[e] == 1 and maxdistance[e] < MonsterDistance(e) then maxdistance[e] = MonsterDistance(e) end if GetAnimationFrame(e) == 10 or GetAnimationFrame(e) == 60 or GetAnimationFrame(e) == 110 or GetAnimationFrame(e) == 160 then PlaySound(e,0) end if GetAnimationFrame(e) == 610 or GetAnimationFrame(e) == 660 or GetAnimationFrame(e) == 710 or GetAnimationFrame(e) == 760 then PlaySound(e,0) end if GetAnimationFrame(e) == 278 then PlaySound(e,1) end if setpos[e] == 0 then xpos[e] = g_Entity[e]['x'] zpos[e] = g_Entity[e]['z'] ypos[e] = g_Entity[e]['y'] setpos[e] = 1 end if MonsterDistance(e) > 5000 then outofbounds[e] = 1 timer[e] = 10 elseif MonsterDistance(e) < 5000 then outofbounds[e] = 0 end if outofbounds[e] == 0 then direction[e] = math.random(0,1) if direction[e] == 0 then direction[e] = -1 end end if outofbounds[e] == 1 and walking[e] == 1 then if started[e] == 0 then StartTimer(e) monsterpos[e] = MonsterDistance(e) started[e] = 1 end if GetTimer(e) > timer[e] then if MonsterDistance(e) > monsterpos[e] then RotateY(e,(40*direction[e])) end started[e] = 0 end end if aggressive[e] == 0 and animationcomplete[e] == 1 then if GetPlayerDistance(e) > 2000 then if state[e] ~= "walking" then g_Entity[e]['animating'] = 0 state[e] = "walking" end walking[e] = 1 curious[e] = 0 attacking[e] = 0 approaching[e] = 0 elseif GetPlayerDistance(e) < 2000 and GetPlayerDistance(e) > 1100 then if state[e] ~= "curious" then g_Entity[e]['animating'] = 0 state[e] = "curious" end walking[e] = 0 curious[e] = 1 attacking[e] = 0 approaching[e] = 0 elseif GetPlayerDistance(e) < 1100 then if state[e] ~= "attacking" then g_Entity[e]['animating'] = 0 state[e] = "attacking" end walking[e] = 0 curious[e] = 0 attacking[e] = 1 end elseif aggressive[e] == 1 and animationcomplete[e] == 1 then if GetPlayerDistance(e) < 1100 then if state[e] ~= "attacking" then g_Entity[e]['animating'] = 0 state[e] = "attacking" end walking[e] = 0 curious[e] = 0 attacking[e] = 1 approaching[e] = 0 end if GetPlayerDistance(e) > 1100 and GetPlayerDistance(e) < 4000 then if state[e] ~= "approaching" then g_Entity[e]['animating'] = 0 state[e] = "approaching" end walking[e] = 0 curious[e] = 0 attacking[e] = 0 approaching[e] = 1 end if GetPlayerDistance(e) > 4000 then if state[e] ~= "walking" then g_Entity[e]['animating'] = 0 state[e] = "walking" end walking[e] = 0 curious[e] = 0 attacking[e] = 0 approaching[e] = 1 aggressive[e] = 0 end end if walking[e] == 1 then ModulateSpeed(e,1) --Prompt(ai_soldier_pathindex[e]) 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 < 800 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 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 SetCharacterToWalk(e) CharacterControlUnarmed(e) --ModulateSpeed(e,walk_speed / 100) 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(g_Entity[e]['obj'],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 < 75 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 else CharacterControlLimbo(e) if g_Entity[e]['animating'] == 0 then SetAnimationFrames(10,210) PlayAnimation(e) g_Entity[e]['animating'] = 1 end MoveForward(e,150) if outofbounds[e] == 0 then RotateY(e,rotation[e]) end end end if approaching[e] == 1 then CharacterControlLimbo(e) ModulateSpeed(e,1.5) if g_Entity[e]['animating'] == 0 then SetAnimationFrames(610,810) PlayAnimation(e) g_Entity[e]['animating'] = 1 end RotateToPlayer(e) MoveForward(e,250) end if curious[e] == 1 then CharacterControlLimbo(e) ModulateSpeed(e,1) RotateToPlayerSlowly(e,5) if g_Entity[e]['animating'] == 0 then SetAnimationFrames(220,350) PlayAnimation(e) g_Entity[e]['animating'] = 1 end if GetAnimationFrame(e) == 350 then aggressive[e] = 1 animationcomplete[e] = 1 end if GetAnimationFrame(e) == 220 then animationcomplete[e] = 0 end end if attacking[e] == 1 then CharacterControlLimbo(e) if animationcomplete[e] == 1 then attacktype[e] = math.random(0,1) animationcomplete[e] = 0 end ModulateSpeed(e,1) RotateToPlayer(e) if attacktype[e] == 0 then if g_Entity[e]['animating'] == 0 then SetAnimationFrames(360,600) PlayAnimation(e) g_Entity[e]['animating'] = 1 end if (GetAnimationFrame(e) > 425 and GetAnimationFrame(e) < 432) or (GetAnimationFrame(e) > 516 and GetAnimationFrame(e) < 520) then hitting[e] = 1 elseif GetAnimationFrame(e) < 425 or (GetAnimationFrame(e) > 432 and GetAnimationFrame(e) < 516) or GetAnimationFrame(e) > 520 then hitting[e] = 0 end if GetAnimationFrame(e) == 360 then animationcomplete[e] = 0 end if GetAnimationFrame(e) == 600 then animationcomplete[e] = 1 end if hitting[e] == 1 and GetPlayerDistance(e) < 1300 and GetPlayerDistance(e) > 400 then HurtPlayer(e,500) end end if attacktype[e] == 1 then if g_Entity[e]['animating'] == 0 then SetAnimationFrames(830,890) PlayAnimation(e) g_Entity[e]['animating'] = 1 end if GetAnimationFrame(e) > 865 and GetAnimationFrame(e) < 870 and GetPlayerDistance(e) > 700 and GetPlayerDistance(e) < 1100 then HurtPlayer(e,500) end if GetAnimationFrame(e) == 830 then animationcomplete[e] = 0 end if GetAnimationFrame(e) == 890 then animationcomplete[e] = 1 end if hitting[e] == 1 and GetPlayerDistance(e) < 1100 then HurtPlayer(e,500) end end end end function monster_waypoints_exit(e) ModulateSpeed(e,1.0) CharacterControlLimbo(e) SetAnimationFrames(905,985) PlayAnimation(e) StopSound(e) end function MonsterDistance(e) monsterDX = (g_Entity[e]['x'] - xpos[e]) monsterDY = (g_Entity[e]['y'] - ypos[e]) monsterDZ = (g_Entity[e]['z'] - zpos[e]) if math.abs(monsterDY) > 100 then monsterDY = monsterDY * 4 end return math.sqrt(math.abs(monsterDX*monsterDX)+math.abs(monsterDY*monsterDY)+math.abs(monsterDZ*monsterDZ)); end