Skip to content

Commit 6a8dfa8

Browse files
committed
Update v2.6.5
1 parent 6d76db3 commit 6a8dfa8

File tree

6 files changed

+100
-49
lines changed

6 files changed

+100
-49
lines changed

client/functions/player.lua

+12-3
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,22 @@ local GetPlayerDeath = function()
4646
return isDead
4747
end
4848

49+
setmetatable(Player, {
50+
__index = function(self, key)
51+
if key == 'coords' then
52+
return GetEntityCoords(self.ped)
53+
elseif key == 'heading' then
54+
return GetEntityHeading(self.ped)
55+
elseif key == 'state' then
56+
return PlayerState(self.serverId).state
57+
end
58+
end
59+
})
60+
4961
CreateThread(function()
5062
while true do
5163
Player:set('ped', PlayerPedId())
5264
Player:set('playerPed', Player.ped)
53-
Player:set('coords', GetEntityCoords(Player.ped))
54-
Player:set('heading', GetEntityHeading(Player.ped))
55-
Player:set('state', PlayerState(Player.serverId).state)
5665

5766
local vehicle = GetVehiclePedIsIn(Player.ped, false)
5867

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.6.4'
7+
version '2.6.5'
88

99
lua54 'yes'
1010

import.lua

+45-23
Original file line numberDiff line numberDiff line change
@@ -30,46 +30,40 @@ MSK = exports.msk_core:GetLib()
3030
----------------------------------------------------------------
3131
-- MSK.Input(header, placeholder, field, cb)
3232
setmetatable(MSK.Input, {
33-
__call = function(self, header, placeholder, field, cb)
34-
self.Open(header, placeholder, field, cb)
33+
__call = function(self, ...)
34+
self.Open(...)
3535
end
3636
})
3737

3838
-- MSK.Numpad(pin, showPin, cb)
3939
setmetatable(MSK.Numpad, {
40-
__call = function(self, pin, showPin, cb)
41-
self.Open(pin, showPin, cb)
40+
__call = function(self, ...)
41+
self.Open(...)
4242
end
4343
})
4444

4545
-- MSK.Progress(data)
4646
setmetatable(MSK.Progress, {
47-
__call = function(self, data, text, color)
48-
self.Start(data, text, color)
47+
__call = function(self, ...)
48+
self.Start(...)
4949
end
5050
})
5151

5252
----------------------------------------------------------------
5353
-- MSK.Player
5454
----------------------------------------------------------------
5555
if context == 'client' then
56-
local Player = {
57-
clientId = MSK.Player.clientId,
58-
serverId = MSK.Player.serverId,
59-
playerId = MSK.Player.playerId,
60-
state = Player(MSK.Player.serverId).state,
61-
ped = MSK.Player.ped,
62-
playerPed = MSK.Player.ped,
63-
coords = MSK.Player.coords,
64-
heading = MSK.Player.heading,
65-
vehicle = MSK.Player.vehicle,
66-
seat = MSK.Player.seat,
67-
weapon = MSK.Player.weapon,
68-
isDead = MSK.Player.isDead,
69-
Notify = MSK.Player.Notify,
70-
}
71-
72-
MSK.Player = Player
56+
setmetatable(MSK.Player, {
57+
__index = function(self, key)
58+
if key == 'coords' then
59+
return GetEntityCoords(self.ped)
60+
elseif key == 'heading' then
61+
return GetEntityHeading(self.ped)
62+
elseif key == 'state' then
63+
return PlayerState(self.serverId).state
64+
end
65+
end
66+
})
7367

7468
AddEventHandler('msk_core:onPlayer', function(key, value, oldValue)
7569
MSK.Player[key] = value
@@ -81,9 +75,31 @@ if context == 'client' then
8175
end
8276

8377
if context == 'server' then
78+
local metatable = {
79+
__index = function(self, key)
80+
if type(key) == "string" then
81+
return rawget(self, tonumber(key))
82+
end
83+
end
84+
}
85+
setmetatable(MSK.Player, metatable)
86+
87+
local playerMeta = {
88+
__index = function(self, key)
89+
if key == 'coords' then
90+
return GetEntityCoords(self.ped)
91+
elseif key == 'heading' then
92+
return GetEntityHeading(self.ped)
93+
elseif key == 'state' then
94+
return PlayerState(self.serverId).state
95+
end
96+
end
97+
}
98+
8499
AddEventHandler('msk_core:OnPlayer', function(playerId, key, value, oldValue)
85100
if not MSK.Player[playerId] then
86101
MSK.Player[playerId] = {}
102+
setmetatable(MSK.Player[playerId], playerMeta)
87103
end
88104

89105
MSK.Player[playerId][key] = value
@@ -93,4 +109,10 @@ if context == 'server' then
93109
if not MSK.Player[playerId] then return end
94110
MSK.Player[playerId][key] = nil
95111
end)
112+
113+
for playerId, data in pairs(MSK.Player) do
114+
if not getmetatable(MSK.Player[playerId]) then
115+
setmetatable(MSK.Player[playerId], playerMeta)
116+
end
117+
end
96118
end

server/functions/commands.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ MSK.RegisterCommand = function(commandName, callback, properties, ...)
139139
if restricted then
140140
local ace = ('command.%s'):format(commandName)
141141

142-
if type(restricted) == 'string' and not MSK.IsPrincipalAceAllowed(restricted, ace) then
142+
if type(restricted) == 'string' and not MSK.IsPrincipalAceAllowed(('group.%s'):format(restricted), ace) then
143143
MSK.AddAce(restricted, ace)
144144
elseif type(restricted) == 'table' then
145145
for i = 1, #restricted do
146146
local res = restricted[i]
147147

148-
if not MSK.IsPrincipalAceAllowed(res, ace) then
148+
if not MSK.IsPrincipalAceAllowed(('group.%s'):format(res), ace) then
149149
MSK.AddAce(res, ace)
150150
end
151151
end

server/functions/player.lua

+34-14
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,41 @@
1+
local PlayerState = Player
12
local Player = {}
23

4+
local metatable = {
5+
__index = function(self, key)
6+
if type(key) == "string" then
7+
return rawget(self, tonumber(key))
8+
end
9+
end
10+
}
11+
setmetatable(Player, metatable)
12+
13+
local playerMeta = {
14+
__index = function(self, key)
15+
if key == 'coords' then
16+
return GetEntityCoords(self.ped)
17+
elseif key == 'heading' then
18+
return GetEntityHeading(self.ped)
19+
elseif key == 'state' then
20+
return PlayerState(self.serverId).state
21+
end
22+
end
23+
}
24+
325
local onPlayer = function(key, value, oldValue)
4-
local playerId = source
26+
local playerId = tonumber(source)
527

628
if not Player[playerId] then
729
Player[playerId] = {}
30+
setmetatable(Player[playerId], playerMeta)
831
end
932

1033
if Player[playerId][key] ~= value then
1134
Player[playerId][key] = value
1235

13-
if key == 'vehicle' then
36+
if key == 'ped' or key == 'playerPed' then
37+
Player[playerId][key] = GetPlayerPed(playerId)
38+
elseif key == 'vehicle' then
1439
Player[playerId][key] = NetworkGetEntityFromNetworkId(value)
1540
Player[playerId]['vehNetId'] = value
1641
end
@@ -21,21 +46,16 @@ end
2146
RegisterNetEvent('msk_core:onPlayer', onPlayer)
2247

2348
local onPlayerRemove = function(key, value)
24-
local playerId = source
25-
26-
if not Player[playerId] then
27-
Player[playerId] = {}
28-
end
49+
local playerId = tonumber(source)
50+
if not Player[playerId] then return end
2951

30-
if Player[playerId][key] then
31-
Player[playerId][key] = nil
52+
Player[playerId][key] = nil
3253

33-
if key == 'vehicle' then
34-
Player[playerId]['vehNetId'] = nil
35-
end
36-
37-
TriggerEvent('msk_core:OnPlayerRemove', playerId, key, value)
54+
if key == 'vehicle' then
55+
Player[playerId]['vehNetId'] = nil
3856
end
57+
58+
TriggerEvent('msk_core:OnPlayerRemove', playerId, key, value)
3959
end
4060
RegisterNetEvent('msk_core:onPlayerRemove', onPlayerRemove)
4161

server/functions/ui.lua

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ exports('Input', MSK.Input.Open)
1313
exports('OpenInput', MSK.Input.Open)
1414

1515
setmetatable(MSK.Input, {
16-
__call = function(self, header, placeholder, field, cb)
17-
self.Open(header, placeholder, field, cb)
16+
__call = function(self, ...)
17+
self.Open(...)
1818
end
1919
})
2020

@@ -35,8 +35,8 @@ end
3535
exports('Numpad', MSK.Numpad.Open)
3636

3737
setmetatable(MSK.Numpad, {
38-
__call = function(self, pin, showPin, cb)
39-
self.Open(pin, showPin, cb)
38+
__call = function(self, ...)
39+
self.Open(...)
4040
end
4141
})
4242

@@ -57,8 +57,8 @@ MSK.Progressbar = MSK.Progress.Start
5757
exports('Progressbar', MSK.Progress.Start)
5858

5959
setmetatable(MSK.Progress, {
60-
__call = function(self, data, text, color)
61-
self.Start(data, text, color)
60+
__call = function(self, ...)
61+
self.Start(...)
6262
end
6363
})
6464

0 commit comments

Comments
 (0)