@jtff/miztemplate-lib 3.7.8 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lua/src/020-mission_functions.lua +10 -11
- package/lua/src/110-set_clients.lua +134 -33
- package/package.json +1 -1
|
@@ -186,14 +186,13 @@ function getNearestTankerfromPlayerUnit(PlayerUnit, Radius)
|
|
|
186
186
|
|
|
187
187
|
local isrefuelable, playerrefuelsystem=PlayerUnit:IsRefuelable()
|
|
188
188
|
if isrefuelable then
|
|
189
|
-
local
|
|
190
|
-
local
|
|
189
|
+
local playerCoordinates=PlayerUnit:GetCoordinate()
|
|
190
|
+
local unitList=playerCoordinates:ScanUnits(Radius)
|
|
191
191
|
local coalition=PlayerUnit:GetCoalition()
|
|
192
192
|
|
|
193
|
-
local
|
|
194
|
-
local
|
|
195
|
-
for
|
|
196
|
-
local unit = _unit --Wrapper.Unit#UNIT
|
|
193
|
+
local minDistance = math.huge
|
|
194
|
+
local foundTanker = nil --Wrapper.Unit#UNIT
|
|
195
|
+
for index,unit in pairs(unitList.Set) do
|
|
197
196
|
local istanker, tankerrefuelsystem=unit:IsTanker()
|
|
198
197
|
if istanker and
|
|
199
198
|
playerrefuelsystem == tankerrefuelsystem and
|
|
@@ -201,14 +200,14 @@ function getNearestTankerfromPlayerUnit(PlayerUnit, Radius)
|
|
|
201
200
|
unit:IsAlive() then
|
|
202
201
|
|
|
203
202
|
-- Distance.
|
|
204
|
-
local d = unit:GetCoordinate():Get2DDistance(
|
|
205
|
-
if d <
|
|
206
|
-
d =
|
|
207
|
-
|
|
203
|
+
local d = unit:GetCoordinate():Get2DDistance(playerCoordinates)
|
|
204
|
+
if d < minDistance then
|
|
205
|
+
d = minDistance
|
|
206
|
+
foundTanker=unit
|
|
208
207
|
end
|
|
209
208
|
end
|
|
210
209
|
end
|
|
211
|
-
return
|
|
210
|
+
return foundTanker
|
|
212
211
|
end
|
|
213
212
|
return nil
|
|
214
213
|
end
|
|
@@ -51,50 +51,151 @@ function Set_CLIENT:OnEventPlayerEnterAircraft(EventData)
|
|
|
51
51
|
local GroupMenu = MENU_GROUP:New( EventData.IniGroup, "My Group settings" )
|
|
52
52
|
jtff_log.debug(string.format("Add Immortal Menu for group [%s], player name [%s]",EventData.IniGroupName , EventData.IniPlayerName),"GENERAL")
|
|
53
53
|
BASE:SetState( EventData.IniGroup, "isImmortal", false )
|
|
54
|
+
BASE:SetState( EventData.IniUnit, "isRefueling", false )
|
|
54
55
|
MENU_GROUP_COMMAND:New( EventData.IniGroup, "Switch immortal status", GroupMenu, switchGroupImmortalStatus, EventData.IniGroup )
|
|
55
|
-
if
|
|
56
|
-
|
|
56
|
+
if (type(AIRBOSSArray) == 'table') then
|
|
57
|
+
if #AIRBOSSArray > 0 then
|
|
58
|
+
MENU_GROUP_COMMAND:New( EventData.IniGroup, "Switch Airboss subtitles", GroupMenu, switchGroupAirbossSubtitlesStatus, EventData.IniGroup )
|
|
59
|
+
end
|
|
57
60
|
end
|
|
58
61
|
end
|
|
59
62
|
end
|
|
60
63
|
function Set_CLIENT:OnEventRefueling(EventData)
|
|
61
64
|
if (EventData.initiator) then
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
if NET:GetMyPlayerID() == 1 then
|
|
66
|
+
--trigger.action.outText("Vous êtes en mode multijoueur.", 90)
|
|
67
|
+
local tankerUnit = UNIT:Find(EventData.initiator)
|
|
68
|
+
local refuelingUnitsSearchRadiusMeters = 150
|
|
69
|
+
local tankerUnitName = 'unknown'
|
|
70
|
+
local client = nil
|
|
71
|
+
local clientUnit = nil
|
|
72
|
+
local clientFuel = 0
|
|
73
|
+
local clientName = 'unknown'
|
|
74
|
+
if (type(tankerUnit) ~= 'nil') then
|
|
75
|
+
local clientRefuelableSet = SET_CLIENT:New()
|
|
76
|
+
--trigger.action.outText(string.format("clientRefuelableSet init count = %d",clientRefuelableSet:Count()), 90)
|
|
77
|
+
--trigger.action.outText(string.format("tankerUnit = %s",tankerUnit:GetName()), 90)
|
|
78
|
+
tankerUnitName = tankerUnit:GetName()
|
|
79
|
+
local isTanker, tankerRefuelSystem = tankerUnit:IsTanker()
|
|
80
|
+
local refuelingUnitsSet = tankerUnit
|
|
81
|
+
:GetCoordinate()
|
|
82
|
+
:ScanUnits(refuelingUnitsSearchRadiusMeters)
|
|
83
|
+
:FilterCoalitions(tankerUnit:GetCoalitionName())
|
|
84
|
+
:FilterActive(true)
|
|
85
|
+
:FilterAlive()
|
|
86
|
+
:FilterFunction(
|
|
87
|
+
function(unit)
|
|
88
|
+
local isRefuelable, unitrefuelsystem = unit:IsRefuelable()
|
|
89
|
+
return isRefuelable and unitrefuelsystem == tankerRefuelSystem
|
|
90
|
+
end)
|
|
91
|
+
:ForEachUnit(
|
|
92
|
+
function(unit)
|
|
93
|
+
local clientRefueling = CLIENT:Find(unit:GetDCSObject(), true)
|
|
94
|
+
--trigger.action.outText(string.format("testing unit %s for clientRefuelableSet",unit:GetName()), 90)
|
|
95
|
+
if type(clientRefueling) ~= 'nil' then
|
|
96
|
+
clientRefuelableSet:AddObject(clientRefueling)
|
|
97
|
+
jtff_log.trace(string.format("adding %s to clientRefuelableSet (refuelable aicrafts near tanker)",clientRefueling:GetPlayer()),"TANKER")
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
)
|
|
101
|
+
jtff_log.trace(string.format("refuelingUnitSet (refuelable aicrafts near tanker) : count = %d",refuelingUnitsSet:Count()),"TANKER")
|
|
102
|
+
jtff_log.trace(string.format("clientRefuelableSet (client refuelable aircrafts near tanker): count = %d",clientRefuelableSet:Count()),"TANKER")
|
|
103
|
+
if clientRefuelableSet:Count() >= 1 then
|
|
104
|
+
if clientRefuelableSet:Count() >= 2 then
|
|
105
|
+
clientRefuelableSet:ForEachClient(
|
|
106
|
+
function(client)
|
|
107
|
+
local clientUnit = client:GetClientGroupUnit()
|
|
108
|
+
local clientFuel = clientUnit:GetFuel() * clientUnit:GetDesc().fuelMassMax
|
|
109
|
+
if not(BASE:GetState(clientUnit, "isRefueling")) then
|
|
110
|
+
local mytimer=TIMER:New(
|
|
111
|
+
function(unit, clientObject, initialFuelState, tankerName)
|
|
112
|
+
if (unit:GetFuel() * unit:GetDesc().fuelMassMax-initialFuelState >= 0) then
|
|
113
|
+
local clientName = clientObject:GetPlayer() or unit:GetName()
|
|
114
|
+
BASE:SetState( unit, "isRefueling", true )
|
|
115
|
+
BASE:SetState( unit, "FuelState", initialFuelState )
|
|
116
|
+
jtff_log.info(
|
|
117
|
+
string.format(
|
|
118
|
+
"[%s] Start refueling at the tanker [%s], current fuel : %.0f Lbs",
|
|
119
|
+
clientName,
|
|
120
|
+
tankerName,
|
|
121
|
+
UTILS.kg2lbs(initialFuelState)
|
|
122
|
+
),
|
|
123
|
+
"TANKER"
|
|
124
|
+
)
|
|
125
|
+
end
|
|
126
|
+
end,
|
|
127
|
+
clientUnit,
|
|
128
|
+
client,
|
|
129
|
+
clientFuel,
|
|
130
|
+
tankerUnitName
|
|
131
|
+
)
|
|
132
|
+
mytimer:Start(2)
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
)
|
|
136
|
+
else
|
|
137
|
+
client = clientRefuelableSet:GetFirst()
|
|
138
|
+
clientUnit = client:GetClientGroupUnit()
|
|
139
|
+
clientFuel = clientUnit:GetFuel() * clientUnit:GetDesc().fuelMassMax
|
|
140
|
+
clientName = client:GetPlayer() or clientUnit:GetName()
|
|
141
|
+
BASE:SetState( clientUnit, "FuelState", clientFuel )
|
|
142
|
+
BASE:SetState( clientUnit, "isRefueling", true )
|
|
143
|
+
jtff_log.info(string.format("[%s] Start refueling at the tanker [%s], current fuel : %.0f Lbs", clientName, tankerUnitName, UTILS.kg2lbs(clientFuel)),"TANKER")
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
else
|
|
147
|
+
jtff_log.error("tanker not found !!!","TANKER")
|
|
148
|
+
end
|
|
149
|
+
else
|
|
150
|
+
--trigger.action.outText("Vous êtes en mode solo.", 90)
|
|
151
|
+
local client = CLIENT:Find(EventData.initiator, true)
|
|
152
|
+
if (type(client) ~= 'nil') then
|
|
153
|
+
local clientUnit = UNIT:Find(EventData.initiator)
|
|
154
|
+
local clientFuel = clientUnit:GetFuel() * clientUnit:GetDesc().fuelMassMax
|
|
155
|
+
local tankerUnit = getNearestTankerfromPlayerUnit(clientUnit)
|
|
156
|
+
local tankerUnitName = 'unknown'
|
|
157
|
+
if (type(tankerUnit) ~= 'nil') then
|
|
158
|
+
tankerUnitName = tankerUnit:GetName()
|
|
159
|
+
end
|
|
160
|
+
local clientName = clientUnit:GetName()
|
|
161
|
+
clientName = client:GetPlayer()
|
|
162
|
+
BASE:SetState( clientUnit, "FuelState", clientFuel )
|
|
163
|
+
BASE:SetState( clientUnit, "isRefueling", true )
|
|
164
|
+
jtff_log.info(string.format("[%s] Start refueling at the tanker [%s], current fuel : %.0f Lbs", clientName, tankerUnitName, UTILS.kg2lbs(clientFuel)),"TANKER")
|
|
165
|
+
end
|
|
69
166
|
end
|
|
70
|
-
jtff_log.trace(string.format("[%s] Start to refuel at the tanker [%s], current fuel : %.0f Lbs",client:GetPlayer() , tankerUnitName, UTILS.kg2lbs(clientFuel)),"TANKER")
|
|
71
|
-
BASE:SetState( client, "Fuel", clientFuel )
|
|
72
167
|
end
|
|
73
168
|
end
|
|
74
169
|
function Set_CLIENT:OnEventRefuelingStop(EventData)
|
|
75
170
|
if (EventData.initiator) then
|
|
76
|
-
local client = CLIENT:Find(EventData.initiator)
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
local
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
[
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
171
|
+
local client = CLIENT:Find(EventData.initiator, true)
|
|
172
|
+
if (type(client) ~= 'nil') then
|
|
173
|
+
local clientUnit = UNIT:Find(EventData.initiator)
|
|
174
|
+
local clientFuel = clientUnit:GetFuel() * clientUnit:GetDesc().fuelMassMax
|
|
175
|
+
local tankerUnit = getNearestTankerfromPlayerUnit(clientUnit)
|
|
176
|
+
local tankerUnitName = 'unknown'
|
|
177
|
+
if (type(tankerUnit) ~= 'nil') then
|
|
178
|
+
tankerUnitName = tankerUnit:GetName()
|
|
179
|
+
end
|
|
180
|
+
if not(BASE:GetState(clientUnit,"isRefueling")) then
|
|
181
|
+
jtff_log.error(string.format("impossible to determine accurately fuel taken by [%s] : trying anyway...",client:GetPlayer()),"TANKER")
|
|
182
|
+
end
|
|
183
|
+
local clientFuelTaken = clientFuel - BASE:GetState(clientUnit,"FuelState")
|
|
184
|
+
BASE:SetState( clientUnit, "FuelState", clientFuel )
|
|
185
|
+
BASE:SetState( clientUnit, "isRefueling", false )
|
|
186
|
+
jtff_log.info(string.format("[%s] just finsihed refueling at the tanker [%s], taken %.0f Lbs",client:GetPlayer() , tankerUnitName, UTILS.kg2lbs(clientFuelTaken)),"TANKER")
|
|
187
|
+
if (type(dcsbot) ~= 'nil') then
|
|
188
|
+
local title = string.format('End of Air refuel !')
|
|
189
|
+
local description = string.format("[%s] just finsihed refueling at the tanker [%s], taken %.0f Lbs",client:GetPlayer() , tankerUnitName, UTILS.kg2lbs(clientFuelTaken))
|
|
190
|
+
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'
|
|
191
|
+
local fields = {
|
|
192
|
+
['Pilot'] = client:GetPlayer(),
|
|
193
|
+
['Tanker'] = tankerUnitName,
|
|
194
|
+
['RefuelQty'] = string.format("%.0f Lbs", UTILS.kg2lbs(clientFuelTaken))
|
|
195
|
+
}
|
|
196
|
+
local footer = 'Sorry, tomcats took it all again...'
|
|
197
|
+
dcsbot.sendEmbed(title, description, img, fields, footer)
|
|
198
|
+
end
|
|
98
199
|
end
|
|
99
200
|
end
|
|
100
201
|
end
|