forked from ciribob/DCS-CSAR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsarSlotBlockGameGUI.lua
221 lines (148 loc) · 6.41 KB
/
csarSlotBlockGameGUI.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
local csarSlotBlock = {} -- DONT REMOVE!!!
--[[
CSAR Slot Blocking - V1.9.1
Put this file in C:/Users/<YOUR USERNAME>/DCS/Scripts for 1.5 or C:/Users/<YOUR USERNAME>/DCS.openalpha/Scripts for 2.0
This script will use flags to disable and enable slots when a pilot is shot down and ejects.
The flags will NOT interfere with mission flags
]]
csarSlotBlock.showEnabledMessage = true -- if set to true, the player will be told that the slot is enabled when switching to it
csarSlotBlock.version = "1.9.1"
-- Logic for determining if player is allowed in a slot
function csarSlotBlock.shouldAllowSlot(_playerID, _slotID) -- _slotID == Unit ID unless its multi aircraft in which case slotID is unitId_seatID
if csarSlotBlock.csarSlotBlockEnabled() then
local _unitId = csarSlotBlock.getUnitId(_slotID);
local _mode = csarSlotBlock.csarMode()
if _mode == 1 then
-- disable aircraft for ALL pilots
local _flag = csarSlotBlock.getFlagValue("CSAR_AIRCRAFT".._unitId)
if _flag == 100 then
return false
end
return true
elseif _mode == 2 then
-- disable aircraft for a certain player
local _playerName = net.get_player_info(_playerID, 'name')
if _playerName == nil then
return true
end
local _flag = csarSlotBlock.getFlagValue("CSAR_AIRCRAFT".._playerName:gsub('%W','').."_".._unitId)
if _flag == 100 then
return false
end
return true
elseif _mode == 3 then
-- global lives limit
local _playerName = net.get_player_info(_playerID, 'name')
if _playerName == nil then
return true
end
local _flag = csarSlotBlock.getFlagValue("CSAR_PILOT".._playerName:gsub('%W',''))
if _flag == 1 then
return false
else
return true
end
end
end
return true
end
function csarSlotBlock.getFlagValue(_flag)
local _status,_error = net.dostring_in('server', " return trigger.misc.getUserFlag(\"".._flag.."\"); ")
if not _status and _error then
net.log("error getting flag: ".._error)
return 0
else
-- net.log("flag value ".._unitId.." value: ".._status)
--disabled
return tonumber(_status)
end
end
-- _slotID == Unit ID unless its multi aircraft in which case slotID is unitId_seatID
function csarSlotBlock.getUnitId(_slotID)
local _unitId = tostring(_slotID)
if string.find(tostring(_unitId),"_",1,true) then
--extract substring
_unitId = string.sub(_unitId,1,string.find(_unitId,"_",1,true))
net.log("Unit ID Substr ".._unitId)
end
return tonumber(_unitId)
end
--DOC
-- onGameEvent(eventName,arg1,arg2,arg3,arg4)
--"friendly_fire", playerID, weaponName, victimPlayerID
--"mission_end", winner, msg
--"kill", killerPlayerID, killerUnitType, killerSide, victimPlayerID, victimUnitType, victimSide, weaponName
--"self_kill", playerID
--"change_slot", playerID, slotID, prevSide
--"connect", id, name
--"disconnect", ID_, name, playerSide
--"crash", playerID, unit_missionID
--"eject", playerID, unit_missionID
--"takeoff", playerID, unit_missionID, airdromeName
--"landing", playerID, unit_missionID, airdromeName
--"pilot_death", playerID, unit_missionID
--
csarSlotBlock.onGameEvent = function(eventName,playerID,arg2,arg3,arg4) -- This stops the user flying again after crashing or other events
if DCS.isServer() and DCS.isMultiplayer() then
if DCS.getModelTime() > 1 then -- must check this to prevent a possible CTD by using a_do_script before the game is ready to use a_do_script. -- Source GRIMES :)
if eventName == "self_kill"
or eventName == "crash"
or eventName == "eject"
or eventName == "pilot_death" then
-- is player in a slot and valid?
local _playerDetails = net.get_player_info(playerID)
if _playerDetails ~=nil and _playerDetails.side ~= 0 and _playerDetails.slot ~= "" and _playerDetails.slot ~= nil then
local _allow = csarSlotBlock.shouldAllowSlot(playerID, _playerDetails.slot)
if not _allow then
csarSlotBlock.rejectPlayer(playerID)
end
end
end
end
end
end
csarSlotBlock.onPlayerTryChangeSlot = function(playerID, side, slotID)
if DCS.isServer() and DCS.isMultiplayer() then
if (side ~=0 and slotID ~='' and slotID ~= nil) then
local _allow = csarSlotBlock.shouldAllowSlot(playerID,slotID)
if not _allow then
csarSlotBlock.rejectPlayer(playerID)
return false
else
local _playerName = net.get_player_info(playerID, 'name')
if _playerName ~= nil and csarSlotBlock.showEnabledMessage and
csarSlotBlock.csarSlotBlockEnabled() and csarSlotBlock.csarMode() > 0 then
--Disable chat message to user
local _chatMessage = string.format("*** %s - Aircraft Enabled! If you will need to be rescued by CSAR. Make sure you eject and Protect the Helis! ***",_playerName)
net.send_chat_to(_chatMessage, playerID)
end
end
net.log("CSAR - allowing - playerid: "..playerID.." side:"..side.." slot: "..slotID)
end
end
return true
end
csarSlotBlock.csarSlotBlockEnabled = function()
local _res = csarSlotBlock.getFlagValue("CSAR_SLOTBLOCK")
return _res == 100
end
csarSlotBlock.csarMode = function()
local _mode = csarSlotBlock.getFlagValue("CSAR_MODE")
return _mode
end
csarSlotBlock.rejectPlayer = function(playerID)
net.log("Reject Slot - force spectators - "..playerID)
-- put to spectators
net.force_player_slot(playerID, 0, '')
local _playerName = net.get_player_info(playerID, 'name')
if _playerName ~= nil then
--Disable chat message to user
local _chatMessage = string.format("*** Sorry %s - Slot DISABLED, Pilot has been shot down and needs to be rescued by CSAR ***",_playerName)
net.send_chat_to(_chatMessage, playerID)
end
end
csarSlotBlock.trimStr = function(_str)
return string.format( "%s", _str:match( "^%s*(.-)%s*$" ) )
end
DCS.setUserCallbacks(csarSlotBlock)
net.log("Loaded - CSAR SLOT BLOCK k v"..csarSlotBlock.version.. " by Ciribob")