From 538a97d3f348625325d637058778efd2fc921306 Mon Sep 17 00:00:00 2001 From: ElPumpo Date: Wed, 11 Jul 2018 12:16:58 +0200 Subject: [PATCH] Fixed max slider when item limit is unlimited --- __resource.lua | 5 ++++- client/main.lua | 51 ++++++++++++++++++++++++++----------------------- server/main.lua | 11 ++++++++++- 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/__resource.lua b/__resource.lua index 7c03c770..ec5f51b3 100644 --- a/__resource.lua +++ b/__resource.lua @@ -19,6 +19,7 @@ client_scripts { server_scripts { '@es_extended/locale.lua', + '@mysql-async/lib/MySQL.lua', 'locales/de.lua', 'locales/br.lua', 'locales/en.lua', @@ -26,7 +27,9 @@ server_scripts { 'locales/fr.lua', 'locales/es.lua', 'locales/sv.lua', - '@mysql-async/lib/MySQL.lua', + 'config.lua', 'server/main.lua' } + +dependency 'es_extended' diff --git a/client/main.lua b/client/main.lua index 935eebaa..1004b61a 100644 --- a/client/main.lua +++ b/client/main.lua @@ -91,16 +91,16 @@ end) -- Create Blips Citizen.CreateThread(function() for k,v in pairs(Config.Zones) do - for i = 1, #v.Pos, 1 do - local blip = AddBlipForCoord(v.Pos[i].x, v.Pos[i].y, v.Pos[i].z) - SetBlipSprite (blip, 52) - SetBlipDisplay(blip, 4) - SetBlipScale (blip, 1.0) - SetBlipColour (blip, 2) - SetBlipAsShortRange(blip, true) - BeginTextCommandSetBlipName("STRING") - AddTextComponentString(_U('shops')) - EndTextCommandSetBlipName(blip) + for i = 1, #v.Pos, 1 do + local blip = AddBlipForCoord(v.Pos[i].x, v.Pos[i].y, v.Pos[i].z) + SetBlipSprite (blip, 52) + SetBlipDisplay(blip, 4) + SetBlipScale (blip, 1.0) + SetBlipColour (blip, 2) + SetBlipAsShortRange(blip, true) + BeginTextCommandSetBlipName("STRING") + AddTextComponentString(_U('shops')) + EndTextCommandSetBlipName(blip) end end end) @@ -151,24 +151,27 @@ end) -- Key Controls Citizen.CreateThread(function() - while true do - Citizen.Wait(10) - if CurrentAction ~= nil then + while true do + Citizen.Wait(10) - SetTextComponentFormat('STRING') - AddTextComponentString(CurrentActionMsg) - DisplayHelpTextFromStringLabel(0, 0, 1, -1) + if CurrentAction ~= nil then - if IsControlJustReleased(0, 38) then + SetTextComponentFormat('STRING') + AddTextComponentString(CurrentActionMsg) + DisplayHelpTextFromStringLabel(0, 0, 1, -1) - if CurrentAction == 'shop_menu' then - OpenShopMenu(CurrentActionData.zone) - end + if IsControlJustReleased(0, 38) then - CurrentAction = nil + if CurrentAction == 'shop_menu' then + OpenShopMenu(CurrentActionData.zone) + end - end + CurrentAction = nil - end - end + end + + else + Citizen.Wait(500) + end + end end) \ No newline at end of file diff --git a/server/main.lua b/server/main.lua index f7099870..ab8e13f3 100644 --- a/server/main.lua +++ b/server/main.lua @@ -12,7 +12,7 @@ end) -- extremely useful when restarting script mid-game Citizen.CreateThread(function() - Citizen.Wait(20000) -- hopefully enough for connection to the SQL server + Citizen.Wait(2000) -- hopefully enough for connection to the SQL server if not hasSqlRun then LoadShop() @@ -26,6 +26,7 @@ function LoadShop() local itemInformation = {} for i=1, #itemResult, 1 do + if itemInformation[itemResult[i].name] == nil then itemInformation[itemResult[i].name] = {} end @@ -39,6 +40,10 @@ function LoadShop() ShopItems[shopResult[i].store] = {} end + if itemInformation[shopResult[i].item].limit == -1 then + itemInformation[shopResult[i].item].limit = 30 + end + table.insert(ShopItems[shopResult[i].store], { label = itemInformation[shopResult[i].item].label, item = shopResult[i].item, @@ -62,6 +67,8 @@ AddEventHandler('esx_shops:buyItem', function(itemName, amount, zone) local xPlayer = ESX.GetPlayerFromId(_source) local sourceItem = xPlayer.getInventoryItem(itemName) + amount = ESX.Round(amount) + -- is the player trying to exploit? if amount < 0 then print('esx_shops: ' .. xPlayer.identifier .. ' attempted to exploit the shop!') @@ -71,6 +78,7 @@ AddEventHandler('esx_shops:buyItem', function(itemName, amount, zone) -- get price local price = 0 local itemLabel = '' + for i=1, #ShopItems[zone], 1 do if ShopItems[zone][i].item == itemName then price = ShopItems[zone][i].price @@ -78,6 +86,7 @@ AddEventHandler('esx_shops:buyItem', function(itemName, amount, zone) break end end + price = price * amount -- can the player afford this item?