diff --git a/client/cocaine.lua b/client/cocaine.lua index 9a2c4fa..a45c9f4 100644 --- a/client/cocaine.lua +++ b/client/cocaine.lua @@ -36,19 +36,6 @@ RegisterNetEvent("coke:init", function() end end) -AddEventHandler('onResourceStart', function(resource) - if resource == GetCurrentResourceName() then - LoadModel('prop_plant_01a') - TriggerEvent('coke:init') - end - end) - - RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function() - Wait(3000) - LoadModel('prop_plant_01a') - TriggerEvent('coke:init') - end) - AddEventHandler('onResourceStop', function(resourceName) if GetCurrentResourceName() == resourceName then SetModelAsNoLongerNeeded(GetHashKey('prop_plant_01a')) diff --git a/client/functions.lua b/client/functions.lua index d8ab2d2..49621ac 100644 --- a/client/functions.lua +++ b/client/functions.lua @@ -63,6 +63,10 @@ function loadParticle(dict) SetPtfxAssetNextCall(dict) end +function LoadModel(hash) + lib.requestModel(hash, Config.RequestModelTime) +end + function minigame() local time = 0 local game = Config.Minigames @@ -173,30 +177,28 @@ function minigame() end function GetImage(img) - if GetResourceState('ox_inventory') == 'started' then - local Items = exports['ox_inventory']:Items() - if Items[img]['client'] then - if Items[img]['client']['image'] then - return Items[img]['client']['image'] - else - return "nui://ox_inventory/web/images/".. img.. '.png' - end - else - return "nui://ox_inventory/web/images/".. img.. '.png' - end - elseif GetResourceState('ps-inventory') == 'started' then - return "nui://ps-inventory/html/images/".. QBCore.Shared.Items[img].image - elseif GetResourceState('lj-inventory') == 'started' then - return "nui://lj-inventory/html/images/".. QBCore.Shared.Items[img].image - elseif GetResourceState('qb-inventory') == 'started' then - return "nui://qb-inventory/html/images/".. QBCore.Shared.Items[img].image - elseif GetResourceState('qs-inventory') == 'started' then - return "nui://qs-inventory/html/img/".. QBCore.Shared.Items[img].image - elseif GetResourceState('origen_inventory') == 'started' then - return "nui://origen_inventory/html/img/".. QBCore.Shared.Items[img].image - elseif GetResourceState('core_inventory') == 'started' then - return "nui://core_inventory/html/img/".. QBCore.Shared.Items[img].image - end + if GetResourceState('ox_inventory') == 'started' then + local Items = exports['ox_inventory']:Items() + local itemClient = Items[img] and Items[img]['client'] + if itemClient and itemClient['image'] then + return itemClient['image'] + else + return "nui://ox_inventory/web/images/" .. img .. '.png' + end + end + local invs = { + ['ps-inventory'] = "nui://ps-inventory/html/images/", + ['lj-inventory'] = "nui://lj-inventory/html/images/", + ['qb-inventory'] = "nui://qb-inventory/html/images/", + ['qs-inventory'] = "nui://qs-inventory/html/img/", + ['origen_inventory'] = "nui://origen_inventory/html/img/", + ['core_inventory'] = "nui://core_inventory/html/img/" + } + for k, v in pairs(invs) do + if GetResourceState(k) == 'started' then + return v .. QBCore.Shared.Items[img].image + end + end end function GetLabel(label) @@ -464,7 +466,7 @@ function AddMultiModel(model, data, num) for k, v in pairs (data) do table.insert(data,{ { icon = v.icon, label = v.label, event = v.event or nil, action = v.action or nil, - onSelect = v.action,data = num,canInteract = v.canInteract or nil, + onSelect = v.action,data = num,canInteract = v.canInteract or nil, distance = 2.0 } }) end @@ -566,9 +568,24 @@ end RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function() Wait(3000) + LoadModel('prop_plant_01b') TriggerEvent('heroin:init') + LoadModel('prop_plant_01a') TriggerEvent('coke:init') + LoadModel('prop_cactus_03') TriggerEvent('Mescaline:init') + LoadModel('mushroom') TriggerEvent('shrooms:init') + LoadModel('bkr_prop_weed_lrg_01b') TriggerEvent('weed:init') local check = lib.callback.await('md-drugs:server:GetRep', false) - return + return +end) + +AddEventHandler('onResourceStart', function(resource) + if resource == GetCurrentResourceName() then + LoadModel('prop_plant_01b') TriggerEvent('heroin:init') + LoadModel('prop_plant_01a') TriggerEvent('coke:init') + LoadModel('prop_cactus_03') TriggerEvent('Mescaline:init') + LoadModel('mushroom') TriggerEvent('shrooms:init') + LoadModel('bkr_prop_weed_lrg_01b') TriggerEvent('weed:init') + end end) local active = false RegisterNetEvent('md-drugs:client:minusTier', function(data) diff --git a/client/heroin.lua b/client/heroin.lua index c326f76..7ec37f5 100644 --- a/client/heroin.lua +++ b/client/heroin.lua @@ -3,7 +3,7 @@ local PoppyPlants = {} local herointable = false local function createLabKit(coord, head) - local heroinlabkit = CreateObject("v_ret_ml_tablea", coord.x, coord.y, coord.z - 1, true, false) + local heroinlabkit = CreateObject("v_ret_ml_tablea", coord.x, coord.y, coord.z - 1, true, false,false) SetEntityHeading(heroinlabkit, head) PlaceObjectOnGroundProperly(heroinlabkit) local options = { @@ -54,19 +54,6 @@ RegisterNetEvent("heroin:init", function() end end) -AddEventHandler('onResourceStart', function(resource) - if resource == GetCurrentResourceName() then - LoadModel('prop_plant_01b') - TriggerEvent('heroin:init') - end - end) - - RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function() - Wait(3000) - LoadModel('prop_plant_01b') - TriggerEvent('heroin:init') - end) - AddEventHandler('onResourceStop', function(resourceName) if GetCurrentResourceName() == resourceName then SetModelAsNoLongerNeeded(GetHashKey('prop_plant_01b')) diff --git a/client/mescaline.lua b/client/mescaline.lua index 2b6d7f0..c52910c 100644 --- a/client/mescaline.lua +++ b/client/mescaline.lua @@ -1,14 +1,6 @@ local QBCore = exports['qb-core']:GetCoreObject() local Mescaline = {} -function LoadModel(hash) - hash = GetHashKey(hash) - RequestModel(hash) - while not HasModelLoaded(hash) do - Wait(3000) - end -end - local function pick(loc) if not progressbar(Lang.mescaline.pick, 4000, 'uncuff') then return end TriggerServerEvent("Mescaline:pickupCane", loc) @@ -41,20 +33,7 @@ RegisterNetEvent("Mescaline:init", function() end end) -AddEventHandler('onResourceStart', function(resource) - if resource == GetCurrentResourceName() then - LoadModel('prop_cactus_03') - TriggerEvent('Mescaline:init') - end - end) - - RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function() - Wait(3000) - LoadModel('prop_cactus_03') - TriggerEvent('Mescaline:init') - end) - - AddEventHandler('onResourceStop', function(resourceName) +AddEventHandler('onResourceStop', function(resourceName) if GetCurrentResourceName() == resourceName then SetModelAsNoLongerNeeded(GetHashKey('prop_cactus_03')) for k, v in pairs(Mescaline) do diff --git a/client/shrooms.lua b/client/shrooms.lua index 29fde38..5aff339 100644 --- a/client/shrooms.lua +++ b/client/shrooms.lua @@ -1,14 +1,6 @@ local QBCore = exports['qb-core']:GetCoreObject() local shrooms = {} -function LoadModel(hash) - hash = GetHashKey(hash) - RequestModel(hash) - while not HasModelLoaded(hash) do - Wait(3000) - end -end - local function pick(loc) if not progressbar(Lang.Shrooms.pick, 4000, 'uncuff') then return end TriggerServerEvent("shrooms:pickupCane", loc) @@ -24,14 +16,6 @@ RegisterNetEvent('shrooms:respawnCane', function(loc) end end) -AddEventHandler('onResourceStart', function(resource) - if resource == GetCurrentResourceName() then - Wait(3000) - LoadModel('mushroom') - TriggerEvent('shrooms:init') - end - end) - AddEventHandler('onResourceStop', function(resourceName) if GetCurrentResourceName() == resourceName then SetModelAsNoLongerNeeded(GetHashKey('mushroom')) @@ -48,13 +32,7 @@ RegisterNetEvent('shrooms:removeCane', function(loc) shrooms[loc] = nil end) - RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function() - Wait(3000) - LoadModel('mushroom') - TriggerEvent('shrooms:init') - end) - - RegisterNetEvent("shrooms:init", function() +RegisterNetEvent("shrooms:init", function() for k, v in pairs (GlobalState.shrooms) do local hash = GetHashKey(v.model) if not HasModelLoaded(hash) then LoadModel(hash) end diff --git a/client/weed.lua b/client/weed.lua index c79ddc1..25f63d9 100644 --- a/client/weed.lua +++ b/client/weed.lua @@ -3,13 +3,6 @@ local WeedPlant = {} local exploded = nil local drying = false -function LoadModel(hash) - hash = GetHashKey(hash) - RequestModel(hash) - while not HasModelLoaded(hash) do - Wait(3000) - end -end local function hasJob() if Config.Joblock then @@ -53,18 +46,6 @@ RegisterNetEvent("weed:init", function() end end) -AddEventHandler('onResourceStart', function(resource) - if resource == GetCurrentResourceName() then - LoadModel('bkr_prop_weed_lrg_01b') - TriggerEvent('weed:init') - end - end) - RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function() - Wait(3000) - LoadModel('bkr_prop_weed_lrg_01b') - TriggerEvent('weed:init') - end) - AddEventHandler('onResourceStop', function(resourceName) if GetCurrentResourceName() == resourceName then SetModelAsNoLongerNeeded(GetHashKey('bkr_prop_weed_lrg_01b'))