Skip to content

Commit b929451

Browse files
committed
Update v2.7.2
1 parent 16c289c commit b929451

File tree

13 files changed

+92
-40
lines changed

13 files changed

+92
-40
lines changed

client/functions/callbacks.lua

+1-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ local CallbackHandler = {}
44
local GenerateCallbackHandlerKey = function()
55
local requestId = math.random(1, 999999999)
66

7-
if not CallbackHandler[requestId] then
8-
return tostring(requestId)
9-
else
10-
GenerateCallbackHandlerKey()
11-
end
7+
return not CallbackHandler[requestId] and tostring(requestId) or GenerateCallbackHandlerKey()
128
end
139

1410
RegisterNetEvent("msk_core:client:callbackResponse", function(requestId, ...)

client/functions/player.lua

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
local PlayerState = Player
22
local Player = {}
33

4+
Player.Get = function(playerId, key)
5+
return MSK.Trigger('msk_core:player', playerId, key)
6+
end
7+
48
function Player:set(key, value)
59
if self[key] ~= value then
610
TriggerEvent('msk_core:onPlayer', key, value, self[key])
7-
TriggerServerEvent('msk_core:onPlayer', key, key == 'vehicle' and NetworkGetNetworkIdFromEntity(value) or value, self[key])
11+
TriggerServerEvent('msk_core:onPlayer', key, key == 'vehicle' and DoesEntityExist(value) and NetworkGetNetworkIdFromEntity(value) or value, self[key])
812
self[key] = value
913

1014
return true
@@ -24,27 +28,37 @@ local GetPlayerDeath = function()
2428
local isDead = IsPlayerDead(Player.clientId) or IsEntityDead(Player.ped) or IsPedFatallyInjured(Player.ped)
2529

2630
if GetResourceState("visn_are") == "started" then
27-
local healthBuffer = exports.visn_are:GetHealthBuffer()
31+
local healthBuffer = MSK.Call(function()
32+
return exports.visn_are:GetHealthBuffer()
33+
end)
34+
2835
isDead = healthBuffer.unconscious
2936
end
3037

3138
if GetResourceState("osp_ambulance") == "started" then
32-
local data = exports.osp_ambulance:GetAmbulanceData(Player.serverId)
39+
local data = MSK.Call(function()
40+
return exports.osp_ambulance:GetAmbulanceData(Player.serverId)
41+
end)
42+
3343
isDead = data.isDead or data.inLastStand
3444
end
3545

3646
return isDead
3747
end
3848

3949
setmetatable(Player, {
40-
__index = function(self, key, ...)
50+
__index = function(self, key)
4151
if key == 'coords' then
4252
return GetEntityCoords(self.ped)
4353
elseif key == 'heading' then
4454
return GetEntityHeading(self.ped)
4555
elseif key == 'state' then
4656
return PlayerState(self.serverId).state
4757
end
58+
59+
if tonumber(key) then
60+
return MSK.Trigger('msk_core:player', key)
61+
end
4862
end
4963
})
5064

client/main.lua

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ if Config.Framework == 'AUTO' then
1414
Config.Framework = 'ESX'
1515
elseif GetResourceState('qb-core') ~= 'missing' then
1616
Config.Framework = 'QBCore'
17+
elseif GetResourceState('ox_core') ~= 'missing' then
18+
Config.Framework = 'OXCore'
1719
else
1820
Config.Framework = 'STANDALONE'
1921
MSK.Bridge.Framework.Type = 'STANDALONE'
@@ -30,6 +32,9 @@ elseif Config.Framework == 'QBCore' then
3032
QBCore = exports['qb-core']:GetCoreObject()
3133
MSK.Bridge.Framework.Type = 'QBCore'
3234
MSK.Bridge.Framework.Core = QBCore
35+
elseif Config.Framework == 'OXCore' then
36+
MSK.Bridge.Framework.Type = 'OXCore'
37+
MSK.Bridge.Framework.Core = Ox or Citizen.Trace("^1SCRIPT ERROR: Please add '@ox_core/lib/init.lua' to the fxmanifest.lua^0\n")
3338
end
3439

3540
MSK.Bridge.Inventory = Config.Inventory

fxmanifest.lua

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

99
lua54 'yes'
1010

1111
shared_scripts {
12+
-- '@ox_core/lib/init.lua',
1213
'config.lua'
1314
}
1415

import.lua

+4
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ if context == 'client' then
9494
elseif key == 'state' then
9595
return PlayerState(self.serverId).state
9696
end
97+
98+
if tonumber(key) then
99+
return MSK.Trigger('msk_core:player', key)
100+
end
97101
end
98102
})
99103

server/functions/callbacks.lua

+2-20
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ MSK.Register = function(eventName, cb)
88
Callbacks[eventName] = cb
99
end
1010
MSK.RegisterCallback = MSK.Register -- Backwards compatibility
11+
MSK.RegisterServerCallback = MSK.Register -- Backwards compatibility
1112
exports('Register', MSK.Register)
1213

1314
RegisterNetEvent('msk_core:server:triggerCallback', function(eventName, requestId, cb, ...)
@@ -35,11 +36,7 @@ end)
3536
local GenerateCallbackHandlerKey = function()
3637
local requestId = math.random(1, 999999999)
3738

38-
if not CallbackHandler[requestId] then
39-
return tostring(requestId)
40-
else
41-
GenerateCallbackHandlerKey()
42-
end
39+
return not CallbackHandler[requestId] and tostring(requestId) or GenerateCallbackHandlerKey()
4340
end
4441

4542
MSK.Trigger = function(eventName, playerId, ...)
@@ -63,7 +60,6 @@ MSK.Trigger = function(eventName, playerId, ...)
6360
local result = Citizen.Await(p)
6461
return table.unpack(result)
6562
end
66-
MSK.TriggerCallback = MSK.Trigger -- Backwards compatibility
6763
exports('Trigger', MSK.Trigger)
6864

6965
RegisterNetEvent("msk_core:server:callbackResponse", function(requestId, ...)
@@ -79,10 +75,6 @@ end)
7975
----------------------------------------------------------------
8076
-- Server Callbacks with Method [return]
8177
----------------------------------------------------------------
82-
MSK.Register('msk_core:hasItem', function(source, itemName, metadata)
83-
return MSK.HasItem(source, itemName, metadata)
84-
end)
85-
8678
MSK.Register('msk_core:isAceAllowed', function(source, command)
8779
return MSK.IsAceAllowed(source, command)
8880
end)
@@ -91,16 +83,6 @@ MSK.Register('msk_core:isPrincipalAceAllowed', function(source, principal, ace)
9183
return MSK.IsPrincipalAceAllowed(principal, ace)
9284
end)
9385

94-
-- For clientside MSK.RegisterCommand
95-
MSK.Register('msk_core:doesPlayerExist', function(source, targetId)
96-
return DoesPlayerExist(targetId)
97-
end)
98-
99-
-- For clientside MSK.RegisterCommand
100-
MSK.Register('msk_core:getPlayerData', function(source, targetId)
101-
return MSK.GetPlayer({source = targetId})
102-
end)
103-
10486
----------------------------------------------------------------
10587
-- Server Callbacks with Method [cb]
10688
----------------------------------------------------------------

server/functions/commands.lua

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
local RegisteredCommands = {}
22

3+
-- For clientside MSK.RegisterCommand
4+
MSK.Register('msk_core:doesPlayerExist', function(source, targetId)
5+
return DoesPlayerExist(targetId)
6+
end)
7+
8+
-- For clientside MSK.RegisterCommand
9+
MSK.Register('msk_core:getPlayerData', function(source, targetId)
10+
return MSK.GetPlayer({source = targetId})
11+
end)
12+
313
AddEventHandler('playerJoining', function()
414
local playerId = source
515

server/functions/main.lua

+16-2
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,21 @@ MSK.HasItem = function(playerId, itemName, metadata)
135135
end
136136

137137
local Player = MSK.GetPlayer({source = playerId})
138+
139+
if type(itemName) ~= 'table' then
140+
return Player.HasItem(itemName, metadata)
141+
end
142+
143+
for i = 1, #itemName do
144+
local item = itemName[i]
145+
local hasItem = Player.HasItem(item, metadata)
146+
147+
if hasItem then
148+
return hasItem
149+
end
150+
end
138151

139-
return Player.HasItem(itemName, metadata)
152+
return false
140153
end
141-
exports('HasItem', MSK.HasItem)
154+
exports('HasItem', MSK.HasItem)
155+
MSK.Register('msk_core:hasItem', MSK.HasItem)

server/functions/player.lua

+12-1
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,15 @@ local onPlayer = function(key, value, oldValue)
4949
end
5050
RegisterNetEvent('msk_core:onPlayer', onPlayer)
5151

52-
MSK.Player = Player
52+
MSK.Player = Player
53+
54+
-- For clientside MSK.Player[targetId] and MSK.Player.Get(targetId, key)
55+
MSK.Register('msk_core:player', function(source, targetId, key)
56+
local targetId = tonumber(targetId)
57+
58+
if DoesPlayerExist(targetId) then
59+
return key and MSK.Player[targetId][key] or MSK.Player[targetId]
60+
end
61+
62+
return false
63+
end)

server/main.lua

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ if Config.Framework == 'AUTO' then
1313
Config.Framework = 'ESX'
1414
elseif GetResourceState('qb-core') ~= 'missing' then
1515
Config.Framework = 'QBCore'
16+
elseif GetResourceState('ox_core') ~= 'missing' then
17+
Config.Framework = 'OXCore'
1618
else
1719
Config.Framework = 'STANDALONE'
1820
MSK.Bridge.Framework.Type = 'STANDALONE'
@@ -29,6 +31,9 @@ elseif Config.Framework == 'QBCore' then
2931
QBCore = exports['qb-core']:GetCoreObject()
3032
MSK.Bridge.Framework.Type = 'QBCore'
3133
MSK.Bridge.Framework.Core = QBCore
34+
elseif Config.Framework == 'OXCore' then
35+
MSK.Bridge.Framework.Type = 'OXCore'
36+
MSK.Bridge.Framework.Core = Ox or Citizen.Trace("^1SCRIPT ERROR: Please add '@ox_core/lib/init.lua' to the fxmanifest.lua^0\n")
3237
end
3338

3439
MSK.Bridge.Inventory = Config.Inventory

shared/functions.lua

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ end
66
exports('Config', MSK.GetConfig)
77
exports('GetConfig', MSK.GetConfig)
88

9+
MSK.Call = function(fn, timeout)
10+
return MSK.Timeout.Await(timeout or 1000, function()
11+
local success, result = pcall(fn)
12+
13+
if success then
14+
return result
15+
end
16+
end)
17+
end
18+
919
MSK.Logging = function(code, ...)
1020
assert(code and type(code) == 'string', 'Parameter "code" has to be a string on function MSK.Logging')
1121
print(('[^2%s^0] %s'):format(GetInvokingResource() or 'msk_core', Config.LoggingTypes[code] or Config.LoggingTypes['debug']), ..., '^0')

shared/math.lua

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ local Numbers = {}
33

44
for i = 48, 57 do table.insert(Numbers, string.char(i)) end
55

6-
MSK.Math.Number = function(length)
7-
assert(length, 'Parameter "length" is nil on function MSK.Math.Number')
6+
MSK.Math.Random = function(length)
7+
assert(length, 'Parameter "length" is nil on function MSK.Math.Random')
88
math.randomseed(GetGameTimer())
99

10-
return length > 0 and MSK.Math.Number(length - 1) .. Numbers[math.random(1, #Numbers)] or ''
10+
return length > 0 and MSK.Math.Random(length - 1) .. Numbers[math.random(1, #Numbers)] or ''
1111
end
12-
MSK.GetRandomNumber = MSK.Math.Number -- Backwards compatibility
13-
exports('GetRandomNumber', MSK.Math.Number)
12+
MSK.Math.Number = MSK.Math.Random -- Backwards compatibility
13+
MSK.GetRandomNumber = MSK.Math.Random -- Backwards compatibility
14+
exports('GetRandomNumber', MSK.Math.Random)
1415

1516
MSK.Math.Round = function(num, decimal)
1617
assert(num and tonumber(num), 'Parameter "num" has to be a number on function MSK.Math.Round')

shared/timeout.lua

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ MSK.DelTimeout = MSK.Timeout.Clear -- Backwards compatibility
3939
exports('ClearTimeout', MSK.Timeout.Clear)
4040

4141
-- Credits to ox_lib (https://overextended.dev/ox_lib/Modules/WaitFor/Shared)
42-
MSK.Timeout.Await = function(ms, cb, errMessage)
43-
assert(ms and tonumber(ms), 'Parameter "ms" has to be a number on function MSK.Timeout.Await')
42+
MSK.Timeout.Await = function(timeout, cb, errMessage)
4443
local value = cb()
4544

4645
if value ~= nil then return value end

0 commit comments

Comments
 (0)