-- COMBATSHOOT Manager Module M = require "scriptbank\\ai\\module_core" MAG = require "scriptbank\\ai\\module_agro" MCC = require "scriptbank\\ai\\module_combatcore" local module_combatshoot = {} function module_combatshoot.init( e, combattype ) if combattype == ai_combattype_regular or combattype == ai_combattype_patrol then MCC.init( e, ai_state_findpatrolpath ) else MCC.init( e, ai_state_startidle ) end end local CanFire = {} function module_combatshoot.main( e, combattype, movetype, attacktype ) -- 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[ e ] ~= nil then combattype = ai_combattype_regular end if combattype == ai_combattype_guard then MCC.idle( e, Ent.obj, PlayerDist, CF, ai_state_startfireonspot, combattype ) else MCC.idle( e, Ent.obj, PlayerDist, CF, ai_state_startmove, combattype ) end -- handle AI that moves if combattype == ai_combattype_regular or combattype == ai_combattype_patrol then MCC.patrol( e, Ent.obj, PlayerDist, movetype, CF, ai_state_startmove, ai_state_startpatrol, combattype ) --MCC.hunt( e, Ent.obj, PlayerDist, movetype, CF, ai_state_startidle ) --MCC.handleducking( e, Ent.obj, PlayerDist ) --MCC.soundawareness( e, Ent.obj ) end -- handle patrol logic if combattype == ai_combattype_regular or combattype == ai_combattype_patrol then local aibs = ai_bot_state[ e ] if aibs == ai_state_idle or aibs == ai_state_move then if Ent.plrvisible == 1 and PlayerDist < AIGetEntityViewRange( Ent.obj ) then -- record last time seen target ai_bot_patroltime[e] = g_Time end if g_Time > ai_bot_patroltime[ e ] + 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[e] ~= -1 then ai_bot_state[ e ] = ai_state_startpatrol ai_bot_coverindex[e] = -1 ai_bot_targetx[ e ] = nil ai_bot_patroltime[ e ] = g_Time end end else ai_bot_patroltime[ e ] = g_Time end end -- handle attacks if combattype == ai_combattype_regular then MCC.sensepunch( e, Ent.obj, PlayerDist, combattype ) end -- handle hurt response if combattype == ai_combattype_guard then MCC.hurt( e, PlayerDist, ai_state_startfireonspot ) else MCC.hurt( e, PlayerDist, ai_state_startidle ) end -- handle events MCC.headshot( e ) MCC.punch( e, Ent.obj, PlayerDist, combattype, ai_state_startfireonspot ) MCC.recover( e, ai_state_startpatrol ) MCC.fireonspot( e, Ent.obj) MCC.reloadweapon( e ) -- handle debugging --M.debug( e, Ent.obj, PlayerDist, combattype ) end function module_combatshoot.preexit( e, movetype ) return MCC.preexit( e, movetype ) end function module_combatshoot.exit( e ) MCC.exit( e ) end return module_combatshoot