-- ***************************************************************************** -- ** FoxZone Training ** -- ********************************************************* -- region FoxZoneConfigFunctions -- @type FOXZoneConfig -- @field #boolean enable Enable the fox zone training -- @field #string name Name of the fox zone training -- @field #boolean debug Debug the fox zone training -- @field #boolean f10Menu Enable the f10 menu -- @field #string launchZoneName Launch zone name -- @field #string safeZoneName Safe zone name -- @field #boolean missileDestruction Missile destruction -- @field #boolean missileLaunchMessages Missile launch messages -- @field #boolean drawzone Draw the zone -- @field #number distance_small_missile Distance of the small missile detonation in meters -- @field #number distance_big_missile Distance of the big missile detonation in meters --- Parse Fox Zone training config from JSON --- @param #JsonObject config Config object to parse --- @return #FOXZoneConfig foxZoneConfigJson Parsed FOXZoneConfig object function ParseFoxZoneConfigJson(config) local json = require('Scripts/json') local parser_name = "FOX_ZONE" -- ************************************************************************** -- enable -- ************************************************************************** local foxZoneConfigJson if config.enable == true then foxZoneConfigJson = config else foxZoneConfigJson = { enable = false, } end Jtff_log.debug( string.format( "parsed Fox Zone training config for %s Zone, resulting config :\n%s", config.type or "", json:encode( foxZoneConfigJson, { indent = true } ) ), parser_name ) return foxZoneConfigJson end -- endregion FoxZoneConfigFunctions -- region FoxZoneFunctions function toggleMissileScript(objFoxZone) if (objFoxZone:Is("Running")) then Jtff_log.info('stoping Fox Zone : '.. objFoxZone.customconfig.name..'...',"FOX_ZONE") objFoxZone:__Stop(0) else Jtff_log.info('starting Fox Zone : '.. objFoxZone.customconfig.name..'...',"FOX_ZONE") objFoxZone:__Start(0) end end function getMissileScriptStatus(objFoxZone) for playername,_playersettings in pairs(objFoxZone.players) do local playersettings=_playersettings --#FOX.PlayerData if playersettings.inzone then local message = '[' .. playername .. '] training area ' .. objFoxZone.customconfig.name .. ' missile script is [' .. objFoxZone:GetState() .. ']' MESSAGE:NewType(message, MESSAGE.Type.Overview):ToClient(playersettings.client) end end end -- endregion FoxZoneFunctions FoxRangesArray = {} local compteur = #FoxRangesArray MenuCoalitionFoxZone = MENU_MISSION:New("Missile training Zones", nil) for index, currentFoxZoneConfigObject in ipairs(FoxRangesConfig) do local foxzoneconfig = ParseFoxZoneConfigJson(currentFoxZoneConfigObject) if foxzoneconfig.enable == true then compteur = compteur + 1 Jtff_log.info( string.format( 'creation Fox Zone : %s ...', foxzoneconfig.name ), "FOX_ZONE" ) local objFoxZone = FOX:New() objFoxZone:SetExplosionPower(0.01) :SetExplosionDistance(foxzoneconfig.distance_small_missile or 100) :SetExplosionDistanceBigMissiles(foxzoneconfig.distance_big_missile or 150) :SetDefaultMissileDestruction(foxzoneconfig.missileDestruction) :SetDefaultLaunchAlerts(foxzoneconfig.missileLaunchMessages) :SetDefaultLaunchMarks(false) local launchGroupObject = GROUP:FindByName(foxzoneconfig.launchZoneName) if type(launchGroupObject) ~= 'nil' then objFoxZone.objLaunchZone = ZONE_POLYGON:New( string.format( 'FOX_LAUNCH_ZONE_%s', foxzoneconfig.name ), launchGroupObject ) else objFoxZone.objLaunchZone = ZONE:New(foxzoneconfig.launchZoneName) end objFoxZone:AddLaunchZone(objFoxZone.objLaunchZone) Jtff_log.info( string.format( 'Launch zone Polygon %s created ...', objFoxZone.objLaunchZone:GetName() ), "FOX_ZONE" ) if ((foxzoneconfig.drawzone == true) or false) then objFoxZone.objLaunchZone:DrawZone( -1, {1,0,0}, 1, {1,0,0}, 0.10, 4, true, nil ) objFoxZone.objLaunchZone:GetCoordinate():TextToAll( string.format( "Missile trainer %s", foxzoneconfig.name ), -1, {1,0,0}, 1, {1,0,0}, 0, 20, true ) end local safeZoneGroupObject = GROUP:FindByName(foxzoneconfig.safeZoneName) if type(safeZoneGroupObject) ~= 'nil' then objFoxZone.objSafeZone = ZONE_POLYGON:New( string.format( 'FOX_SAFE_ZONE_%s', foxzoneconfig.name ), safeZoneGroupObject ) else objFoxZone.objSafeZone = ZONE:New(foxzoneconfig.safeZoneName) end objFoxZone:AddSafeZone(objFoxZone.objSafeZone) if foxzoneconfig.debug then objFoxZone:SetDebugOn() end objFoxZone.menudisabled = foxzoneconfig.f10Menu == false if (foxzoneconfig.f10Menu) then objFoxZone:SetEnableF10Menu() else objFoxZone:SetDisableF10Menu() end objFoxZone.menuZone = MENU_MISSION:New(foxzoneconfig.name, MenuCoalitionFoxZone) objFoxZone.customconfig = foxzoneconfig -- **** Message to client ***** function objFoxZone:OnAfterEnterSafeZone(From, Event, To, player) local message = string.format( '[%s] You\'re entering in the missile trainer area %s. Missile script is [%s]', player.name, foxzoneconfig.name, objFoxZone:GetState() ) MESSAGE:NewType(message, MESSAGE.Type.Overview):ToClient(player.client) end function objFoxZone:OnAfterExitSafeZone(From, Event, To, player) local message = string.format( '[%s] You\'re leaving the missile trainer area %s. Missile script is [%s]', player.name, foxzoneconfig.name, objFoxZone:GetState() ) MESSAGE:NewType(message, MESSAGE.Type.Overview):ToClient(player.client) end function objFoxZone:OnAfterStop(From, Event, To) local message = string.format( 'Training area [%s] -> Script has been unactivated. Missile script is [%s]', foxzoneconfig.name, objFoxZone:GetState() ) MESSAGE:NewType(message, MESSAGE.Type.Overview):ToAll() end function objFoxZone:OnAfterStart(From, Event, To) local message = string.format( 'Training area [%s] -> Script has been activated. Missile script is [%s]', foxzoneconfig.name, objFoxZone:GetState() ) MESSAGE:NewType(message, MESSAGE.Type.Overview):ToAll() end function objFoxZone:OnAfterMissileDestroyed(From, Event, To, missile) local unitTargeted = missile.targetUnit -- #Wrapper.Unit#UNIT local playerTargeted = missile.targetPlayer -- #FOX.PlayerData local unitShooter = missile.shooterUnit -- #Wrapper.Unit#UNIT local missileType = missile.missileType -- string local missileName = missile.missileName -- string local playerNameTargeted = playerTargeted.name -- string local clientShooter = CLIENT:Find(unitShooter:GetDCSObject(), '', false) local message = '' if (clientShooter) then local playerNameShooter = clientShooter:GetPlayerName() message = playerNameTargeted .. ' HAS BEEN SHOT DOWN BY ' .. playerNameShooter else message = playerNameTargeted .. ' HAS BEEN SHOT DOWN BY ' .. unitShooter:GetName() end Jtff_log.info(message,"FOX_ZONE") Set_AllClients:ForEachClientInZone(objFoxZone.objSafeZone, function(clientInZone) if clientInZone:IsAlive() then MESSAGE:NewType(message, MESSAGE.Type.Update):ToClient(clientInZone) end end) end -- ***************************** FoxRangesArray[compteur] = objFoxZone FoxRangesArray[compteur]:Start() FoxRangesArray[compteur].commandToggle = MENU_MISSION_COMMAND:New( "Toggle missile script", FoxRangesArray[compteur].menuZone, toggleMissileScript, FoxRangesArray[compteur]) FoxRangesArray[compteur].commandStatus = MENU_MISSION_COMMAND:New( "missile script status", FoxRangesArray[compteur].menuZone, getMissileScriptStatus, FoxRangesArray[compteur]) end end