-- ***************************************************************************** -- ** ClientWatch ** -- ********************************************************* Set_AllClients = SET_CLIENT:New():FilterOnce() Jtff_log.debug(string.format("Nbre Clients : %i", Set_AllClients:Count()),"GENERAL") Set_AllBlueClients = SET_CLIENT:New():FilterCoalitions(coalition.side.BLUE):FilterOnce() Jtff_log.debug(string.format("Nbre Blue Client : %i", Set_AllBlueClients:Count()),"GENERAL") Set_AllRedClients = SET_CLIENT:New():FilterCoalitions(coalition.side.RED):FilterOnce() Jtff_log.debug(string.format("Nbre Red Client : %i", Set_AllRedClients:Count()),"GENERAL") AllClientsWatch = CLIENTWATCH:New(Set_AllClients:GetSetNames()) AllClientsWatch:HandleEvent(EVENTS.PlayerEnterAircraft) AllClientsWatch:HandleEvent(EVENTS.Refueling) AllClientsWatch:HandleEvent(EVENTS.RefuelingStop) function AllClientsWatch:OnEventPlayerEnterAircraft(EventData) if (EventData.IniGroupName) then Jtff_log.debug(string.format("OnEventPlayerEnterAircraft: IniGroupName = %s", EventData.IniGroupName),"GENERAL") Jtff_log.debug(string.format("OnEventPlayerEnterAircraft: IniPlayerName = %s", EventData.IniPlayerName),"GENERAL") Jtff_log.debug(string.format("OnEventPlayerEnterAircraft: IniUnitName = %s", net.lua2json(EventData.IniUnitName)),"GENERAL") local clientGroup = GROUP:FindByName(EventData.IniGroupName) local clientUnit = UNIT:FindByName(EventData.IniUnitName) local clientSetting = SETTINGS:Set( EventData.IniPlayerName) clientSetting:SetImperial() clientSetting:SetA2G_MGRS() clientSetting:SetMenutextShort(true) if type(InterceptArray) == 'table' then for index, objIntercept in ipairs(InterceptArray) do if (objIntercept.menus[clientUnit:GetCoalition()]) then MENU_GROUP_COMMAND:New( clientGroup, "High Aspect", objIntercept.menus[clientUnit:GetCoalition()], StartInterceptTraining, {clientUnit:GetName(),index,-20,20} ) MENU_GROUP_COMMAND:New( clientGroup, "Medium Aspect Left", objIntercept.menus[clientUnit:GetCoalition()], StartInterceptTraining, {clientUnit:GetName(),index,20,50} ) MENU_GROUP_COMMAND:New( clientGroup, "Medium Aspect Right", objIntercept.menus[clientUnit:GetCoalition()], StartInterceptTraining, {clientUnit:GetName(),index,-50,-20} ) MENU_GROUP_COMMAND:New( clientGroup, "Low Aspect Left", objIntercept.menus[clientUnit:GetCoalition()], StartInterceptTraining, {clientUnit:GetName(),index,50,80} ) MENU_GROUP_COMMAND:New( clientGroup, "Low Aspect Right", objIntercept.menus[clientUnit:GetCoalition()], StartInterceptTraining, {clientUnit:GetName(),index,-80,-50} ) end end end Jtff_log.debug(string.format("Add QRA Menu for group [%s], player name [%s]",EventData.IniGroupName , EventData.IniPlayerName),"QRA") if type(QRAArray) == 'table' then for index, objQRA in ipairs(QRAArray) do if (MenuCoalitionQRA[UTILS.GetCoalitionName(clientUnit:GetCoalition())]) and (objQRA.customconfig.type == JTFF_QRA.Type.TangoAuto) then objQRA.menu[clientUnit:GetCoalition()] = MENU_GROUP_COMMAND:New( clientGroup, "Trigger " .. objQRA.customconfig.name, MenuCoalitionQRA[UTILS.GetCoalitionName(clientUnit:GetCoalition())], QRATrigger, { objQRA, clientUnit:GetName(), index, } ) end end end Jtff_log.debug( string.format( "Add Tanker Menu for group [%s], player name [%s]", EventData.IniGroupName, EventData.IniPlayerName ), "TANKER" ) if clientUnit:GetCoalition() == coalition.side.BLUE then MENU_GROUP_COMMAND:New( clientGroup, "Nearest Tanker Info", MenuCoalitionTankers[UTILS.GetCoalitionName(coalition.side.BLUE)], NearestTankerInfo, { clientUnit, clientGroup} ) MENU_GROUP_COMMAND:New( clientGroup, "All Tankers Info", MenuCoalitionTankers[UTILS.GetCoalitionName(coalition.side.BLUE)], AllTankersInfo, {clientUnit,clientGroup} ) else MENU_GROUP_COMMAND:New( clientGroup, "Nearest Tanker Info", MenuCoalitionTankers[UTILS.GetCoalitionName(coalition.side.RED)], NearestTankerInfo, { clientUnit, clientGroup} ) MENU_GROUP_COMMAND:New( clientGroup, "All Tankers Info", MenuCoalitionTankers[UTILS.GetCoalitionName(coalition.side.RED)], AllTankersInfo, {clientUnit,clientGroup} ) end local GroupMenu = MENU_GROUP:New( clientGroup, "My Group settings" ) Jtff_log.debug(string.format("Add Immortal Menu for group [%s], player name [%s]",EventData.IniGroupName , EventData.IniPlayerName),"GENERAL") BASE:SetState( clientGroup, "isImmortal", false ) BASE:SetState( clientUnit, "isRefueling", false ) MENU_GROUP_COMMAND:New( clientGroup, "Switch immortal status", GroupMenu, SwitchGroupImmortalStatus, clientGroup ) if (type(AIRBOSSArray) == 'table') then if #AIRBOSSArray > 0 then MENU_GROUP_COMMAND:New( clientGroup, "Switch Airboss subtitles", GroupMenu, SwitchGroupAirbossSubtitlesStatus, clientGroup ) end end end end function AllClientsWatch:OnEventRefueling(EventData) if (EventData.initiator) then if NET:GetMyPlayerID() == 1 then --trigger.action.outText("Vous ĂȘtes en mode multijoueur.", 90) local tankerUnit = UNIT:Find(EventData.initiator) local refuelingUnitsSearchRadiusMeters = 150 local tankerUnitName = 'unknown' local client local clientUnit local clientFuel = 0 local clientName = 'unknown' if (type(tankerUnit) ~= 'nil') then local clientRefuelableSet = SET_CLIENT:New() --trigger.action.outText(string.format("clientRefuelableSet init count = %d",clientRefuelableSet:Count()), 90) --trigger.action.outText(string.format("tankerUnit = %s",tankerUnit:GetName()), 90) tankerUnitName = tankerUnit:GetName() local isTanker, tankerRefuelSystem = tankerUnit:IsTanker() local refuelingUnitsSet = tankerUnit :GetCoordinate() :ScanUnits(refuelingUnitsSearchRadiusMeters) :FilterCoalitions(tankerUnit:GetCoalitionName()) :FilterActive(true) :FilterAlive() :FilterFunction( function(unit) local isRefuelable, unitrefuelsystem = unit:IsRefuelable() return isRefuelable and unitrefuelsystem == tankerRefuelSystem end) :ForEachUnit( function(unit) local clientRefueling = CLIENT:Find(unit:GetDCSObject(), true) --trigger.action.outText(string.format("testing unit %s for clientRefuelableSet",unit:GetName()), 90) if type(clientRefueling) ~= 'nil' then clientRefuelableSet:AddObject(clientRefueling) Jtff_log.trace(string.format("adding %s to clientRefuelableSet (refuelable aicrafts near tanker)",clientRefueling:GetPlayer()),"TANKER") end end ) Jtff_log.trace(string.format("refuelingUnitSet (refuelable aicrafts near tanker) : count = %d",refuelingUnitsSet:Count()),"TANKER") Jtff_log.trace(string.format("clientRefuelableSet (client refuelable aircrafts near tanker): count = %d",clientRefuelableSet:Count()),"TANKER") if clientRefuelableSet:Count() >= 1 then if clientRefuelableSet:Count() >= 2 then clientRefuelableSet:ForEachClient( function(curClient) local clientUnitObject = curClient:GetClientGroupUnit() local clientFuelMassMax = clientUnitObject:GetFuel() * clientUnitObject:GetDesc().fuelMassMax if not(BASE:GetState(clientUnitObject, "isRefueling")) then local mytimer=TIMER:New( function(unit, clientObject, initialFuelState, tankerName) if (unit:GetFuel() * unit:GetDesc().fuelMassMax-initialFuelState >= 0) then local clientNameString = clientObject:GetPlayer() or unit:GetName() BASE:SetState( unit, "isRefueling", true ) BASE:SetState( unit, "FuelState", initialFuelState ) Jtff_log.info( string.format( "[%s] Start refueling at the tanker [%s], current fuel : %.0f Lbs", clientNameString, tankerName, UTILS.kg2lbs(initialFuelState) ), "TANKER" ) end end, clientUnitObject, curClient, clientFuelMassMax, tankerUnitName ) mytimer:Start(2) end end ) else client = clientRefuelableSet:GetFirst() clientUnit = client:GetClientGroupUnit() clientFuel = clientUnit:GetFuel() * clientUnit:GetDesc().fuelMassMax clientName = client:GetPlayer() or clientUnit:GetName() BASE:SetState( clientUnit, "FuelState", clientFuel ) BASE:SetState( clientUnit, "isRefueling", true ) Jtff_log.info(string.format("[%s] Start refueling at the tanker [%s], current fuel : %.0f Lbs", clientName, tankerUnitName, UTILS.kg2lbs(clientFuel)),"TANKER") end end else Jtff_log.error("tanker not found !!!","TANKER") end else --trigger.action.outText("Vous ĂȘtes en mode solo.", 90) local client = CLIENT:Find(EventData.initiator, true) if (type(client) ~= 'nil') then local clientUnit = UNIT:Find(EventData.initiator) or {} local clientFuel = clientUnit:GetFuel() * clientUnit:GetDesc().fuelMassMax local tankerUnit = GetNearestTankerfromPlayerUnit(clientUnit) local tankerUnitName = 'unknown' if (type(tankerUnit) ~= 'nil') then tankerUnitName = tankerUnit:GetName() end local clientName = clientUnit:GetName() clientName = client:GetPlayer() BASE:SetState( clientUnit, "FuelState", clientFuel ) BASE:SetState( clientUnit, "isRefueling", true ) Jtff_log.info(string.format("[%s] Start refueling at the tanker [%s], current fuel : %.0f Lbs", clientName, tankerUnitName, UTILS.kg2lbs(clientFuel)),"TANKER") end end end end function AllClientsWatch:OnEventRefuelingStop(EventData) if (EventData.initiator) then local client = CLIENT:Find(EventData.initiator, true) if (type(client) ~= 'nil') then local clientUnit = UNIT:Find(EventData.initiator) or {} local clientFuel = clientUnit:GetFuel() * clientUnit:GetDesc().fuelMassMax local tankerUnit = GetNearestTankerfromPlayerUnit(clientUnit) local tankerUnitName = 'unknown' if (type(tankerUnit) ~= 'nil') then tankerUnitName = tankerUnit:GetName() end if not(BASE:GetState(clientUnit,"isRefueling")) then Jtff_log.error(string.format("impossible to determine accurately fuel taken by [%s] : trying anyway...",client:GetPlayer()),"TANKER") end local clientFuelTaken = clientFuel - BASE:GetState(clientUnit,"FuelState") BASE:SetState( clientUnit, "FuelState", clientFuel ) BASE:SetState( clientUnit, "isRefueling", false ) Jtff_log.info(string.format("[%s] just finsihed refueling at the tanker [%s], taken %.0f Lbs",client:GetPlayer() , tankerUnitName, UTILS.kg2lbs(clientFuelTaken)),"TANKER") if (type(Jtff_dcsbot) ~= 'nil') then local title = string.format('End of Air refuel !') local description = string.format("[%s] just finsihed refueling at the tanker [%s], taken %.0f Lbs",client:GetPlayer() , tankerUnitName, UTILS.kg2lbs(clientFuelTaken)) local img = 'https://cdn10.picryl.com/photo/2004/10/03/a-us-navy-usn-f-14b-tomcat-aircraft-assigned-to-fighter-squadron-one-zero-three-f5f749-1024.jpg' local fields = { ['Pilot'] = client:GetPlayer(), ['Tanker'] = tankerUnitName, ['RefuelQty'] = string.format("%.0f Lbs", UTILS.kg2lbs(clientFuelTaken)) } local footer = 'Sorry, tomcats took it all again...' Jtff_dcsbot.sendEmbed(title, description, img, fields, footer) end end end end