forked from AlterGamingNetwork/mellotrainer
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcl_admin.lua
383 lines (307 loc) · 9.65 KB
/
cl_admin.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
--[[--------------------------------------------------------------------------
*
* Mello Trainer
* (C) Michael Goodwin 2017
* http://github.com/thestonedturtle/mellotrainer/releases
*
* This menu used the Scorpion Trainer as a framework to build off of.
* https://github.com/pongo1231/ScorpionTrainer
* (C) Emre Cürgül 2017
*
* A lot of useful functionality has been converted from the lambda menu.
* https://lambda.menu
* (C) Oui 2017
*
* Additional Contributors:
* WolfKnight (https://forum.fivem.net/u/WolfKnight)
*
---------------------------------------------------------------------------]]
--[[------------------------------------------------------------------------
Player Management
------------------------------------------------------------------------]]--
function GetNetworkPlayers()
local players = {}
for i = 0, 31 do
if ( NetworkIsPlayerConnected( i ) ) then
table.insert( players, i )
end
end
if ( next( players ) == nil ) then return nil else return players end
end
--[[ function GeneratePlayerBans( id )
local bans = { 0.016667, 0.085, 0.17, 0.25, 0.5, 1, 2, 3, 4, 5, 8, 10, 15, 20, 30, 40, 60, 120, 240, 480 }
local options = {}
for k, v in pairs( bans ) do
local option = {
[ "menuName" ] = tostring( v ) .. " hours",
[ "data" ] = {
[ "action" ] = "adminban " .. id .. " " .. v
}
}
table.insert( options, option )
end
return options
end ]]--
function GeneratePlayerAdminMenus( id )
local serverid = GetPlayerServerId( id )
local kick = {
[ "menuName" ] = "Kick",
[ "data" ] = {
[ "action" ] = "adminkick " .. serverid
}
}
local kick_reason = {
[ "menuName" ] = "Kick (specify reason)",
[ "data" ] = {
[ "action" ] = "adminkick input " .. serverid
}
}
local temp_ban = {
[ "menuName" ] = "Temp Ban",
[ "data" ] = {
[ "action" ] = "admintempban " .. serverid
}
}
--[[ local banOptions = GeneratePlayerBans( serverid )
local ban = {
[ "menuName" ] = "Ban",
[ "data" ] = {
[ "sub" ] = 3
},
[ "submenu" ] = banOptions
} ]]--
local kill = {
[ "menuName" ] = "Kill player",
[ "data" ] = {
[ "action" ] = "adminkill " .. serverid
}
}
local teleport = {
[ "menuName" ] = "Teleport to me",
[ "data" ] = {
[ "action" ] = "admintp " .. serverid
}
}
local options = { kick, kick_reason, temp_ban, teleport, kill }
return options
end
RegisterNUICallback( "playermanagement", function( data, cb )
local players = GetNetworkPlayers()
local validOptions = {}
for k, v in pairs( players ) do
local playerOptions = GeneratePlayerAdminMenus( v )
table.insert( validOptions, {
[ "menuName" ] = GetPlayerName( v ),
[ "data" ] = {
[ "sub" ] = GetPlayerServerId( v )
},
[ "submenu" ] = playerOptions
} )
end
local customJSON = "{}"
if ( getTableLength( validOptions ) > 0 ) then
customJSON = json.encode( validOptions, { indent = true } )
end
SendNUIMessage( {
createmenu = true,
refreshmenu = true,
menuName = "playermanagement",
menudata = customJSON
} )
if ( cb ) then cb( "ok" ) end
end )
RegisterNUICallback( "adminkick", function( data, cb )
if ( data.action == "input" ) then
local id = tonumber( data.data[3] )
local reason = requestInput( "", 60 )
if ( reason ) then
TriggerServerEvent( 'mellotrainer:adminKick', id, "Kicked: " .. reason )
end
else
local id = tonumber( data.action )
TriggerServerEvent( 'mellotrainer:adminKick', id, "Kicked: You have been kicked from the server." )
end
end )
RegisterNUICallback( "admintempban", function( data, cb )
local id = tonumber( data.action )
TriggerServerEvent( 'mellotrainer:adminTempBan', id )
end )
RegisterNUICallback( "adminkill", function( data, cb )
local id = tonumber( data.action )
TriggerServerEvent( 'mellotrainer:s_adminKill', id )
end )
RegisterNetEvent( 'mellotrainer:adminKill' )
AddEventHandler( 'mellotrainer:adminKill', function( data, cb )
local ped = GetPlayerPed( -1 )
if ( DoesEntityExist( ped ) and not IsEntityDead( ped ) ) then
SetEntityHealth( ped, 0 )
end
end )
RegisterNUICallback( "admintp", function( data, cb )
local id = tonumber( data.action )
TriggerServerEvent( 'mellotrainer:s_adminTp', id )
end )
RegisterNetEvent( 'mellotrainer:adminTp' )
AddEventHandler( 'mellotrainer:adminTp', function( adminSource )
local me = GetPlayerPed( -1 )
local target = GetPlayerFromServerId( adminSource )
local targetPed = GetPlayerPed( target )
local coords = GetEntityCoords( targetPed, true )
local x, y, z = coords.x, coords.y, coords.z
z = z + 3.5
RequestCollisionAtCoord( x, y, z )
SetEntityCoordsNoOffset( me, x, y, z, false, false, true )
end )
-- _______ _ ____ _ _
-- |__ __(_) / __ \ | | (_)
-- | | _ _ __ ___ ___ | | | |_ __ | |_ _ ___ _ __ ___
-- | | | | '_ ` _ \ / _ \ | | | | '_ \| __| |/ _ \| '_ \/ __|
-- | | | | | | | | | __/ | |__| | |_) | |_| | (_) | | | \__ \
-- |_| |_|_| |_| |_|\___| \____/| .__/ \__|_|\___/|_| |_|___/
-- | |
-- |_|
-- Forward one hour
function getForwardTime()
local hour = GetClockHours() + 1
if(hour == 24)then
hour = 0
end
return {h=hour,m=GetClockMinutes(),s=GetClockSeconds()}
end
-- Back one hour
function getReverseTime()
local hour = GetClockHours() - 1
if(hour < 0)then
hour = 23
end
return {h=hour,m=GetClockMinutes(),s=GetClockSeconds()}
end
-- Update time
RegisterNetEvent('mellotrainer:updateTime')
AddEventHandler('mellotrainer:updateTime', function(h,m,s)
--Citizen.Trace("Time Updated")
NetworkOverrideClockTime(h,m,s)
end)
RegisterNUICallback("time", function(data, cb)
local h,m,s
local action = data.action
if (action == "input") then
local request = tonumber(requestInput("", 2))
if (request == nil) or (request > 24) or (request < 0) then
drawNotification("~r~You must specify a number from 0-24.")
return
else
h=request
m=0
s=0
end
elseif(action == "forwards")then
local time = getForwardTime()
h=time.h
m=time.m
s=time.s
elseif(action == "backwards")then
local time = getReverseTime()
h=time.h
m=time.m
s=time.s
else
h=tonumber(data.action) or 0
m=0
s=0
end
TriggerServerEvent("mellotrainer:adminTime", PlayerId(), h,m,s)
drawNotification("~g~Time changed to "..tostring(h)..":"..string.format("%02d", tostring(m)))
end)
-- __ __ _ _ ____ _ _
-- \ \ / / | | | | / __ \ | | (_)
-- \ \ /\ / /__ __ _| |_| |__ ___ _ __ | | | |_ __ | |_ _ ___ _ __ ___
-- \ \/ \/ / _ \/ _` | __| '_ \ / _ \ '__| | | | | '_ \| __| |/ _ \| '_ \/ __|
-- \ /\ / __/ (_| | |_| | | | __/ | | |__| | |_) | |_| | (_) | | | \__ \
-- \/ \/ \___|\__,_|\__|_| |_|\___|_| \____/| .__/ \__|_|\___/|_| |_|___/
-- | |
-- |_|
-- Change Weather Type
function changeWeatherType(type, freezeToggle)
SetOverrideWeather(type)
if(freezeToggle)then
ClearWeatherTypePersist()
SetWeatherTypePersist(type)
end
end
-- Blackout
RegisterNetEvent('mellotrainer:updateBlackout')
AddEventHandler('mellotrainer:updateBlackout', function(toggle)
SetBlackout(toggle)
end)
-- Wind
RegisterNetEvent('mellotrainer:updateWind')
AddEventHandler('mellotrainer:updateWind', function(toggle, heading)
if(toggle) then
SetWind(1.0)
SetWindSpeed(11.99);
SetWindDirection(heading)
else
SetWind(0.0)
SetWindSpeed(0.0);
end
end)
-- Weather
RegisterNetEvent('mellotrainer:updateWeather')
AddEventHandler('mellotrainer:updateWeather', function(weatherString, toggle)
SetOverrideWeather(weatherString)
if(toggle)then
ClearWeatherTypePersist()
SetWeatherTypePersist(weatherString)
end
end)
RegisterNUICallback("weatheroptions", function(data, cb)
local action = data.action
local newstate = data.newstate
-- Notification Toggle Text
local text = "~r~OFF"
if(newstate) then
text = "~g~ON"
end
if(action == "wind")then
featureWeatherWind = newstate
local heading = GetEntityHeading(PlayerPedId())
TriggerServerEvent("mellotrainer:adminWind", PlayerId(), featureWeatherWind, heading)
drawNotification("Wind "..text)
elseif(action == "freeze")then
featureWeatherFreeze = newstate
drawNotification("Persistent Weather "..text.."~w~, Select weather to apply")
elseif(action == "blackout")then
featureBlackout = newstate
TriggerServerEvent("mellotrainer:adminBlackout", PlayerId(), featureBlackout)
drawNotification("Blackout "..text)
end
end)
RegisterNUICallback("weather", function(data, cb)
local weather = data.action
TriggerServerEvent("mellotrainer:adminWeather", PlayerId(), weather, featureWeatherFreeze)
drawNotification("Weather changed to ~g~" .. weather .. ".")
cb("ok")
end)
RegisterNetEvent("mellotrainer:adminstatus")
AddEventHandler("mellotrainer:adminstatus", function(status)
if(status)then
SendNUIMessage({adminaccess = true})
else
drawNotification("~r~You are not an admin!")
end
end)
-- Only show menu if they are an admin
RegisterNUICallback("requireadmin", function(data, cb)
TriggerServerEvent("mellotrainer:isAdmin")
end)
-- Wait until in game to trigger proper join
Citizen.CreateThread(function()
while true do
Citizen.Wait( 0 )
if NetworkIsSessionStarted() then
TriggerEvent( "mellotrainer:init" )
return
end
end
end )