Skip to content

Commit 4dfb1d5

Browse files
committed
Update v2.6.0
1 parent 3e3300c commit 4dfb1d5

File tree

12 files changed

+347
-213
lines changed

12 files changed

+347
-213
lines changed

client/functions/main.lua

+13-1
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,16 @@ exports('GetClosestPlayer', MSK.GetClosestPlayer)
201201
MSK.GetClosestPlayers = function(coords, distance)
202202
return GetClosestEntities(true, coords, distance)
203203
end
204-
exports('GetClosestPlayers', MSK.GetClosestPlayers)
204+
exports('GetClosestPlayers', MSK.GetClosestPlayers)
205+
206+
MSK.IsAceAllowed = function(command)
207+
return MSK.Trigger('msk_core:isAceAllowed', ('command.%s'):format(command))
208+
end
209+
210+
MSK.RegisterCommand = function(command, cb, restricted)
211+
RegisterCommand(command, function(source, args, raw)
212+
if not restricted or MSK.IsAceAllowed(command) then
213+
cb(source, args, raw)
214+
end
215+
end)
216+
end

client/functions/player.lua

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local Player = {}
33
function Player:set(key, value)
44
if self[key] ~= value then
55
TriggerEvent('msk_core:onPlayer', key, value, self[key])
6+
TriggerServerEvent('msk_core:onPlayer', key, key == 'vehicle' and DoesEntityExist(value) and NetworkGetNetworkIdFromEntity(value) or value, key == 'vehicle' and DoesEntityExist(self[key]) and NetworkGetNetworkIdFromEntity(self[key]) or self[key])
67
self[key] = value
78

89
return true
@@ -12,6 +13,7 @@ end
1213
function Player:remove(key)
1314
if self[key] then
1415
TriggerEvent('msk_core:onPlayerRemove', key, self[key])
16+
TriggerServerEvent('msk_core:onPlayerRemove', key, key == 'vehicle' and DoesEntityExist(self[key]) and NetworkGetNetworkIdFromEntity(self[key]) or self[key])
1517
self[key] = nil
1618

1719
return true

client/main.lua

-14
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,6 @@ elseif MSK.Bridge.Framework.Type == 'QBCore' then
8484
end)
8585
end
8686

87-
if Config.BanSystem.enable and Config.BanSystem.commands.enable then
88-
CreateThread(function()
89-
TriggerEvent('chat:addSuggestion', '/' .. Config.BanSystem.commands.ban, 'Ban a Player', {
90-
{name = "targetId", help = "ServerId"},
91-
{name = "time", help = "1M = 1 Minute / 1H = 1 Hour / 1D = 1 Day / 1W = 1 Week / P = Permanent"},
92-
{name = "reason", help = "Reason"},
93-
})
94-
95-
TriggerEvent('chat:addSuggestion', '/' .. Config.BanSystem.commands.unban, 'Unban a Player', {
96-
{name = "banId", help = "BanId"}
97-
})
98-
end)
99-
end
100-
10187
local GetLib = function()
10288
return MSK
10389
end

fxmanifest.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ games { 'gta5' }
44
author 'Musiker15 - MSK Scripts'
55
name 'msk_core'
66
description 'Functions for MSK Scripts'
7-
version '2.5.1'
7+
version '2.6.0'
88

99
lua54 'yes'
1010

import.lua

+15
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,19 @@ if context == 'client' then
7676
AddEventHandler('msk_core:onPlayerRemove', function(key, value)
7777
MSK.Player[key] = nil
7878
end)
79+
end
80+
81+
if context == 'server' then
82+
AddEventHandler('msk_core:OnPlayer', function(playerId, key, value, oldValue)
83+
if not MSK.Player[playerId] then
84+
MSK.Player[playerId] = {}
85+
end
86+
87+
MSK.Player[playerId][key] = value
88+
end)
89+
90+
AddEventHandler('msk_core:OnPlayerRemove', function(playerId, key, value)
91+
if not MSK.Player[playerId] then return end
92+
MSK.Player[playerId][key] = nil
93+
end)
7994
end

server/functions/ace.lua

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
MSK.IsAceAllowed = function(playerId, command)
2+
return IsPlayerAceAllowed(playerId, ('command.%s'):format(command))
3+
end
4+
exports('IsAceAllowed', IsAceAllowed)
5+
6+
local allowAce = function(allow)
7+
return allow == false and 'deny' or 'allow'
8+
end
9+
10+
MSK.AddAce = function(principal, ace, allow)
11+
if type(principal) == 'string' then
12+
principal = 'group.' .. principal
13+
elseif type(principal) == 'number' then
14+
principal = 'player.' .. principal
15+
end
16+
17+
ExecuteCommand(('add_ace %s %s %s'):format(principal, ace, allowAce(allow)))
18+
end
19+
exports('AddAce', MSK.AddAce)
20+
21+
MSK.RemoveAce = function(principal, ace, allow)
22+
if type(principal) == 'string' then
23+
principal = 'group.' .. principal
24+
elseif type(principal) == 'number' then
25+
principal = 'player.' .. principal
26+
end
27+
28+
ExecuteCommand(('remove_ace %s %s %s'):format(principal, ace, allowAce(allow)))
29+
end
30+
exports('RemoveAce', MSK.RemoveAce)
31+
32+
MSK.AddPrincipal = function(child, parent)
33+
if type(principal) == 'number' then
34+
principal = 'player.' .. principal
35+
end
36+
37+
ExecuteCommand(('add_principal %s %s'):format(child, parent))
38+
end
39+
exports('AddPrincipal', MSK.AddPrincipal)
40+
41+
MSK.RemovePrincipal = function(child, parent)
42+
if type(principal) == 'number' then
43+
principal = 'player.' .. principal
44+
end
45+
46+
ExecuteCommand(('remove_principal %s %s'):format(child, parent))
47+
end
48+
exports('RemovePrincipal', MSK.RemovePrincipal)

server/functions/bansystem.lua

+30-46
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ local formatTime = function(time)
7474
if time:find('P') then
7575
banTime = os.time() + (60 * 60 * 24 * 7 * 52 * 100)
7676
elseif time:find('M') then
77-
banTime = os.time() + (60 * MSK.Split(time, 'M')[1])
77+
banTime = os.time() + (60 * MSK.String.Split(time, 'M')[1])
7878
elseif time:find('H') then
79-
banTime = os.time() + (60 * 60 * MSK.Split(time, 'H')[1])
79+
banTime = os.time() + (60 * 60 * MSK.String.Split(time, 'H')[1])
8080
elseif time:find('D') then
81-
banTime = os.time() + (60 * 60 * 24 * MSK.Split(time, 'D')[1])
81+
banTime = os.time() + (60 * 60 * 24 * MSK.String.Split(time, 'D')[1])
8282
elseif time:find('W') then
83-
banTime = os.time() + (60 * 60 * 24 * 7 * MSK.Split(time, 'W')[1])
83+
banTime = os.time() + (60 * 60 * 24 * 7 * MSK.String.Split(time, 'W')[1])
8484
end
8585

8686
return banTime, os.date('%d-%m-%Y %H:%M', banTime)
@@ -230,50 +230,34 @@ exports('UnbanPlayer', MSK.UnbanPlayer)
230230
exports('unbanPlayer', MSK.UnbanPlayer) -- Support for old Scripts
231231

232232
if Config.BanSystem.enable and Config.BanSystem.commands.enable then
233-
for i = 1, #Config.BanSystem.commands.groups do
234-
local group = Config.BanSystem.commands.groups[i]
235-
ExecuteCommand(('add_ace group.%s command.%s allow'):format(group, Config.BanSystem.commands.ban))
236-
ExecuteCommand(('add_ace group.%s command.%s allow'):format(group, Config.BanSystem.commands.unban))
237-
end
238-
239-
local IsPlayerAllowed = function(playerId, command)
240-
return IsPlayerAceAllowed(playerId, ('command.%s'):format(command))
241-
end
242-
243-
RegisterCommand(Config.BanSystem.commands.ban, function(source, args, raw)
233+
MSK.RegisterCommand(Config.BanSystem.commands.ban, function(source, args, raw)
244234
local playerId = source
245-
local targetId, time, reason = args[1], args[2], args[3]
246-
247-
if not targetId or not time then return end
248-
if not reason then reason = 'Unknown' end
235+
local targetId, time, reason = args.playerId, args.time, args.reason,
249236

250-
if playerId == 0 then
251-
MSK.BanPlayer(nil, targetId, time, reason)
252-
return
237+
if not reason then
238+
reason = 'Unknown reason'
253239
end
254240

255-
if IsPlayerAllowed(playerId, Config.BanSystem.commands.ban) then
256-
MSK.BanPlayer(playerId, targetId, time, reason)
257-
else
258-
MSK.Notification(playerId, 'MSK Bansystem', 'You don\'t have permission to do that!')
259-
end
260-
end)
261-
262-
RegisterCommand(Config.BanSystem.commands.unban, function(source, args, raw)
263-
local playerId = source
264-
local banId = args[1]
265-
266-
if not banId then return end
267-
268-
if playerId == 0 then
269-
MSK.UnbanPlayer(nil, banId)
270-
return
271-
end
272-
273-
if IsPlayerAllowed(playerId, Config.BanSystem.commands.unban) then
274-
MSK.UnbanPlayer(playerId, banId)
275-
else
276-
MSK.Notification(playerId, 'MSK Bansystem', 'You don\'t have permission to do that!')
277-
end
278-
end)
241+
MSK.BanPlayer(playerId, targetId, time, reason)
242+
end, {
243+
allowConsole = true,
244+
restricted = Config.BanSystem.commands.groups,
245+
help = 'Ban a Player',
246+
params = {
247+
{name = "playerId", type = 'playerId', help = "Target players server id"},
248+
{name = "time", type = 'string', help = "1M = 1 Minute / 1H = 1 Hour / 1D = 1 Day / 1W = 1 Week / P = Permanent"},
249+
{name = "reason", type = 'string', help = "Ban Reason", optional = true},
250+
}
251+
})
252+
253+
MSK.RegisterCommand(Config.BanSystem.commands.unban, function(source, args, raw)
254+
MSK.UnbanPlayer(source, args.banId)
255+
end, {
256+
allowConsole = true,
257+
restricted = Config.BanSystem.commands.groups,
258+
help = 'Unban a Player',
259+
params = {
260+
{name = 'banId', type = 'number', help = 'Banned players BanId'}
261+
}
262+
})
279263
end

server/functions/callbacks.lua

+2-3
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,8 @@ end)
8585
----------------------------------------------------------------
8686
-- Server Callbacks with Method [return]
8787
----------------------------------------------------------------
88-
MSK.Register('msk_core:hasItem', function(source, item)
89-
return MSK.HasItem(source, item)
90-
end)
88+
MSK.Register('msk_core:hasItem', MSK.HasItem)
89+
MSK.Register('msk_core:isAceAllowed', MSK.IsAceAllowed)
9190

9291
----------------------------------------------------------------
9392
-- Server Callbacks with Method [cb]

0 commit comments

Comments
 (0)