Skip to content

Commit 97a4fa0

Browse files
committed
Update v1.4
* Changed MSK.RegisterCommand
1 parent e982b81 commit 97a4fa0

File tree

5 files changed

+60
-10
lines changed

5 files changed

+60
-10
lines changed

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.3
1+
1.3.1

client.lua

+17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
MSK = {}
22
MSK.Timeouts = {}
33

4+
if Config.Framework:match('esx') then
5+
ESX = exports["es_extended"]:getSharedObject()
6+
elseif Config.Framework:match('qbcore') then
7+
QBCore = exports['qb-core']:GetCoreObject()
8+
end
9+
410
local callbackRequest = {}
511
local Letters = {}
612
for i = 48, 57 do table.insert(Letters, string.char(i)) end
@@ -16,6 +22,16 @@ MSK.GetRandomLetter = function(length)
1622
end
1723
end
1824

25+
MSK.HasItem = function(item)
26+
if not Config.Framework:match('esx') or Config.Framework:match('qbcore') then
27+
logging('error', ('Function %s can not used without Framework!'):format('MSK.HasItem'))
28+
return
29+
end
30+
31+
local hasItem = MSK.TriggerCallback('msk_core:hasItem', item)
32+
return hasItem
33+
end
34+
1935
MSK.Notification = function(text)
2036
SetNotificationTextEntry('STRING')
2137
AddTextComponentString(text)
@@ -68,6 +84,7 @@ MSK.Table_Contains = function(table, value)
6884
end
6985
end
7086
end
87+
return false
7188
end
7289

7390
MSK.TriggerCallback = function(name, ...)

config.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ Config = {}
22
----------------------------------------------------------------
33
Config.VersionChecker = true
44
----------------------------------------------------------------
5-
-- This is only for MSK.RegisterCommand // View the Wiki to get more Information about this
6-
Config.Framework = 'standalone' -- Set to 'standalone', 'esx' or 'qbcore'
5+
-- Only Required for MSK.RegisterCommand // View Wiki for more Information about that!
6+
Config.Framework = 'esx' -- Set to 'standalone', 'esx' or 'qbcore'
77
----------------------------------------------------------------

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 'Core functions for MSK Scripts'
7-
version '1.3'
7+
version '1.4'
88

99
lua54 'yes'
1010

server.lua

+39-6
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ MSK.GetRandomLetter = function(length)
2222
end
2323
end
2424

25-
MSK.RegisterCommand = function(name, group, cb, console, suggestion)
25+
MSK.RegisterCommand = function(name, group, cb, console, framework, suggestion)
2626
if type(name) == 'table' then
2727
for k, v in ipairs(name) do
28-
MSK.RegisterCommand(v, group, cb, console, suggestion)
28+
MSK.RegisterCommand(v, group, cb, console, framework, suggestion)
2929
end
3030
return
3131
end
@@ -86,14 +86,14 @@ MSK.RegisterCommand = function(name, group, cb, console, suggestion)
8686
MSK.Notification(source, error)
8787
end
8888
else
89-
if Config.Framework:match('standalone') then
90-
cb(source, args, rawCommand)
91-
elseif Config.Framework:match('esx') then
89+
if Config.Framework:match('esx') and framework then
9290
local xPlayer = ESX.GetPlayerFromId(source)
9391
cb(xPlayer, args, rawCommand)
94-
elseif Config.Framework:match('qbcore') then
92+
elseif Config.Framework:match('qbcore') and framework then
9593
local Player = QBCore.Functions.GetPlayer(source)
9694
cb(Player, args, rawCommand)
95+
elseif Config.Framework:match('standalone') or not framework then
96+
cb(source, args, rawCommand)
9797
end
9898
end
9999
end
@@ -128,6 +128,7 @@ MSK.Table_Contains = function(table, value)
128128
end
129129
end
130130
end
131+
return false
131132
end
132133

133134
MSK.AddWebhook = function(webhook, botColor, botName, botAvatar, title, description, fields, footer, time)
@@ -174,6 +175,38 @@ MSK.logging = function(script, code, ...)
174175
end
175176
end
176177

178+
MSK.HasItem = function(xPlayer, item)
179+
if not xPlayer then logging('error', 'Player on Function MSK.HasItem does not exist!') return end
180+
if not Config.Framework:match('esx') or Config.Framework:match('qbcore') then
181+
logging('error', ('Function %s can not used without Framework!'):format('^3MSK.HasItem^0'))
182+
return
183+
end
184+
local hasItem
185+
186+
if Config.Framework:match('esx') then
187+
hasItem = xPlayer.getInventoryItem(item)
188+
elseif Config.Framework:match('qbcore') then
189+
hasItem = xPlayer.Functions.GetItemByName(item)
190+
else
191+
logging('error', 'Framework on Function MSK.HasItem is not configured!')
192+
end
193+
194+
return hasItem
195+
end
196+
197+
MSK.RegisterCallback('msk_core:hasItem', function(source, cb, item)
198+
local src = source
199+
local xPlayer
200+
201+
if Config.Framework:match('esx') then
202+
xPlayer = ESX.GetPlayerFromId(src)
203+
elseif Config.Framework:match('qbcore') then
204+
xPlayer = QBCore.Functions.GetPlayer(src)
205+
end
206+
207+
cb(MSK.HasItem(xPlayer, item))
208+
end)
209+
177210
RegisterNetEvent('msk_core:triggerCallback')
178211
AddEventHandler('msk_core:triggerCallback', function(name, requestId, ...)
179212
local src = source

0 commit comments

Comments
 (0)