From d43ff45bfa9882dcf2f6bf5ef1f68dc1e7fe08fe Mon Sep 17 00:00:00 2001 From: ElPumpo Date: Mon, 30 Apr 2018 17:21:59 +0200 Subject: [PATCH] Fixed cheating exploit, empty shop bug, broken translation --- client/main.lua | 11 ++++--- config.lua | 79 ++++++++++++++++++++++++------------------------- locales/br.lua | 6 ++-- server/main.lua | 61 +++++++++++++++++++------------------- 4 files changed, 77 insertions(+), 80 deletions(-) diff --git a/client/main.lua b/client/main.lua index 5b818efb..e9392bd1 100644 --- a/client/main.lua +++ b/client/main.lua @@ -10,25 +10,24 @@ Citizen.CreateThread(function() TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) Citizen.Wait(0) end -end) - -AddEventHandler('onClientMapStart', function() - + + Citizen.Wait(5000) + ESX.TriggerServerCallback('esx_shops:requestDBItems', function(ShopItems) for k,v in pairs(ShopItems) do Config.Zones[k].Items = v end end) - end) + function OpenShopMenu(zone) local elements = {} for i=1, #Config.Zones[zone].Items, 1 do local item = Config.Zones[zone].Items[i] table.insert(elements, { - label = item.label .. ' - ' .. item.price .. '$', + label = item.label .. ' - $' .. item.price .. '', realLabel = item.label, value = item.name, price = item.price diff --git a/config.lua b/config.lua index 10a1f089..e1d07b2b 100644 --- a/config.lua +++ b/config.lua @@ -1,50 +1,49 @@ -Config = {} - +Config = {} Config.DrawDistance = 100 Config.Size = {x = 1.5, y = 1.5, z = 1.5} Config.Color = {r = 0, g = 128, b = 255} Config.Type = 1 -Config.Locale = 'en' +Config.Locale = 'en' Config.Zones = { - TwentyFourSeven = { - Items = {}, - Pos = { - {x = 373.875, y = 325.896, z = 102.566}, - {x = 2557.458, y = 382.282, z = 107.622}, - {x = -3038.939, y = 585.954, z = 6.908}, - {x = -3241.927, y = 1001.462, z = 11.830}, - {x = 547.431, y = 2671.710, z = 41.156}, - {x = 1961.464, y = 3740.672, z = 31.343}, - {x = 2678.916, y = 3280.671, z = 54.241}, - {x = 1729.216, y = 6414.131, z = 34.037} - } - }, + TwentyFourSeven = { + Items = {}, + Pos = { + {x = 373.875, y = 325.896, z = 102.566}, + {x = 2557.458, y = 382.282, z = 107.622}, + {x = -3038.939, y = 585.954, z = 6.908}, + {x = -3241.927, y = 1001.462, z = 11.830}, + {x = 547.431, y = 2671.710, z = 41.156}, + {x = 1961.464, y = 3740.672, z = 31.343}, + {x = 2678.916, y = 3280.671, z = 54.241}, + {x = 1729.216, y = 6414.131, z = 34.037} + } + }, - RobsLiquor = { - Items = {}, - Pos = { - {x = 1135.808, y = -982.281, z = 45.415}, - {x = -1222.915, y = -906.983, z = 11.326}, - {x = -1487.553, y = -379.107, z = 39.163}, - {x = -2968.243, y = 390.910, z = 14.043}, - {x = 1166.024, y = 2708.930, z = 37.157}, - {x = 1392.562, y = 3604.684, z = 33.980}, - {x = 127.830, y = -1284.796, z = 28.280}, --StripClub - {x = -1393.409, y = -606.624, z = 29.319}, --Tequila la - {x = -559.906, y = 287.093, z = 81.176} --Bahamamas - } - }, + RobsLiquor = { + Items = {}, + Pos = { + {x = 1135.808, y = -982.281, z = 45.415}, + {x = -1222.915, y = -906.983, z = 11.326}, + {x = -1487.553, y = -379.107, z = 39.163}, + {x = -2968.243, y = 390.910, z = 14.043}, + {x = 1166.024, y = 2708.930, z = 37.157}, + {x = 1392.562, y = 3604.684, z = 33.980}, + {x = 127.830, y = -1284.796, z = 28.280}, --StripClub + {x = -1393.409, y = -606.624, z = 29.319}, --Tequila la + {x = -559.906, y = 287.093, z = 81.176} --Bahamamas + } + }, - LTDgasoline = { - Items = {}, - Pos = { - {x = -48.519, y = -1757.514, z = 28.421}, - {x = 1163.373, y = -323.801, z = 68.205}, - {x = -707.501, y = -914.260, z = 18.215}, - {x = -1820.523, y = 792.518, z = 137.118}, - {x = 1698.388, y = 4924.404, z = 41.063} - } - } + LTDgasoline = { + Items = {}, + Pos = { + {x = -48.519, y = -1757.514, z = 28.421}, + {x = 1163.373, y = -323.801, z = 68.205}, + {x = -707.501, y = -914.260, z = 18.215}, + {x = -1820.523, y = 792.518, z = 137.118}, + {x = 1698.388, y = 4924.404, z = 41.063} + } + } } diff --git a/locales/br.lua b/locales/br.lua index 902206af..2d529545 100644 --- a/locales/br.lua +++ b/locales/br.lua @@ -1,10 +1,8 @@ Locales['br'] = { - ['shop'] = 'Comprar', ['shops'] = 'Lojas', ['press_menu'] = 'Pressione ~INPUT_CONTEXT~ para acessar a loja.', ['bought'] = 'você comprou ~b~1x ', - ['not_enough'] = 'você não tem ~r~dinheiro suficiente~s~.' - ['player_cannot_hold'] = 'Você ~r~não~s~ tem bastante ~y~espaço livre~s~ no seu inventário!', - + ['not_enough'] = 'você não tem ~r~dinheiro suficiente~s~.', + ['player_cannot_hold'] = 'Você ~r~não~s~ tem bastante ~y~espaço livre~s~ no seu inventário!', } diff --git a/server/main.lua b/server/main.lua index b3544158..310a7b1c 100644 --- a/server/main.lua +++ b/server/main.lua @@ -3,52 +3,53 @@ local ItemsLabels = {} TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) -AddEventHandler('onMySQLReady', function() - +-- Load item labels +Citizen.CreateThread(function() + Citizen.Wait(5000) + MySQL.Async.fetchAll( - 'SELECT * FROM items', - {}, - function(result) - - for i=1, #result, 1 do - ItemsLabels[result[i].name] = result[i].label - end - + 'SELECT * FROM items', + {}, + function(result) + for i=1, #result, 1 do + ItemsLabels[result[i].name] = result[i].label end - ) - + end) end) ESX.RegisterServerCallback('esx_shops:requestDBItems', function(source, cb) MySQL.Async.fetchAll( - 'SELECT * FROM shops', - {}, - function(result) - local shopItems = {} - for i=1, #result, 1 do - if shopItems[result[i].name] == nil then - shopItems[result[i].name] = {} - end - - table.insert(shopItems[result[i].name], { - name = result[i].item, - price = result[i].price, - label = ItemsLabels[result[i].item] - }) + 'SELECT * FROM shops', + {}, + function(result) + local shopItems = {} + for i=1, #result, 1 do + if shopItems[result[i].name] == nil then + shopItems[result[i].name] = {} end - cb(shopItems) + + table.insert(shopItems[result[i].name], { + name = result[i].item, + price = result[i].price, + label = ItemsLabels[result[i].item] + }) end - ) - + cb(shopItems) + end) end) RegisterServerEvent('esx_shops:buyItem') AddEventHandler('esx_shops:buyItem', function(itemName, price) - local _source = source local xPlayer = ESX.GetPlayerFromId(_source) local sourceItem = xPlayer.getInventoryItem(itemName) + + -- is the player trying to cheat? + if price < 0 then + print('esx_shops: ' .. xPlayer.identifier .. ' attempted to cheat money!') + return + end -- can the player afford this item? if xPlayer.getMoney() >= price then