-- COMBATSHOOT Manager Module local M = require "scriptbank\\ai\\module_core" local MAG = require "scriptbank\\ai\\module_agro" local MCC = require "scriptbank\\ai\\module_combatcore" local MCS = {} function MCS.init( e, combattype ) if combattype == ai_combattype_regular or combattype == ai_combattype_patrol then MCC.init( e, "findpatrolpath" ) else MCC.init( e, "startidle" ) end end local CanFire = {} function MCS.main( e, combattype, movetype, attacktype ) local ai_bot = g_aiList[ e ] if ai_bot == nil then PromptLocal( e, "Not Initialised" ) return end -- DEBUG OPTION - make player undetectable so can test AI waypoints --g_Entity[e]['plrvisible'] = 0 local Ent = g_Entity[ e ] -- common vars local PlayerDist = M.getplayerdist( e ) -- attack types local CF = CanFire[ e ] if CF == nil then CanFire[ e ] = false return else if attacktype == ai_attacktype_canfire then CF = true end end -- handle idle if ai_bot.angryhurt ~= nil then combattype = ai_combattype_regular end if combattype == ai_combattype_guard then MCC.idle( e, ai_bot, Ent.obj, PlayerDist, CF, "startfireonspot" , combattype ) else MCC.idle( e, ai_bot, Ent.obj, PlayerDist, CF, "startmove", combattype ) end -- handle AI that moves if combattype == ai_combattype_regular or combattype == ai_combattype_patrol then MCC.patrol( e, ai_bot, Ent.obj, PlayerDist, movetype, CF, "startmove", "startpatrol" , combattype ) MCC.hunt( e, ai_bot, Ent.obj, PlayerDist, movetype, CF, "startidle" ) MCC.handleducking( e, ai_bot, Ent.obj, PlayerDist ) MCC.soundawareness( e, ai_bot, Ent.obj ) end -- handle patrol logic if combattype == ai_combattype_regular or combattype == ai_combattype_patrol then if ai_bot.state == "idle" or ai_bot.state == "move" then if Ent.plrvisible == 1 and PlayerDist < AIGetEntityViewRange( Ent.obj ) then -- record last time seen target ai_bot.patroltime = g_Time end if g_Time > ai_bot.patroltime + 5000 then -- after X seconds elapsed, return to patrol -- only if a ai_bot_pathindex exist , otherwise this will just flicker the idle animation. if ai_bot.pathindex ~= -1 then ai_bot.state = "startpatrol" ai_bot.coverindex = -1 ai_bot.targetx = nil ai_bot.patroltime = g_Time end end else ai_bot.patroltime = g_Time end end -- handle attacks if combattype == ai_combattype_regular then MCC.sensepunch( e, ai_bot, Ent.obj, PlayerDist, combattype ) end -- handle hurt response if combattype == ai_combattype_guard then MCC.hurt( e, ai_bot, PlayerDist, "startfireonspot" ) else MCC.hurt( e, ai_bot, PlayerDist, "startidle" ) end -- handle events MCC.headshot( e ) MCC.punch( e, ai_bot, Ent.obj, PlayerDist, combattype, "startfireonspot" ) MCC.recover( e, ai_bot, "startpatrol" ) MCC.fireonspot( e, ai_bot, Ent.obj) MCC.reloadweapon( e, ai_bot ) -- handle debugging --M.debug( e, ai_bot, Ent.obj, PlayerDist, combattype ) end function MCS.preexit( e, movetype ) return MCC.preexit( e, g_aiList[ e ], movetype ) end function MCS.exit( e ) MCC.exit( e ) end return MCS