Skip to content

Commit

Permalink
Update v2.6.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Musiker15 committed Oct 19, 2024
1 parent 6d76db3 commit 6a8dfa8
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 49 deletions.
15 changes: 12 additions & 3 deletions client/functions/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,22 @@ local GetPlayerDeath = function()
return isDead
end

setmetatable(Player, {
__index = function(self, key)
if key == 'coords' then
return GetEntityCoords(self.ped)
elseif key == 'heading' then
return GetEntityHeading(self.ped)
elseif key == 'state' then
return PlayerState(self.serverId).state
end
end
})

CreateThread(function()
while true do
Player:set('ped', PlayerPedId())
Player:set('playerPed', Player.ped)
Player:set('coords', GetEntityCoords(Player.ped))
Player:set('heading', GetEntityHeading(Player.ped))
Player:set('state', PlayerState(Player.serverId).state)

local vehicle = GetVehiclePedIsIn(Player.ped, false)

Expand Down
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ games { 'gta5' }
author 'Musiker15 - MSK Scripts'
name 'msk_core'
description 'Functions for MSK Scripts'
version '2.6.4'
version '2.6.5'

lua54 'yes'

Expand Down
68 changes: 45 additions & 23 deletions import.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,46 +30,40 @@ MSK = exports.msk_core:GetLib()
----------------------------------------------------------------
-- MSK.Input(header, placeholder, field, cb)
setmetatable(MSK.Input, {
__call = function(self, header, placeholder, field, cb)
self.Open(header, placeholder, field, cb)
__call = function(self, ...)
self.Open(...)
end
})

-- MSK.Numpad(pin, showPin, cb)
setmetatable(MSK.Numpad, {
__call = function(self, pin, showPin, cb)
self.Open(pin, showPin, cb)
__call = function(self, ...)
self.Open(...)
end
})

-- MSK.Progress(data)
setmetatable(MSK.Progress, {
__call = function(self, data, text, color)
self.Start(data, text, color)
__call = function(self, ...)
self.Start(...)
end
})

----------------------------------------------------------------
-- MSK.Player
----------------------------------------------------------------
if context == 'client' then
local Player = {
clientId = MSK.Player.clientId,
serverId = MSK.Player.serverId,
playerId = MSK.Player.playerId,
state = Player(MSK.Player.serverId).state,
ped = MSK.Player.ped,
playerPed = MSK.Player.ped,
coords = MSK.Player.coords,
heading = MSK.Player.heading,
vehicle = MSK.Player.vehicle,
seat = MSK.Player.seat,
weapon = MSK.Player.weapon,
isDead = MSK.Player.isDead,
Notify = MSK.Player.Notify,
}

MSK.Player = Player
setmetatable(MSK.Player, {
__index = function(self, key)
if key == 'coords' then
return GetEntityCoords(self.ped)
elseif key == 'heading' then
return GetEntityHeading(self.ped)
elseif key == 'state' then
return PlayerState(self.serverId).state
end
end
})

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

if context == 'server' then
local metatable = {
__index = function(self, key)
if type(key) == "string" then
return rawget(self, tonumber(key))
end
end
}
setmetatable(MSK.Player, metatable)

local playerMeta = {
__index = function(self, key)
if key == 'coords' then
return GetEntityCoords(self.ped)
elseif key == 'heading' then
return GetEntityHeading(self.ped)
elseif key == 'state' then
return PlayerState(self.serverId).state
end
end
}

AddEventHandler('msk_core:OnPlayer', function(playerId, key, value, oldValue)
if not MSK.Player[playerId] then
MSK.Player[playerId] = {}
setmetatable(MSK.Player[playerId], playerMeta)
end

MSK.Player[playerId][key] = value
Expand All @@ -93,4 +109,10 @@ if context == 'server' then
if not MSK.Player[playerId] then return end
MSK.Player[playerId][key] = nil
end)

for playerId, data in pairs(MSK.Player) do
if not getmetatable(MSK.Player[playerId]) then
setmetatable(MSK.Player[playerId], playerMeta)
end
end
end
4 changes: 2 additions & 2 deletions server/functions/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ MSK.RegisterCommand = function(commandName, callback, properties, ...)
if restricted then
local ace = ('command.%s'):format(commandName)

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

if not MSK.IsPrincipalAceAllowed(res, ace) then
if not MSK.IsPrincipalAceAllowed(('group.%s'):format(res), ace) then
MSK.AddAce(res, ace)
end
end
Expand Down
48 changes: 34 additions & 14 deletions server/functions/player.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
local PlayerState = Player
local Player = {}

local metatable = {
__index = function(self, key)
if type(key) == "string" then
return rawget(self, tonumber(key))
end
end
}
setmetatable(Player, metatable)

local playerMeta = {
__index = function(self, key)
if key == 'coords' then
return GetEntityCoords(self.ped)
elseif key == 'heading' then
return GetEntityHeading(self.ped)
elseif key == 'state' then
return PlayerState(self.serverId).state
end
end
}

local onPlayer = function(key, value, oldValue)
local playerId = source
local playerId = tonumber(source)

if not Player[playerId] then
Player[playerId] = {}
setmetatable(Player[playerId], playerMeta)
end

if Player[playerId][key] ~= value then
Player[playerId][key] = value

if key == 'vehicle' then
if key == 'ped' or key == 'playerPed' then
Player[playerId][key] = GetPlayerPed(playerId)
elseif key == 'vehicle' then
Player[playerId][key] = NetworkGetEntityFromNetworkId(value)
Player[playerId]['vehNetId'] = value
end
Expand All @@ -21,21 +46,16 @@ end
RegisterNetEvent('msk_core:onPlayer', onPlayer)

local onPlayerRemove = function(key, value)
local playerId = source

if not Player[playerId] then
Player[playerId] = {}
end
local playerId = tonumber(source)
if not Player[playerId] then return end

if Player[playerId][key] then
Player[playerId][key] = nil
Player[playerId][key] = nil

if key == 'vehicle' then
Player[playerId]['vehNetId'] = nil
end

TriggerEvent('msk_core:OnPlayerRemove', playerId, key, value)
if key == 'vehicle' then
Player[playerId]['vehNetId'] = nil
end

TriggerEvent('msk_core:OnPlayerRemove', playerId, key, value)
end
RegisterNetEvent('msk_core:onPlayerRemove', onPlayerRemove)

Expand Down
12 changes: 6 additions & 6 deletions server/functions/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ exports('Input', MSK.Input.Open)
exports('OpenInput', MSK.Input.Open)

setmetatable(MSK.Input, {
__call = function(self, header, placeholder, field, cb)
self.Open(header, placeholder, field, cb)
__call = function(self, ...)
self.Open(...)
end
})

Expand All @@ -35,8 +35,8 @@ end
exports('Numpad', MSK.Numpad.Open)

setmetatable(MSK.Numpad, {
__call = function(self, pin, showPin, cb)
self.Open(pin, showPin, cb)
__call = function(self, ...)
self.Open(...)
end
})

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

setmetatable(MSK.Progress, {
__call = function(self, data, text, color)
self.Start(data, text, color)
__call = function(self, ...)
self.Start(...)
end
})

Expand Down

0 comments on commit 6a8dfa8

Please sign in to comment.