From 565af10b6caa123f197aa26b7f470deb86fc68a3 Mon Sep 17 00:00:00 2001 From: ElPumpo Date: Mon, 24 Sep 2018 17:31:33 +0200 Subject: [PATCH] mysql-async v3.0.1 support --- client/main.lua | 26 ++++++++++++++------------ server/main.lua | 24 ++---------------------- 2 files changed, 16 insertions(+), 34 deletions(-) diff --git a/client/main.lua b/client/main.lua index 797c61eb..c3c287f7 100644 --- a/client/main.lua +++ b/client/main.lua @@ -1,10 +1,21 @@ +local Keys = { + ["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57, + ["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177, + ["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18, + ["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182, + ["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81, + ["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70, + ["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178, + ["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173, + ["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118 +} + ESX = nil local HasAlreadyEnteredMarker = false local LastZone = nil local CurrentAction = nil local CurrentActionMsg = '' local CurrentActionData = {} -local PlayerData = {} Citizen.CreateThread(function() while ESX == nil do @@ -13,7 +24,6 @@ Citizen.CreateThread(function() end Citizen.Wait(5000) - PlayerData = ESX.GetPlayerData() ESX.TriggerServerCallback('esx_shops:requestDBItems', function(ShopItems) for k,v in pairs(ShopItems) do @@ -23,8 +33,6 @@ Citizen.CreateThread(function() end) function OpenShopMenu(zone) - PlayerData = ESX.GetPlayerData() - local elements = {} for i=1, #Config.Zones[zone].Items, 1 do local item = Config.Zones[zone].Items[i] @@ -156,21 +164,15 @@ Citizen.CreateThread(function() Citizen.Wait(10) if CurrentAction ~= nil then + ESX.ShowHelpNotification(CurrentActionMsg) - SetTextComponentFormat('STRING') - AddTextComponentString(CurrentActionMsg) - DisplayHelpTextFromStringLabel(0, 0, 1, -1) - - if IsControlJustReleased(0, 38) then - + if IsControlJustReleased(0, Keys['E']) then if CurrentAction == 'shop_menu' then OpenShopMenu(CurrentActionData.zone) end CurrentAction = nil - end - else Citizen.Wait(500) end diff --git a/server/main.lua b/server/main.lua index ab8e13f3..b674b281 100644 --- a/server/main.lua +++ b/server/main.lua @@ -1,26 +1,10 @@ ESX = nil local ShopItems = {} -local hasSqlRun = false TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) -- Load items -AddEventHandler('onMySQLReady', function() - hasSqlRun = true - LoadShop() -end) - --- extremely useful when restarting script mid-game -Citizen.CreateThread(function() - Citizen.Wait(2000) -- hopefully enough for connection to the SQL server - - if not hasSqlRun then - LoadShop() - hasSqlRun = true - end -end) - -function LoadShop() +MySQL.ready(function() local itemResult = MySQL.Sync.fetchAll('SELECT * FROM items') local shopResult = MySQL.Sync.fetchAll('SELECT * FROM shops') @@ -51,13 +35,9 @@ function LoadShop() limit = itemInformation[shopResult[i].item].limit }) end -end +end) ESX.RegisterServerCallback('esx_shops:requestDBItems', function(source, cb) - if not hasSqlRun then - TriggerClientEvent('esx:showNotification', source, 'The shop database has not been loaded yet, try again in a few moments.') - end - cb(ShopItems) end)