diff --git a/README.md b/README.md index 74489e9..a84cd72 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,5 @@ -This work is licensed under a [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 -International License][cc-by-nc-sa]. - -[![CC BY-NC-SA 4.0][cc-by-nc-sa-image]][cc-by-nc-sa] - -[cc-by-nc-sa]: http://creativecommons.org/licenses/by-nc-sa/4.0/ -[cc-by-nc-sa-image]: https://licensebuttons.net/l/by-nc-sa/4.0/88x31.png -[cc-by-nc-sa-shield]: https://img.shields.io/badge/License-CC%20BY--NC--SA%204.0-lightgrey.svg - -# tr-mining -Mining Script for QBCore +# ESX-Mining +Mining Script for ESX ## Whats included - Easy to use config @@ -19,80 +10,29 @@ Mining Script for QBCore - DrawtextUi & Target Combined ## Dependencies -- [qb-core](https://github.com/qbcore-framework/qb-core) **Lastest Core with DrawtextUI** -- [qb-target](https://github.com/BerkieBb/qb-target) -- [qb-menu](https://github.com/qbcore-framework/qb-menu) +- [Esx-Legacy](https://github.com/esx-framework/esx-legacy) +- [Qtarget](https://github.com/overextended/qtarget) - [PolyZone](https://github.com/mkafrin/PolyZone) -- [nw-mine](https://github.com/Nowimps8/nw_mine) ## Installation - -Add the item to your **qb-core/shared/item.lua** -``` --- Mining - ['mining_pickaxe'] = {['name'] = 'mining_pickaxe', ['label'] = 'Mining Pickaxe', ['weight'] = 500, ['type'] = 'item', ['image'] = 'mining_pickaxe.png', ['unique'] = true, ['useable'] = true, ['shouldClose'] = true, ['combinable'] = nil, ['description'] = 'Classic\'s pickaxe for mining'}, - ['mining_pan'] = {['name'] = 'mining_pan', ['label'] = 'Washing Pan', ['weight'] = 500, ['type'] = 'item', ['image'] = 'mining_pan.png', ['unique'] = true, ['useable'] = true, ['shouldClose'] = true, ['combinable'] = nil, ['description'] = 'Classic\'s washing pan'}, - ['mining_stone'] = {['name'] = 'mining_stone', ['label'] = 'Mined Stone', ['weight'] = 500, ['type'] = 'item', ['image'] = 'mining_stone.png', ['unique'] = false, ['useable'] = true, ['shouldClose'] = true, ['combinable'] = nil, ['description'] = 'Mined Stone'}, - ['mining_washedstone'] = {['name'] = 'mining_washedstone', ['label'] = 'Washed Stone', ['weight'] = 500, ['type'] = 'item', ['image'] = 'mining_washedstone.png', ['unique'] = false, ['useable'] = true, ['shouldClose'] = true, ['combinable'] = nil, ['description'] = 'Wasted Stone'}, - ['mining_ironfragment'] = {['name'] = 'mining_ironfragment', ['label'] = 'Iron Fragment', ['weight'] = 500, ['type'] = 'item', ['image'] = 'mining_ironfragment.png', ['unique'] = false, ['useable'] = true, ['shouldClose'] = true, ['combinable'] = nil, ['description'] = 'Iron fragment from mining'}, - ['mining_ironbar'] = {['name'] = 'mining_ironbar', ['label'] = 'Iron Bar', ['weight'] = 500, ['type'] = 'item', ['image'] = 'mining_ironbar.png', ['unique'] = false, ['useable'] = true, ['shouldClose'] = true, ['combinable'] = nil, ['description'] = 'Iron Bar'}, - ['mining_goldnugget'] = {['name'] = 'mining_goldnugget', ['label'] = 'Golden Nugget', ['weight'] = 500, ['type'] = 'item', ['image'] = 'mining_goldnugget.png', ['unique'] = false, ['useable'] = true, ['shouldClose'] = true, ['combinable'] = nil, ['description'] = 'Golden nugget from mining'}, - ['mining_goldbar'] = {['name'] = 'mining_goldbar', ['label'] = 'Gold Bar', ['weight'] = 500, ['type'] = 'item', ['image'] = 'mining_goldbar.png', ['unique'] = false, ['useable'] = true, ['shouldClose'] = true, ['combinable'] = nil, ['description'] = 'Gold Bar'}, - ['mining_copperfragment'] = {['name'] = 'mining_copperfragment', ['label'] = 'Copper Fragment', ['weight'] = 500, ['type'] = 'item', ['image'] = 'mining_copperfragment.png', ['unique'] = false, ['useable'] = true, ['shouldClose'] = true, ['combinable'] = nil, ['description'] = 'Copper fragment from mining'}, - ['mining_copperbar'] = {['name'] = 'mining_copperbar', ['label'] = 'Copper Bar', ['weight'] = 500, ['type'] = 'item', ['image'] = 'mining_copperbar.png', ['unique'] = false, ['useable'] = true, ['shouldClose'] = true, ['combinable'] = nil, ['description'] = 'Copper Bar'}, - -``` -For images move the images from the img folder to your inventory image folder **qb-inventory/html/images** - -If you use another Drawtext like cd_drawtextui for example change the following in the **client/main.lua 287 - 296** - -**Before** DRAWTEXT -``` -exports['qb-core']:DrawText(Config.Text['MiningAlert'], 'left') - -exports['qb-core']:DrawText(Config.Text['StartMining'],'left') -``` - -**After** -``` -TriggerEvent('cd_drawtextui:ShowUI', 'show', Config.Text['MiningAlert']) - -TriggerEvent('cd_drawtextui:ShowUI', 'show', Config.Text['StartMining']) -``` - -**Before** HIDETEXT -``` -exports['qb-core']:HideText() -``` - -**After** -``` -TriggerEvent('cd_drawtextui:HideUI') -``` - -**You will also need to remove this line if you are using CD_Drawtextui** -**Line 160** -``` -exports['qb-core']:KeyPressed() -``` - -## **Drawtext Ui Files will be provided if you don't have it installed in your core** -- [QBCore_Drawtext](https://github.com/trclassic92/QBCore_Drawtext) **Only add if you dont have the lastest core update** - +Download the resource, rename it from esx-mining-main to esx-mining, drag it into your resource folder. ensure it in your server.cfg, dont forget to run the items.sql into the database ## Preview Pictures - [Youtube Video](https://youtu.be/9VXjTrUdjfc) ![Preview Screenshot](https://i.imgur.com/jIJ9SOU.png) ![Preview Screenshot](https://i.imgur.com/mu0gNQC.jpeg) -![Preview Screenshot](https://i.imgur.com/7gKe9wE.jpeg) -![Preview Screenshot](https://i.imgur.com/cGaTg3V.jpeg) -![Preview Screenshot](https://i.imgur.com/my22yZL.jpeg) +![image](https://user-images.githubusercontent.com/102178921/165142626-75b1e6ba-4c4b-415f-b4f5-edb3a678064d.png)) +![image](https://user-images.githubusercontent.com/102178921/165142476-1c5ea064-c3e0-4744-9f25-4868717a72e1.png)) ![Preview Screenshot](https://i.imgur.com/fUQ61Bl.jpeg) ![Preview Screenshot](https://i.imgur.com/S382wMf.jpeg) ![Preview Screenshot](https://i.imgur.com/VJCk6cx.jpeg) ## Discord -- [Join Discord](https://discord.gg/zRCdhENsHG) +- [ESX](https://discord.com/invite/VKX6DHVyhV) +- [Join Classics Discord](https://discord.gg/zRCdhENsHG) ## Support The Script -- [Ko-fi Link](https://ko-fi.com/trclassic) +- [Ko-fi Link for Classic](https://ko-fi.com/trclassic) + +## Credits +[Classic](https://github.com/trclassic92) diff --git a/client/blips.lua b/client/blips.lua index f5f0d3d..2b30883 100644 --- a/client/blips.lua +++ b/client/blips.lua @@ -1,45 +1,16 @@ -local QBCore = exports['qb-core']:GetCoreObject() - if Config.UseBlips then CreateThread(function() - MineShaftBlip = AddBlipForCoord(MiningLocation.coords) - SetBlipSprite (MineShaftBlip, MiningLocation.SetBlipSprite) - SetBlipDisplay(MineShaftBlip, MiningLocation.SetBlipDisplay) - SetBlipScale (MineShaftBlip, MiningLocation.SetBlipScale) - SetBlipAsShortRange(MineShaftBlip, true) - SetBlipColour(MineShaftBlip, MiningLocation.SetBlipColour) + for k,v in pairs(Config.Blips) do + local Blip = AddBlipForCoord(v.coords) + SetBlipSprite (Blip, v.Sprite) + SetBlipDisplay(Blip, v.Display) + SetBlipScale (Blip, v.Scale) + SetBlipAsShortRange(Blip, true) + SetBlipColour(Blip, v.Colour) BeginTextCommandSetBlipName("STRING") - AddTextComponentSubstringPlayerName(MiningLocation.BlipLabel) - EndTextCommandSetBlipName(MineShaftBlip) - - WashBlip = AddBlipForCoord(WashLocation.coords) - SetBlipSprite (WashBlip, WashLocation.SetBlipSprite) - SetBlipDisplay(WashBlip, WashLocation.SetBlipDisplay) - SetBlipScale (WashBlip, WashLocation.SetBlipScale) - SetBlipAsShortRange(WashBlip, true) - SetBlipColour(WashBlip, WashLocation.SetBlipColour) - BeginTextCommandSetBlipName("STRING") - AddTextComponentSubstringPlayerName(WashLocation.BlipLabel) - EndTextCommandSetBlipName(WashBlip) - - SmeltBlip = AddBlipForCoord(SmeltLocation.coords) - SetBlipSprite (SmeltBlip, SmeltLocation.SetBlipSprite) - SetBlipDisplay(SmeltBlip, SmeltLocation.SetBlipDisplay) - SetBlipScale (SmeltBlip, SmeltLocation.SetBlipScale) - SetBlipAsShortRange(SmeltBlip, true) - SetBlipColour(SmeltBlip, SmeltLocation.SetBlipColour) - BeginTextCommandSetBlipName("STRING") - AddTextComponentSubstringPlayerName(SmeltLocation.BlipLabel) - EndTextCommandSetBlipName(SmeltBlip) - - SellerBlip = AddBlipForCoord(SellLocation.coords) - SetBlipSprite (SellerBlip, SellLocation.SetBlipSprite) - SetBlipDisplay(SellerBlip, SellLocation.SetBlipDisplay) - SetBlipScale (SellerBlip, SellLocation.SetBlipScale) - SetBlipAsShortRange(SellerBlip, true) - SetBlipColour(SellerBlip, SellLocation.SetBlipColour) - BeginTextCommandSetBlipName("STRING") - AddTextComponentSubstringPlayerName(SellLocation.BlipLabel) - EndTextCommandSetBlipName(SellerBlip) + AddTextComponentSubstringPlayerName(v.Label) + EndTextCommandSetBlipName(Blip) + Config.Blips[k].blip = Blip + end end) end \ No newline at end of file diff --git a/client/main.lua b/client/main.lua index 3555639..1c4ed6d 100644 --- a/client/main.lua +++ b/client/main.lua @@ -1,8 +1,10 @@ -local QBCore = exports['qb-core']:GetCoreObject() local miningZone = false local isMining = false - -RegisterNetEvent('tr-mining:getMiningstage', function(stage, state, k) +local MiningLocation = Config.Blips.MiningLocation +local WashLocation = Config.Blips.WashLocation +local SmeltLocation = Config.Blips.SmeltLocation +local SellLocation = Config.Blips.SellLocation +RegisterNetEvent('esx-mining:getMiningstage', function(stage, state, k) Config.MiningLocation[k][stage] = state end) @@ -16,38 +18,46 @@ end local function StartMining(mining) local animDict = "melee@hatchet@streamed_core" local animName = "plyr_rear_takedown_b" - local trClassic = PlayerPedId() + local Ped = PlayerPedId() local miningtimer = MiningJob.MiningTimer isMining = true - TriggerEvent('tr-mining:miningwithaxe') - FreezeEntityPosition(trClassic, true) - QBCore.Functions.Progressbar("Mining....", Config.Text['Mining_ProgressBar'], miningtimer, false, true, { - disableMovement = true, - disableCarMovement = true, - disableMouse = false, - disableCombat = true, - }, {}, {}, {}, function() - TriggerServerEvent('tr-mining:setMiningStage', "isMined", true, mining) - TriggerServerEvent('tr-mining:setMiningStage', "isOccupied", false, mining) - TriggerServerEvent('tr-mining:receivedStone') - TriggerServerEvent('tr-mining:setMiningTimer') + TriggerEvent('esx-mining:miningwithaxe') + FreezeEntityPosition(Ped, true) + TriggerEvent("mythic_progbar:client:progress", { + name = "Mining", + duration = miningtimer, + label = Config.Text['Mining_ProgressBar'], + useWhileDead = false, + canCancel = true, + controlDisables = { + disableMovement = true, + disableCarMovement = true, + disableMouse = false, + disableCombat = true, + },animation = {}}, function(status) + if not status then + TriggerServerEvent('esx-mining:setMiningStage', "isMined", true, mining) + TriggerServerEvent('esx-mining:setMiningStage', "isOccupied", false, mining) + TriggerServerEvent('esx-mining:receivedStone') + TriggerServerEvent('esx-mining:setMiningTimer') isMining = false - TaskPlayAnim(trClassic, animDict, "exit", 3.0, 3.0, -1, 2, 0, 0, 0, 0) + TaskPlayAnim(Ped, animDict, "exit", 3.0, 3.0, -1, 2, 0, 0, 0, 0) DetachEntity(pickaxeprop, 1, true) DeleteEntity(pickaxeprop) - DeleteObject(pickaxeprop) - FreezeEntityPosition(trClassic, false) - end, function() - ClearPedTasks(trClassic) - TriggerServerEvent('tr-mining:setMiningStage', "isOccupied", false, mining) + FreezeEntityPosition(Ped, false) + else + ClearPedTasks(Ped) + TriggerServerEvent('esx-mining:setMiningStage', "isOccupied", false, mining) isMining = false - TaskPlayAnim(trClassic, animDict, "exit", 3.0, 3.0, -1, 2, 0, 0, 0, 0) - FreezeEntityPosition(trClassic, false) + TaskPlayAnim(Ped, animDict, "exit", 3.0, 3.0, -1, 2, 0, 0, 0, 0) + FreezeEntityPosition(Ped, false) DetachEntity(pickaxeprop, 1, true) DeleteEntity(pickaxeprop) DeleteObject(pickaxeprop) + end end) - TriggerServerEvent('tr-mining:setMiningStage', "isOccupied", true, mining) + + TriggerServerEvent('esx-mining:setMiningStage', "isOccupied", true, mining) CreateThread(function() while isMining do loadAnimDict(animDict) @@ -57,253 +67,239 @@ local function StartMining(mining) end) end -RegisterNetEvent('tr-mining:miningwithaxe', function() +RegisterCommand("stone", function() + TriggerServerEvent('esx-mining:receivedStone') +end) + +RegisterNetEvent('esx-mining:miningwithaxe', function() local ped = PlayerPedId() trpickaxeprop = CreateObject(GetHashKey("prop_tool_pickaxe"), 0, 0, 0, true, true, true) AttachEntityToEntity(trpickaxeprop, ped, GetPedBoneIndex(ped, 57005), 0.17, -0.04, -0.04, 180, 100.00, 120.0, true, true, false, true, 1, true) Wait(MiningJob.MiningTimer) DetachEntity(trpickaxeprop, 1, true) DeleteEntity(trpickaxeprop) - DeleteObject(trpickaxeprop) end) -RegisterNetEvent('tr-mining:getpickaxe', function() - TriggerServerEvent('tr-mining:BuyPickaxe') +RegisterNetEvent('esx-mining:getpickaxe', function() + TriggerServerEvent('esx-mining:BuyPickaxe') end) -RegisterNetEvent('tr-mining:getPan', function() - TriggerServerEvent('tr-mining:BuyWash') +RegisterNetEvent('esx-mining:getPan', function() + TriggerServerEvent('esx-mining:BuyWash') end) -RegisterNetEvent('tr-mining:minermenu', function() -local minermenu = { - { - header = Config.Text["MenuHeading"], - isMenuHeader = true, - }, - { - header = Config.Text["MenuPickAxe"], - txt = Config.Text["PickAxeText"], - params = { - event = 'tr-mining:getpickaxe', - } - }, - { - header = Config.Text["goback"], - }, - } - exports['qb-menu']:openMenu(minermenu) +RegisterNetEvent('esx-mining:minermenu', function() + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'miner_menu', { + title = Config.Text["MenuHeading"], + align = 'top-left', + elements = { + {label = Config.Text["PickAxeText"], event = 'esx-mining:getpickaxe'} +}}, function(data, menu) + TriggerEvent(data.current.event) + menu.close() +end, function(data, menu) + menu.close() +end) end) -RegisterNetEvent('tr-mining:panmenu', function() -local panmenu = { - { - header = Config.Text["WashHeading"], - isMenuHeader = true, - }, - { - header = Config.Text["MenuWashPan"], - txt = Config.Text["PanText"], - params = { - event = 'tr-mining:getPan', - } - }, - { - header = Config.Text["goback"], - }, - } - exports['qb-menu']:openMenu(panmenu) +RegisterNetEvent('esx-mining:panmenu', function() + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'pan_menu', { + title = Config.Text["WashHeading"], + align = 'top-left', + elements = { + {label = Config.Text["PanText"], event = 'esx-mining:getPan'} +}}, function(data, menu) + TriggerEvent(data.current.event) + menu.close() +end, function(data, menu) + menu.close() +end) end) -RegisterNetEvent('tr-mining:smeltmenu', function() - local smeltMenu = { - { - header = Config.Text["SmethHeading"], - isMenuHeader = true, - }, - { - header = Config.Text["Semlt_Iron"], - txt = Config.Text["smelt_IText"], - params = { - event = 'tr-mining:SmeltIron', - } - }, - { - header = Config.Text["Semlt_Copper"], - txt = Config.Text["smelt_CText"], - params = { - event = 'tr-mining:SmeltCopper', - } - }, - { - header = Config.Text["Smelt_Gold"], - txt = Config.Text["smelt_GText"], - params = { - event = 'tr-mining:SmeltGold', - } - }, - { - header = Config.Text["goback"], - }, - } - exports['qb-menu']:openMenu(smeltMenu) +RegisterNetEvent('esx-mining:smeltmenu', function() + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'smelt_menu', { + title = Config.Text["SmethHeading"], + align = 'top-left', + elements = { + {label = Config.Text["smelt_IText"], event = 'esx-mining:SmeltIron'}, + {label = Config.Text["smelt_CText"], event = 'esx-mining:SmeltCopper'}, + {label = Config.Text["smelt_GText"], event = 'esx-mining:SmeltGold'}, + }}, function(data, menu) + TriggerEvent(data.current.event) + menu.close() + end, function(data, menu) + menu.close() + end) end) -local inMiningZone = false -local function MiningKeyBind(mining) - isMiningZone = true - CreateThread(function() - while isMiningZone do - if IsControlJustPressed(0, 38) then - isMiningZone = false + RegisterNetEvent('esx-mining:mine', function(data) + local mining = data.location if not Config.MiningLocation[mining]["isMined"] and not Config.MiningLocation[mining]["isOccupied"] then - exports['qb-core']:KeyPressed() - QBCore.Functions.TriggerCallback('tr-mining:pickaxe', function(PickAxe) + ESX.TriggerServerCallback('esx-mining:pickaxe', function(PickAxe) if PickAxe then StartMining(mining) elseif not PickAxe then - QBCore.Functions.Notify(Config.Text['error_mining'], 'error') + ESX.ShowNotification(Config.Text['error_mining']) end end) - else - exports['qb-core']:DrawText(Config.Text['error_alreadymined'], 'left') end - end - Wait(0) - end end) -end -RegisterNetEvent('tr-mining:washingrocks', function() - QBCore.Functions.TriggerCallback('tr-mining:washpan', function(washingpancheck) +RegisterNetEvent('esx-mining:washingrocks', function() + ESX.TriggerServerCallback('esx-mining:washpan', function(washingpancheck) if washingpancheck then - QBCore.Functions.TriggerCallback('tr-mining:stonesbruf', function(stonesbruf) + ESX.TriggerServerCallback('esx-mining:stonesbruf', function(stonesbruf) if stonesbruf then local playerPed = PlayerPedId() local coords = GetEntityCoords(playerPed) local rockwash = MiningJob.WashingTimer TaskStartScenarioInPlace(playerPed, 'WORLD_HUMAN_BUM_WASH', 0, false) - QBCore.Functions.Progressbar('Washing Stones', Config.Text['Washing_Rocks'], rockwash, false, true, { -- Name | Label | Time | useWhileDead | canCancel - disableMovement = true, - disableCarMovement = true, - disableMouse = false, - disableCombat = true, - }, { - }, {}, {}, function() + TriggerEvent("mythic_progbar:client:progress", { + name = "Washing Stones", + duration = rockwash, + label = Config.Text['Washing_Rocks'], + useWhileDead = false, + canCancel = true, + controlDisables = { + disableMovement = true, + disableCarMovement = true, + disableMouse = false, + disableCombat = true, + },animation = {}}, function(status) + if not status then + ClearPedTasks(PlayerPedId()) + TriggerServerEvent("esx-mining:receivedReward") + else ClearPedTasks(PlayerPedId()) - TriggerServerEvent("tr-mining:receivedReward") - end, function() - QBCore.Functions.Notify(Config.Text['cancel'], "error") + ESX.ShowNotification(Config.Text['cancel']) + end end) - elseif not stonesbruf then - QBCore.Functions.Notify(Config.Text['error_minerstone'], "error") + else + ESX.ShowNotification(Config.Text['error_minerstone']) end end) - elseif not washingpancheck then + else Wait(500) - QBCore.Functions.Notify(Config.Text['error_washpan'], "error", 3000) + ESX.ShowNotification(Config.Text['error_washpan']) end end) end) -RegisterNetEvent('tr-mining:SmeltIron', function() - QBCore.Functions.TriggerCallback('tr-mining:IronCheck', function(IronCheck) +RegisterNetEvent('esx-mining:SmeltIron', function() + ESX.TriggerServerCallback('esx-mining:IronCheck', function(IronCheck) if IronCheck then local iron = MiningJob.IronTimer - TriggerEvent('animations:client:EmoteCommandStart', {"Warmth"}) - QBCore.Functions.Progressbar("smeltIron", Config.Text['smelt_iron'], iron, false, true, { + --TriggerEvent('animations:client:EmoteCommandStart', {"Warmth"}) + TriggerEvent("mythic_progbar:client:progress", { + name = "smeltIron", + duration = iron, + label = Config.Text['smelt_iron'], + useWhileDead = false, + canCancel = true, + controlDisables = { disableMovement = true, disableCarMovement = true, disableMouse = false, disableCombat = true, - disableInventory = true, - }, {}, {}, {}, function() - TriggerEvent('animations:client:EmoteCommandStart', {"c"}) - TriggerServerEvent('tr-mining:IronBar') - end, function() + },animation = {}}, function(status) + if not status then + -- TriggerEvent('animations:client:EmoteCommandStart', {"c"}) + TriggerServerEvent('esx-mining:IronBar') + else ClearPedTasks(PlayerPedId()) - QBCore.Functions.Notify(Config.Text['cancel'], "error") + ESX.ShowNotification(Config.Text['cancel']) + end end) - elseif not IronCheck then - QBCore.Functions.Notify(Config.Text['error_ironCheck'], "error", 3000) + else + ESX.ShowNotification(Config.Text['error_ironCheck']) end end) end) -RegisterNetEvent('tr-mining:SmeltCopper', function() - QBCore.Functions.TriggerCallback('tr-mining:CopperCheck', function(CopperCheck) +RegisterNetEvent('esx-mining:SmeltCopper', function() + ESX.TriggerServerCallback('esx-mining:CopperCheck', function(CopperCheck) if CopperCheck then local copper = MiningJob.CopperTimer - TriggerEvent('animations:client:EmoteCommandStart', {"Warmth"}) - QBCore.Functions.Progressbar("SmeltCopper", Config.Text['smelt_copper'], copper, false, true, { - disableMovement = true, - disableCarMovement = true, - disableMouse = false, - disableCombat = true, - disableInventory = true, - }, {}, {}, {}, function() - TriggerEvent('animations:client:EmoteCommandStart', {"c"}) - TriggerServerEvent('tr-mining:CopperBar') - end, function() + --TriggerEvent('animations:client:EmoteCommandStart', {"Warmth"}) + TriggerEvent("mythic_progbar:client:progress", { + name = "SmeltCopper", + duration = copper, + label = Config.Text['smelt_copper'], + useWhileDead = false, + canCancel = true, + controlDisables = { + disableMovement = true, + disableCarMovement = true, + disableMouse = false, + disableCombat = true, + },animation = {}}, function(status) + if not status then + --TriggerEvent('animations:client:EmoteCommandStart', {"c"}) + TriggerServerEvent('esx-mining:CopperBar') + else ClearPedTasks(PlayerPedId()) - QBCore.Functions.Notify(Config.Text['cancel'], "error") + ESX.ShowNotification(Config.Text['cancel']) + end end) - elseif not CopperCheck then - QBCore.Functions.Notify(Config.Text['error_goldCheck'], "error", 3000) + else + ESX.ShowNotification(Config.Text['error_copperCheck']) end end) end) -RegisterNetEvent('tr-mining:SmeltGold', function() - QBCore.Functions.TriggerCallback('tr-mining:GoldCheck', function(GoldCheck) +RegisterNetEvent('esx-mining:SmeltGold', function() + ESX.TriggerServerCallback('esx-mining:GoldCheck', function(GoldCheck) if GoldCheck then local gold = MiningJob.GoldTimer - TriggerEvent('animations:client:EmoteCommandStart', {"Warmth"}) - QBCore.Functions.Progressbar("smeltGold", Config.Text['smelt_gold'], gold, false, true, { - disableMovement = true, - disableCarMovement = true, - disableMouse = false, - disableCombat = true, - disableInventory = true, - }, {}, {}, {}, function() - TriggerEvent('animations:client:EmoteCommandStart', {"c"}) - TriggerServerEvent('tr-mining:GoldBar') - end, function() + -- TriggerEvent('animations:client:EmoteCommandStart', {"Warmth"}) + TriggerEvent("mythic_progbar:client:progress", { + name = "smeltGold", + duration = gold, + label = Config.Text['smelt_gold'], + useWhileDead = false, + canCancel = true, + controlDisables = { + disableMovement = true, + disableCarMovement = true, + disableMouse = false, + disableCombat = true, + },animation = {}}, function(status) + if not status then + -- TriggerEvent('animations:client:EmoteCommandStart', {"c"}) + TriggerServerEvent('esx-mining:GoldBar') + else ClearPedTasks(PlayerPedId()) - QBCore.Functions.Notify(Config.Text['cancel'], "error") + ESX.ShowNotification(Config.Text['cancel']) + end end) - elseif not GoldCheck then - QBCore.Functions.Notify(Config.Text['error_goldCheck'], "error", 3000) + else + ESX.ShowNotification(Config.Text['error_goldCheck']) end end) end) CreateThread(function() for k, v in pairs(Config.MiningLocation) do - local shaftZones = BoxZone:Create(v.coords, 3.5, 3, { - name = "mineshaft"..k, + exports['qtarget']:AddBoxZone("Mining"..k, v.coords, 3.5, 3, { + name = "Mining"..k, heading = 15, + debugPoly = false, minZ = v.coords - 1, maxZ = v.coords + 1, - debugPoly = false + }, { + options = { + { + type = "client", + event = "esx-mining:mine", + icon = "Fas Fa-hands", + location = k, + label = "Start Mining", + }, + }, + distance = 3.5 }) - shaftZones:onPlayerInOut(function(isPointInside) - if isPointInside then - miningZone = true - exports['qb-core']:DrawText(Config.Text['MiningAlert'], 'left') - Wait(1500) - exports['qb-core']:HideText() - Wait(1000) - exports['qb-core']:DrawText(Config.Text['StartMining'],'left') - MiningKeyBind(k) - else - inMiningZone = false - miningZone = false - exports['qb-core']:HideText() - end - end) end - exports['qb-target']:AddBoxZone("MinerBoss", MiningLocation.targetZone, 1, 1, { + exports['qtarget']:AddBoxZone("MinerBoss", MiningLocation.targetZone, 1, 1, { name = "MinerBoss", heading = MiningLocation.targetHeading, debugPoly = false, @@ -313,14 +309,14 @@ CreateThread(function() options = { { type = "client", - event = "tr-mining:minermenu", + event = "esx-mining:minermenu", icon = "Fas Fa-hands", label = Config.Text['MenuTarget'], }, }, distance = 1.5 }) - exports['qb-target']:AddBoxZone("PanWasher", WashLocation.targetZone, 1, 1, { + exports['qtarget']:AddBoxZone("PanWasher", WashLocation.targetZone, 1, 1, { name = "PanWasher", heading = WashLocation.targetHeading, debugPoly = false, @@ -330,14 +326,14 @@ CreateThread(function() options = { { type = "client", - event = "tr-mining:panmenu", + event = "esx-mining:panmenu", icon = "Fas Fa-hands", label = Config.Text['Menu_pTarget'], }, }, distance = 1.5 }) - exports['qb-target']:AddBoxZone("Water", vector3(54.77, 3160.31, 25.62), 38.2, 8, { + exports['qtarget']:AddBoxZone("Water", vector3(54.77, 3160.31, 25.62), 38.2, 8, { name = "Water", heading = 155, debugPoly = false, @@ -347,14 +343,14 @@ CreateThread(function() options = { { type = "client", - event = "tr-mining:washingrocks", + event = "esx-mining:washingrocks", icon = "Fas Fa-hands", label = Config.Text['Washing_Target'], }, }, distance = 3.0 }) - exports['qb-target']:AddBoxZone("smelt", vector3(1086.38, -2003.69, 31.42), 3.8, 3, { + exports['qtarget']:AddBoxZone("smelt", vector3(1086.38, -2003.69, 31.42), 3.8, 3, { name = "smelt", heading = 319, debugPoly = false, @@ -364,14 +360,14 @@ CreateThread(function() options = { { type = "client", - event = "tr-mining:smeltmenu", + event = "esx-mining:smeltmenu", icon = "Fas Fa-hands", label = Config.Text['Smeth_Rocks'], }, }, distance = 1.5 }) - exports['qb-target']:AddBoxZone("Seller", SellLocation.targetZone, 1, 1, { + exports['qtarget']:AddBoxZone("Seller", SellLocation.targetZone, 1, 1, { name = "Seller", heading = SellLocation.targetHeading, debugPoly = false, @@ -381,7 +377,7 @@ CreateThread(function() options = { { type = "server", - event = "tr-mining:Seller", + event = "esx-mining:Seller", icon = "Fas Fa-hands", label = Config.Text['Seller'], }, diff --git a/client/peds.lua b/client/peds.lua index 4b14328..b58c900 100644 --- a/client/peds.lua +++ b/client/peds.lua @@ -1,11 +1,10 @@ -local QBCore = exports['qb-core']:GetCoreObject() -local ClassicMiner = MiningLocation.coords +local ClassicMiner = Config.Blips.MiningLocation.coords local ClassicPed = MiningJob.Miner local ClassicMHash = MiningJob.MinerHash local ClasWashericPed = MiningJob.Washer local notClasHashsic = MiningJob.WasherHash -local TRonTop = WashLocation.coords -local ClassicSeller = SellLocation.coords +local TRonTop = Config.Blips.WashLocation.coords +local ClassicSeller = Config.Blips.SellLocation.coords CreateThread(function() RequestModel( GetHashKey( ClassicPed ) ) diff --git a/config.lua b/config.lua index 843bcee..45c2e30 100644 --- a/config.lua +++ b/config.lua @@ -4,49 +4,51 @@ Config.UseBlips = true -- True / fa Config.Timeout = 20 * (60 * 1000) -- 20 minutes --Blips Config +Config.Blips = { MiningLocation = { targetZone = vector3(-600.57, 2092.49, 130.33), -- qb-target vector targetHeading = 273.47, -- qb-target box zone coords = vector4(-600.57, 2092.49, 130.33, 339.52), -- Move Location (Ped and blip) - SetBlipSprite = 414, -- Blip Icon (https://docs.fivem.net/docs/game-references/blips/) - SetBlipDisplay = 6, -- Blip Behavior (https://docs.fivem.net/natives/?_0x9029B2F3DA924928) - SetBlipScale = 0.85, -- Blip Size - SetBlipColour = 21, -- Blip Color - BlipLabel = "Mine Shaft", -- Blip Label + Sprite = 414, -- Blip Icon (https://docs.fivem.net/docs/game-references/blips/) + Display = 6, -- Blip Behavior (https://docs.fivem.net/natives/?_0x9029B2F3DA924928) + Scale = 0.85, -- Blip Size + Colour = 21, -- Blip Color + Label = "Mine Shaft", -- Blip Label minZ = 129.42, -- Max Z maxZ = 132.42, -- Max Z -} +}, WashLocation = { targetZone = vector3(77.17, 3150.86, 28.79), targetHeading = 80.46, coords = vector4(77.17, 3150.86, 28.79, 80.46), - SetBlipSprite = 162, - SetBlipDisplay = 6, - SetBlipScale = 0.85, - SetBlipColour = 26, - BlipLabel = "Mine Washing Location", + Sprite = 162, + Display = 6, + Scale = 0.85, + Colour = 26, + Label = "Mine Washing Location", minZ = 27, maxZ = 31, -} +}, SmeltLocation = { coords = vector4(1090.11, -1991.51, 32.27, 56.22), - SetBlipSprite = 162, - SetBlipDisplay = 6, - SetBlipScale = 0.85, - SetBlipColour = 36, - BlipLabel = "Smelt Factory", -} + Sprite = 162, + Display = 6, + Scale = 0.85, + Colour = 36, + Label = "Smelt Factory", +}, SellLocation = { targetZone = vector3(579.11, -2804.96, 5.06), targetHeading = 242.63, coords = vector4(579.11, -2804.96, 5.06, 242.63), - SetBlipSprite = 431, - SetBlipDisplay = 6, - SetBlipScale = 0.85, - SetBlipColour = 28, - BlipLabel = "Material Seller", + Sprite = 431, + Display = 6, + Scale = 0.85, + Colour = 28, + Label = "Material Seller", minZ = 3, maxZ = 7, +}, } --Job Config MiningJob = { @@ -93,8 +95,6 @@ MiningJob = { GoldBarsMax = 2, } - -vector4(77.17, 3150.86, 29.79, 80.46) Config.MiningLocation = { [1] = { ["coords"] = vector3(-590.57, 2073.85, 131.3), @@ -174,30 +174,14 @@ Config.MiningLocation = { } Config.Sell = { - ["mining_washedstone"] = { - ["price"] = math.random(5, 10) -- Seller Price - }, - ["mining_stone"] = { - ["price"] = 2 - }, - ["mining_ironfragment"] = { - ["price"] = math.random(35, 45) - }, - ["mining_ironbar"] = { - ["price"] = math.random(75, 90) - }, - ["mining_goldnugget"] = { - ["price"] = math.random(75, 80) - }, - ["mining_goldbar"] = { - ["price"] = math.random(110, 125) - }, - ["mining_copperfragment"] = { - ["price"] = math.random(25, 35) - }, - ["mining_copperbar"] = { - ["price"] = math.random(50, 65) - }, + mining_washedstone = math.random(5, 10), -- Seller Price + mining_stone = math.random(10, 20), + mining_ironfragment = math.random(35, 45), + mining_ironbar = math.random(75, 90), + mining_goldnugget = math.random(60, 70), + mining_goldbar = math.random(120, 200), + mining_copperfragment = math.random(25, 35), + mining_copperbar = math.random(50, 65), } --- Config Alerts diff --git a/fxmanifest.lua b/fxmanifest.lua index bdfd912..efcf9b9 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -1,9 +1,9 @@ fx_version 'cerulean' game 'gta5' -author 'TRClassic#0001' -description 'Mining script for QBCore' -version '1.0.1' +author 'TRClassic, Mycroft, Benzo' +description 'Mining script for ESX' +version '2.0.1' client_script { '@PolyZone/client.lua', @@ -13,12 +13,9 @@ client_script { server_scripts {'server/*.lua'} -shared_scripts {'config.lua'} +shared_scripts {'@es_extended/imports.lua','config.lua'} dependencies { 'PolyZone', - 'qb-menu', - 'qb-target' + 'qtarget' } - -this_is_a_map 'yes' \ No newline at end of file diff --git a/items.sql b/items.sql new file mode 100644 index 0000000..cd05645 --- /dev/null +++ b/items.sql @@ -0,0 +1,14 @@ + +INSERT INTO `items` (`name`, `label`, `weight`, `rare`, `can_remove`) VALUES + ('mining_pickaxe', 'Pickaxe', 1, 0, 1), + ('mining_pan', 'Pan', 1, 0, 1), + ('mining_washedstone', 'Washed Stone', 1, 0, 1), + ('mining_ironfragment', 'Iron Nugget', 1, 0, 1), + ('mining_ironbar', 'Iron Bar', 1, 0, 1), + ('mining_goldnugget', 'Gold Nugget', 1, 0, 1), + ('mining_goldbar', 'Gold Bar', 1, 0, 1), + ('mining_copperfragment', 'Copper Fragment', 1, 0, 1), + ('mining_copperbar', 'Copper Bar', 1, 0, 1), + ('mining_stone', 'Dirty Stone ', 1, 0, 1); + + diff --git a/server/main.lua b/server/main.lua index 2dcaaba..7593d42 100644 --- a/server/main.lua +++ b/server/main.lua @@ -1,4 +1,3 @@ -local QBCore = exports['qb-core']:GetCoreObject() local mining = false MiningMaterial = { @@ -8,44 +7,42 @@ MiningMaterial = { {'mining_goldnugget', math.random(MiningJob.GoldNugMin, MiningJob.GoldNugMax)}, -- Rare } -RegisterNetEvent('tr-mining:Seller', function() +RegisterNetEvent('esx-mining:Seller', function() local source = source local price = 0 - local Player = QBCore.Functions.GetPlayer(source) - if Player.PlayerData.items ~= nil and next(Player.PlayerData.items) ~= nil then - for k, v in pairs(Player.PlayerData.items) do - if Player.PlayerData.items[k] ~= nil then - if Config.Sell[Player.PlayerData.items[k].name] ~= nil then - price = price + (Config.Sell[Player.PlayerData.items[k].name].price * Player.PlayerData.items[k].amount) - Player.Functions.RemoveItem(Player.PlayerData.items[k].name, Player.PlayerData.items[k].amount, k) - TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items[Player.PlayerData.items[k].name], "remove") - end - end + local xPlayer = ESX.GetPlayerFromId(source) + for k,v in pairs(Config.Sell) do + local item = xPlayer.getInventoryItem(k) + if item and item.count >= 1 then + price = price + (v * item.count) + xPlayer.removeInventoryItem(k, item.count) end - Player.Functions.AddMoney("cash", price) - TriggerClientEvent('QBCore:Notify', source, Config.Text["successfully_sold"]) - end + end + if price > 0 then + xPlayer.addMoney(price) + xPlayer.showNotification(Config.Alerts["successfully_sold"], true, false, 140) + else + xPlayer.showNotification(Config.Alerts["no_item"]) + end end) -RegisterNetEvent('tr-mining:BuyPickaxe', function() +RegisterNetEvent('esx-mining:BuyPickaxe', function() local source = source - local Player = QBCore.Functions.GetPlayer(tonumber(source)) - local TRClassicPickaxe = MiningJob.PickAxePrice - local pickaxe = Player.Functions.GetItemByName('mining_pickaxe') - if not pickaxe then - Player.Functions.AddItem('mining_pickaxe', 1) - TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items['mining_pickaxe'], "add") - Player.Functions.RemoveMoney("cash", TRClassicPickaxe) - TriggerClientEvent('QBCore:Notify', source, Config.Text["Pickaxe_Bought"]) - elseif pickaxe then - TriggerClientEvent('QBCore:Notify', source, Config.Text["Pickaxe_Check"], 'error') + local xPlayer = ESX.GetPlayerFromId(source) + local pickaxe = xPlayer.getInventoryItem('mining_pickaxe').count + if pickaxe < 1 then + xPlayer.addInventoryItem('mining_pickaxe', 1) + xPlayer.removeMoney(MiningJob.PickAxePrice) + xPlayer.showNotification(Config.Text["Pickaxe_Bought"]) + else + xPlayer.showNotification(Config.Text["Pickaxe_Check"]) end end) -QBCore.Functions.CreateCallback('tr-mining:pickaxe', function(source, cb) - local Player = QBCore.Functions.GetPlayer(source) - if Player ~= nil then - if Player.Functions.GetItemByName("mining_pickaxe") ~= nil then +ESX.RegisterServerCallback('esx-mining:pickaxe', function(source, cb) + local xPlayer = ESX.GetPlayerFromId(source) + if xPlayer then + if xPlayer.getInventoryItem("mining_pickaxe").count >= 1 then cb(true) else cb(false) @@ -53,25 +50,23 @@ QBCore.Functions.CreateCallback('tr-mining:pickaxe', function(source, cb) end end) -RegisterNetEvent('tr-mining:BuyWash', function() +RegisterNetEvent('esx-mining:BuyWash', function() local source = source - local Player = QBCore.Functions.GetPlayer(tonumber(source)) - local TRClassicPan = MiningJob.WashPanPrice - local pan = Player.Functions.GetItemByName('mining_pan') - if not pan then - Player.Functions.AddItem('mining_pan', 1) - TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items['mining_pan'], "add") - Player.Functions.RemoveMoney("cash", TRClassicPan) - TriggerClientEvent('QBCore:Notify', source, Config.Text["Pan_Bought"]) - elseif pan then - TriggerClientEvent('QBCore:Notify', source, Config.Text["Pan_check"], 'error') + local xPlayer = ESX.GetPlayerFromId(source) + local pan = xPlayer.getInventoryItem("mining_pan").count + if pan < 1 then + xPlayer.addInventoryItem('mining_pan', 1) + xPlayer.removeMoney(MiningJob.WashPanPrice) + xPlayer.showNotification(Config.Text["Pan_Bought"]) + else + xPlayer.showNotification(Config.Text["Pan_check"]) end end) -QBCore.Functions.CreateCallback('tr-mining:washpan', function(source, cb) - local Player = QBCore.Functions.GetPlayer(source) - if Player ~= nil then - if Player.Functions.GetItemByName("mining_pan") ~= nil then +ESX.RegisterServerCallback('esx-mining:washpan', function(source, cb) + local xPlayer = ESX.GetPlayerFromId(source) + if xPlayer then + if xPlayer.getInventoryItem("mining_pan").count >= 1 then cb(true) else cb(false) @@ -79,47 +74,42 @@ QBCore.Functions.CreateCallback('tr-mining:washpan', function(source, cb) end end) -RegisterServerEvent('tr-mining:receivedStone', function() +RegisterServerEvent('esx-mining:receivedStone', function() local source = source - local Player = QBCore.Functions.GetPlayer(tonumber(source)) + local xPlayer = ESX.GetPlayerFromId(source) local mineStone = math.random(MiningJob.StoneMin, MiningJob.StoneMax) - Player.Functions.AddItem('mining_stone', mineStone) - TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items['mining_stone'], "add") + print(mineStone) + xPlayer.addInventoryItem('mining_stone', mineStone) end) -RegisterNetEvent('tr-mining:receivedReward', function() +RegisterNetEvent('esx-mining:receivedReward', function() local source = source - local Player = QBCore.Functions.GetPlayer(tonumber(source)) - local minerstone = Player.Functions.GetItemByName('mining_stone') + local xPlayer = ESX.GetPlayerFromId(source) + local minerstone = xPlayer.getInventoryItem("mining_stone") local ChanceItem = MiningMaterial[math.random(1, #MiningMaterial)] - if not minerstone then - TriggerClientEvent('QBCore:Notify', source, Config.Text['error_minerstone']) - end - local amount = minerstone.amount + + local amount = minerstone.count if amount >= 1 then amount = 1 else return false end - if not Player.Functions.RemoveItem('mining_stone', amount) then - TriggerClientEvent('QBCore:Notify', source, Config.Text['error_minerstone']) + + if minerstone.count >= amount then + xPlayer.removeInventoryItem('minerstone', amount) + xPlayer.addInventoryItem(ChanceItem[1], ChanceItem[2]) end - TriggerClientEvent('invenotry:client:ItemBox', source, QBCore.Shared.Items['error_minerstone'], "remove") - Wait(1000) - TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items[ChanceItem[1]], "add") - Player.Functions.AddItem(ChanceItem[1], ChanceItem[2] ) - end) -RegisterNetEvent('tr-mining:setMiningStage', function(stage, state, k) +RegisterNetEvent('esx-mining:setMiningStage', function(stage, state, k) Config.MiningLocation[k][stage] = state - TriggerClientEvent('tr-mining:getMiningstage', -1, stage, state, k) + TriggerClientEvent('esx-mining:getMiningstage', -1, stage, state, k) end) -QBCore.Functions.CreateCallback('tr-mining:stonesbruf', function(source, cb) - local Player = QBCore.Functions.GetPlayer(source) - if Player ~= nil then - if Player.Functions.GetItemByName("mining_stone") ~= nil then +ESX.RegisterServerCallback('esx-mining:stonesbruf', function(source, cb) + local xPlayer = ESX.GetPlayerFromId(source) + if xPlayer then + if xPlayer.getInventoryItem("mining_stone").count >= 1 then cb(true) else cb(false) @@ -128,54 +118,45 @@ QBCore.Functions.CreateCallback('tr-mining:stonesbruf', function(source, cb) end) -RegisterNetEvent('tr-mining:setMiningTimer', function() +RegisterNetEvent('esx-mining:setMiningTimer', function() if not mining then mining = true CreateThread(function() Wait(Config.Timeout) for k, v in pairs(Config.MiningLocations) do Config.MiningLocations[k]["isMined"] = false - TriggerClientEvent('tr-mining:getMiningstage', -1, 'isMined', false, k) + TriggerClientEvent('esx-mining:getMiningstage', -1, 'isMined', false, k) end mining = false end) end end) -RegisterServerEvent('tr-mining:IronBar', function() +RegisterServerEvent('esx-mining:IronBar', function() local source = source - local Player = QBCore.Functions.GetPlayer(tonumber(source)) - local TRIronCheck = Player.Functions.GetItemByName('mining_ironfragment') + local xPlayer = ESX.GetPlayerFromId(source) + local IronCheck = xPlayer.getInventoryItem('mining_ironfragment') local IronSmeltAmount = math.random(MiningJob.SmeltIronMin, MiningJob.SmeltIronMax) local IronBarsReceived = math.random(MiningJob.IronBarsMin, MiningJob.IronBarsMax) - if not TRIronCheck then - TriggerClientEvent('QBCore:Notify', source, Config.Text['error_ironCheck']) - return false - end - local amount = TRIronCheck.amount + local amount = IronCheck.count if amount >= 1 then amount = IronSmeltAmount else return false end - if not Player.Functions.RemoveItem('mining_ironfragment', amount) then - TriggerClientEvent('QBCore:Notify', source, Config.Text['itemamount']) - return false + if IronCheck.count >= amount then + xPlayer.removeInventoryItem('mining_ironfragment', amount) + xPlayer.addInventoryItem('mining_ironbar', IronBarsReceived) + xPlayer.showNotification(Config.Text["ironSmelted"] ..IronSmeltAmount.. Config.Text["ironSmeltedMiddle"] ..IronBarsReceived.. Config.Text["ironSmeltedEnd"]) end - - TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items['mining_ironfragment'], "remove") - TriggerClientEvent('QBCore:Notify', source, Config.Text["ironSmelted"] ..IronSmeltAmount.. Config.Text["ironSmeltedMiddle"] ..IronBarsReceived.. Config.Text["ironSmeltedEnd"]) - Wait(750) - Player.Functions.AddItem('mining_ironbar', IronBarsReceived) - TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items['mining_ironbar'], "add") end) -QBCore.Functions.CreateCallback('tr-mining:IronCheck', function(source, cb) - local Player = QBCore.Functions.GetPlayer(source) - if Player ~= nil then - if Player.Functions.GetItemByName("mining_ironfragment") ~= nil then +ESX.RegisterServerCallback('esx-mining:IronCheck', function(source, cb) + local xPlayer = ESX.GetPlayerFromId(source) + if xPlayer then + if xPlayer.getInventoryItem("mining_ironfragment").count >= 1 then cb(true) else cb(false) @@ -183,70 +164,52 @@ QBCore.Functions.CreateCallback('tr-mining:IronCheck', function(source, cb) end end) -RegisterServerEvent('tr-mining:CopperBar', function() +RegisterServerEvent('esx-mining:CopperBar', function() local source = source - local Player = QBCore.Functions.GetPlayer(tonumber(source)) - local TRCopperBars = Player.Functions.GetItemByName('mining_copperfragment') + local xPlayer = ESX.GetPlayerFromId(source) + local CopperBars = xPlayer.getInventoryItem('mining_copperfragment') local CopperSmeltAmount = math.random(MiningJob.SmeltCopperMin, MiningJob.SmeltCopperMin) local CopperBarsReceived = math.random(MiningJob.CopperBarsMin, MiningJob.CopperBarsMax) - if not TRCopperBars then - TriggerClientEvent('QBCore:Notify', source, Config.Text['error_copperCheck']) - return false - end - local amount = TRCopperBars.amount + local amount = CopperBars.count if amount >= 1 then amount = CopperSmeltAmount else return false end - if not Player.Functions.RemoveItem('mining_copperfragment', amount) then - TriggerClientEvent('QBCore:Notify', source, Config.Text['itemamount']) - return false + if CopperBars.count >= amount then + xPlayer.removeInventoryItem('mining_copperfragment', amount) + xPlayer.addInventoryItem('mining_copperbar', CopperBarsReceived) + xPlayer.showNotification(Config.Text["CopperSmelted"] ..CopperSmeltAmount.. Config.Text["CopperSmeltedMiddle"] ..CopperBarsReceived.. Config.Text["CopperSmeltedEnd"]) end - - TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items['mining_copperfragment'], "remove") - TriggerClientEvent('QBCore:Notify', source, Config.Text["CopperSmelted"] ..CopperSmeltAmount.. Config.Text["CopperSmeltedMiddle"] ..CopperBarsReceived.. Config.Text["CopperSmeltedEnd"]) - Wait(750) - Player.Functions.AddItem('mining_copperbar', CopperBarsReceived) - TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items['mining_copperbar'], "add") end) -RegisterServerEvent('tr-mining:GoldBar', function() +RegisterServerEvent('esx-mining:GoldBar', function() local source = source - local Player = QBCore.Functions.GetPlayer(tonumber(source)) - local TRGoldenTicket = Player.Functions.GetItemByName('mining_goldnugget') - local GoldSmeltAmount = math.random(MiningJob.SmeltGoldMin, MiningJob.SmeltGoldMax) - local GoldBarRecevied = math.random(MiningJob.GoldBarsMin, MiningJob.GoldBarsMax) - if not TRGoldenTicket then - TriggerClientEvent('QBCore:Notify', source, Config.Text['error_copperCheck']) - return false - end + local xPlayer = ESX.GetPlayerFromId(source) + local Gold = xPlayer.getInventoryItem('mining_goldnugget') + local GoldSmeltAmount = math.random(MiningJob.SmeltCopperMin, MiningJob.SmeltCopperMin) + local GoldBarsReceived = math.random(MiningJob.CopperBarsMin, MiningJob.CopperBarsMax) - local amount = TRGoldenTicket.amount + local amount = Gold.count if amount >= 1 then amount = GoldSmeltAmount else return false end - if not Player.Functions.RemoveItem('mining_goldnugget', amount) then - TriggerClientEvent('QBCore:Notify', source, Config.Text['itemamount']) - return false + if Gold.count >= amount then + xPlayer.removeInventoryItem('mining_goldnugget', amount) + xPlayer.addInventoryItem('mining_goldbar', CopperBarsReceived) + xPlayer.showNotification(Config.Text["GoldSmelted"] ..CopperSmeltAmount.. Config.Text["GoldSmeltedMiddle"] ..CopperBarsReceived.. Config.Text["GoldSmeltedEnd"]) end - - TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items['mining_goldnugget'], "remove") - TriggerClientEvent('QBCore:Notify', source, Config.Text["GoldSmelted"] ..GoldSmeltAmount.. Config.Text["GoldSmeltedMiddle"] ..GoldBarRecevied.. Config.Text["GoldSmeltedEnd"]) - Wait(750) - Player.Functions.AddItem('mining_goldbar', GoldBarRecevied) - TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items['mining_goldbar'], "add") end) -QBCore.Functions.CreateCallback('tr-mining:IronCheck', function(source, cb) - local Player = QBCore.Functions.GetPlayer(source) - if Player ~= nil then - if Player.Functions.GetItemByName("mining_ironfragment") ~= nil then +ESX.RegisterServerCallback('esx-mining:IronCheck', function(source, cb) + local xPlayer = ESX.GetPlayerFromId(source) + if xPlayer ~= nil then + if xPlayer.getInventoryItem("mining_ironfragment").count >= 1 then cb(true) else cb(false) @@ -254,20 +217,21 @@ QBCore.Functions.CreateCallback('tr-mining:IronCheck', function(source, cb) end end) -QBCore.Functions.CreateCallback('tr-mining:GoldCheck', function(source, cb) - local Player = QBCore.Functions.GetPlayer(source) - if Player ~= nil then - if Player.Functions.GetItemByName("mining_goldnugget") ~= nil then +ESX.RegisterServerCallback('esx-mining:GoldCheck', function(source, cb) + local xPlayer = ESX.GetPlayerFromId(source) + if xPlayer ~= nil then + if xPlayer.getInventoryItem("mining_goldnugget").count >= 1 then cb(true) else cb(false) end end end) -QBCore.Functions.CreateCallback('tr-mining:CopperCheck', function(source, cb) - local Player = QBCore.Functions.GetPlayer(source) - if Player ~= nil then - if Player.Functions.GetItemByName("mining_copperfragment") ~= nil then + +ESX.RegisterServerCallback('esx-mining:CopperCheck', function(source, cb) + local xPlayer = ESX.GetPlayerFromId(source) + if xPlayer ~= nil then + if xPlayer.getInventoryItem("mining_copperfragment").count >= 1 then cb(true) else cb(false) @@ -279,5 +243,17 @@ AddEventHandler('onResourceStart', function(resourceName) if (GetCurrentResourceName() ~= resourceName) then return end - print("^0\n ------------------------------------------------------------------------------------------------------------------------------\n ^1\n ████████╗██████╗ ███╗ ███╗██╗███╗ ██╗██╗███╗ ██╗ ██████╗ \t \n ╚══██╔══╝██╔══██╗ ████╗ ████║██║████╗ ██║██║████╗ ██║██╔════╝ \t \n ██║ ██████╔╝█████╗██╔████╔██║██║██╔██╗ ██║██║██╔██╗ ██║██║ ███╗\t \n ██║ ██╔══██╗╚════╝██║╚██╔╝██║██║██║╚██╗██║██║██║╚██╗██║██║ ██║ \t \n ██║ ██║ ██║ ██║ ╚═╝ ██║██║██║ ╚████║██║██║ ╚████║╚██████╔╝\t \n ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝╚═╝╚═╝ ╚═══╝ ╚═════╝ \t \n \n \n ^1Discord ^5 --> ^0https://discord.gg/zRCdhENsHG ^1Author^5: ^0TRClassic#0001 \n \n------------------------------------------------------------------------------------------------------------------------------ \n ") + print("--------------------------------------------------------------------------") + print("^4███████╗ ██████╗██╗ ██╗  ███╗ ███╗██╗███╗ ██╗██╗███╗ ██╗ ██████╗ |") + print("^4██╔════╝██╔════╝╚██╗██╔╝  ████╗ ████║██║████╗ ██║██║████╗ ██║██╔════╝ |") + print("^4█████╗ ╚█████╗ ╚███╔╝   ██╔████╔██║██║██╔██╗██║██║██╔██╗██║██║ ██╗ |") + print("^3██╔══╝ ╚═══██╗ ██╔██╗   ██║╚██╔╝██║██║██║╚████║██║██║╚████║██║ ╚██╗ |") + print("^3███████╗██████╔╝██╔╝╚██╗  ██║ ╚═╝ ██║██║██║ ███║██║██║ ╚███║╚██████╔╝ |") + print("^3╚══════╝╚═════╝ ╚═╝ ╚═╝  ╚═╝ ╚═╝╚═╝╚═╝ ╚══╝╚═╝╚═╝ ╚══╝ ╚═════╝ |") + print("^7----------------------------------------------------------------------------------") + print("^7 Converted By Mycroft (Manager of ESX-Framework) & Benzo (ESX Community Manager) |") + print("^7 Website: https://docs.esx-framework.org |") + print("^7 TRClassic: https://dsc.gg/trclassic |") + print("^1 Original Script: https://github.com/trclassic92/tr-mining ^7|") + print("----------------------------------------------------------------------------------") end) \ No newline at end of file