mirror of
https://github.com/jimathy/jim-consumables.git
synced 2026-08-16 22:16:02 +01:00
place start functions behind onResourceStart()
This commit is contained in:
@@ -1,11 +1,18 @@
|
|||||||
local Consumables = Config.Consumables
|
local Consumables = Config.Consumables
|
||||||
local Emotes = Config.Emotes
|
local Emotes = Config.Emotes
|
||||||
|
|
||||||
for k, v in pairs(Config.Consumables) do
|
onResourceStart(function()
|
||||||
createUseableItem(k, function(source, item) TriggerClientEvent(getScript()..':Consume', source, item.name) end)
|
for k, v in pairs(Config.Consumables) do
|
||||||
if not Items[k] then print("^1Debug^7: ^2Item check ^7- '^1"..k.."^7' ^2not found in the shared lua^7") end
|
createUseableItem(k, function(source, item) TriggerClientEvent(getScript()..':Consume', source, item.name) end)
|
||||||
if not Config.Emotes[v.emote] then print("^1Debug^7: ^2Emote check ^7- '^1"..k.."^7' ^2requested emote ^7'^6"..v.emote.."^7' - ^2not found in config^7.^2lua^7") end
|
if not Items[k] then print("^1Debug^7: ^2Item check ^7- '^1"..k.."^7' ^2not found in the shared lua^7") end
|
||||||
end
|
if not Config.Emotes[v.emote] then print("^1Debug^7: ^2Emote check ^7- '^1"..k.."^7' ^2requested emote ^7'^6"..v.emote.."^7' - ^2not found in config^7.^2lua^7") end
|
||||||
|
end
|
||||||
|
|
||||||
|
--Export Import System--
|
||||||
|
createCallback(getScript()..':server:syncConsumables', function(source) return Consumables end)
|
||||||
|
createCallback(getScript()..':server:syncEmotes', function(source) return Emotes end)
|
||||||
|
|
||||||
|
end, true)
|
||||||
|
|
||||||
RegisterNetEvent(getScript()..':server:addNeed', function(amount, type)
|
RegisterNetEvent(getScript()..':server:addNeed', function(amount, type)
|
||||||
local Player = Core.Functions.GetPlayer(source) if not Player then return end
|
local Player = Core.Functions.GetPlayer(source) if not Player then return end
|
||||||
@@ -18,19 +25,15 @@ RegisterNetEvent(getScript()..':server:addNeed', function(amount, type)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--Export Import System--
|
|
||||||
createCallback(getScript()..':server:syncConsumables', function(source) return Consumables end)
|
|
||||||
createCallback(getScript()..':server:syncEmotes', function(source) return Emotes end)
|
|
||||||
|
|
||||||
local syncScheduled = false
|
local syncScheduled = false
|
||||||
function syncConsumables()
|
function syncConsumables()
|
||||||
if Config.System.Debug then print("^5Debug^7: ^2Sending ^6"..countTable(Consumables).." ^3Consumables ^2to all clients^7") end
|
debugPrint("^5Debug^7: ^2Sending ^6"..countTable(Consumables).." ^3Consumables ^2to all clients^7")
|
||||||
TriggerClientEvent(getScript()..":client:syncConsumables", -1, Consumables)
|
TriggerClientEvent(getScript()..":client:syncConsumables", -1, Consumables)
|
||||||
syncScheduled = false
|
syncScheduled = false
|
||||||
end
|
end
|
||||||
local emoteSyncScheduled = false
|
local emoteSyncScheduled = false
|
||||||
function syncEmotes()
|
function syncEmotes()
|
||||||
if Config.System.Debug then print("^5Debug^7: ^2Sending ^6"..countTable(Emotes).." ^3Emotes to all clients^7") end
|
debugPrint("^5Debug^7: ^2Sending ^6"..countTable(Emotes).." ^3Emotes to all clients^7")
|
||||||
TriggerClientEvent(getScript()..":client:syncEmotes", -1, Emotes)
|
TriggerClientEvent(getScript()..":client:syncEmotes", -1, Emotes)
|
||||||
emoteSyncScheduled = false
|
emoteSyncScheduled = false
|
||||||
end
|
end
|
||||||
@@ -39,26 +42,26 @@ RegisterNetEvent(getScript()..':server:syncAddItem', function(itemName, data)
|
|||||||
if not Consumables[itemName] then
|
if not Consumables[itemName] then
|
||||||
Consumables[itemName] = data
|
Consumables[itemName] = data
|
||||||
createUseableItem(itemName, function(source, item) TriggerClientEvent(getScript()..':Consume', source, itemName) end)
|
createUseableItem(itemName, function(source, item) TriggerClientEvent(getScript()..':Consume', source, itemName) end)
|
||||||
if Config.System.Debug then print("^5Debug^7: "..GetInvokingResource().." ^2is sending new ^3Item^7: '"..itemName.."'") end
|
debugPrint("^5Debug^7: "..GetInvokingResource().." ^2is sending new ^3Item^7: '"..itemName.."'")
|
||||||
if not syncScheduled then
|
if not syncScheduled then
|
||||||
syncScheduled = true
|
syncScheduled = true
|
||||||
Citizen.SetTimeout(5000, syncConsumables)
|
Citizen.SetTimeout(5000, syncConsumables)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if Config.System.Debug then print("^1Debug^7: "..GetInvokingResource().." ^2is sending ^1duplicate ^3Item^7: '"..itemName.."'") end
|
debugPrint("^1Debug^7: "..GetInvokingResource().." ^2is sending ^1duplicate ^3Item^7: '"..itemName.."'")
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNetEvent(getScript()..':server:syncAddEmote', function(emoteName, data)
|
RegisterNetEvent(getScript()..':server:syncAddEmote', function(emoteName, data)
|
||||||
if not Emotes[emoteName] then
|
if not Emotes[emoteName] then
|
||||||
Emotes[emoteName] = data
|
Emotes[emoteName] = data
|
||||||
if Config.System.Debug then print("^5Debug^7: "..GetInvokingResource().." ^2is sending new ^3Emote^7: '"..emoteName.."'") end
|
debugPrint("^5Debug^7: "..GetInvokingResource().." ^2is sending new ^3Emote^7: '"..emoteName.."'")
|
||||||
if not emoteSyncScheduled then
|
if not emoteSyncScheduled then
|
||||||
emoteSyncScheduled = true
|
emoteSyncScheduled = true
|
||||||
Citizen.SetTimeout(5000, syncEmotes)
|
Citizen.SetTimeout(5000, syncEmotes)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if Config.System.Debug then print("^1Debug^7: "..GetInvokingResource().." ^2is sending ^1duplicate ^3Emote^7: '"..emoteName.."'") end
|
debugPrint("^1Debug^7: "..GetInvokingResource().." ^2is sending ^1duplicate ^3Emote^7: '"..emoteName.."'")
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -67,12 +70,14 @@ RegisterNetEvent(getScript()..":server:syncConsumables", function()
|
|||||||
end)
|
end)
|
||||||
RegisterNetEvent(getScript()..":server:syncEmotes", function()
|
RegisterNetEvent(getScript()..":server:syncEmotes", function()
|
||||||
TriggerClientEvent(getScript()..':client:syncEmotes', -1, Emotes)
|
TriggerClientEvent(getScript()..':client:syncEmotes', -1, Emotes)
|
||||||
end)
|
|
||||||
|
|
||||||
|
end)
|
||||||
|
--[[
|
||||||
Core.Commands.Add('consumableCreator', "Create consumables (admin only)", {}, false, function(source)
|
Core.Commands.Add('consumableCreator', "Create consumables (admin only)", {}, false, function(source)
|
||||||
if source > 0 then return TriggerClientEvent(getScript()..":client:consumableCreator", source) end
|
if source > 0 then return TriggerClientEvent(getScript()..":client:consumableCreator", source) end
|
||||||
end, 'admin')
|
end, 'admin')
|
||||||
|
|
||||||
Core.Commands.Add('testConsumableEmotes', "Test consumables Emotes (admin only)", {}, false, function(source)
|
Core.Commands.Add('testConsumableEmotes', "Test consumables Emotes (admin only)", {}, false, function(source)
|
||||||
if source > 0 then return TriggerClientEvent(getScript()..":client:testEmotes", source) end
|
if source > 0 then return TriggerClientEvent(getScript()..":client:testEmotes", source) end
|
||||||
end, 'admin')
|
end, 'admin')
|
||||||
|
]]
|
||||||
Reference in New Issue
Block a user