diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..4bfca33b --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +indent_size = 2 +indent_style = space +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/__resource.lua b/__resource.lua index 48d4cead..114c0c75 100644 --- a/__resource.lua +++ b/__resource.lua @@ -3,24 +3,24 @@ description 'ESX Mecano Job' version '1.0.0' client_scripts { - '@es_extended/locale.lua', - 'locales/de.lua', - 'locales/br.lua', - 'locales/en.lua', - 'locales/fr.lua', - 'locales/es.lua', - 'config.lua', - 'client/main.lua' + '@es_extended/locale.lua', + 'locales/de.lua', + 'locales/br.lua', + 'locales/en.lua', + 'locales/fr.lua', + 'locales/es.lua', + 'config.lua', + 'client/main.lua' } server_scripts { - '@es_extended/locale.lua', - 'locales/de.lua', - 'locales/br.lua', - 'locales/en.lua', - 'locales/fr.lua', - 'locales/es.lua', - '@mysql-async/lib/MySQL.lua', - 'config.lua', - 'server/main.lua' + '@es_extended/locale.lua', + 'locales/de.lua', + 'locales/br.lua', + 'locales/en.lua', + 'locales/fr.lua', + 'locales/es.lua', + '@mysql-async/lib/MySQL.lua', + 'config.lua', + 'server/main.lua' } diff --git a/client/main.lua b/client/main.lua index e07aca95..ef34d62f 100644 --- a/client/main.lua +++ b/client/main.lua @@ -4,140 +4,140 @@ local LastZone = nil local CurrentAction = nil local CurrentActionMsg = '' local CurrentActionData = {} - + Citizen.CreateThread(function() - while ESX == nil do - TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) - Citizen.Wait(0) - end + while ESX == nil do + TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) + Citizen.Wait(0) + end end) AddEventHandler('onClientMapStart', function() - - ESX.TriggerServerCallback('esx_weashop:requestDBItems', function(ShopItems) - for k,v in pairs(ShopItems) do - Config.Zones[k].Items = v - end - end) + + ESX.TriggerServerCallback('esx_weashop:requestDBItems', function(ShopItems) + for k,v in pairs(ShopItems) do + Config.Zones[k].Items = v + end + end) end) function OpenShopMenu(zone) - local elements = {} + local elements = {} - for i=1, #Config.Zones[zone].Items, 1 do + for i=1, #Config.Zones[zone].Items, 1 do - local item = Config.Zones[zone].Items[i] + local item = Config.Zones[zone].Items[i] - table.insert(elements, { - label = item.label .. ' - $' .. item.price .. ' ', - realLabel = item.label, - value = item.name, - price = item.price - }) + table.insert(elements, { + label = item.label .. ' - $' .. item.price .. ' ', + realLabel = item.label, + value = item.name, + price = item.price + }) - end + end - ESX.UI.Menu.CloseAll() + ESX.UI.Menu.CloseAll() - ESX.UI.Menu.Open( - 'default', GetCurrentResourceName(), 'shop', - { - title = _U('shop'), - elements = elements - }, - function(data, menu) - TriggerServerEvent('esx_weashop:buyItem', data.current.value, data.current.price, zone) - end, - function(data, menu) - - menu.close() - - CurrentAction = 'shop_menu' - CurrentActionMsg = _U('shop_menu') - CurrentActionData = {zone = zone} - end - ) + ESX.UI.Menu.Open( + 'default', GetCurrentResourceName(), 'shop', + { + title = _U('shop'), + elements = elements + }, + function(data, menu) + TriggerServerEvent('esx_weashop:buyItem', data.current.value, data.current.price, zone) + end, + function(data, menu) + + menu.close() + + CurrentAction = 'shop_menu' + CurrentActionMsg = _U('shop_menu') + CurrentActionData = {zone = zone} + end + ) end AddEventHandler('esx_weashop:hasEnteredMarker', function(zone) - - CurrentAction = 'shop_menu' - CurrentActionMsg = _U('shop_menu') - CurrentActionData = {zone = zone} + + CurrentAction = 'shop_menu' + CurrentActionMsg = _U('shop_menu') + CurrentActionData = {zone = zone} end) AddEventHandler('esx_weashop:hasExitedMarker', function(zone) - CurrentAction = nil - ESX.UI.Menu.CloseAll() + CurrentAction = nil + ESX.UI.Menu.CloseAll() end) -- Create Blips Citizen.CreateThread(function() - for k,v in pairs(Config.Zones) do - if v.legal==0 then - for i = 1, #v.Pos, 1 do - local blip = AddBlipForCoord(v.Pos[i].x, v.Pos[i].y, v.Pos[i].z) - SetBlipSprite (blip, 154) - SetBlipDisplay(blip, 4) - SetBlipScale (blip, 1.0) - SetBlipColour (blip, 2) - SetBlipAsShortRange(blip, true) - BeginTextCommandSetBlipName("STRING") - AddTextComponentString(_U('map_blip')) - EndTextCommandSetBlipName(blip) - end - end - end + for k,v in pairs(Config.Zones) do + if v.legal==0 then + for i = 1, #v.Pos, 1 do + local blip = AddBlipForCoord(v.Pos[i].x, v.Pos[i].y, v.Pos[i].z) + SetBlipSprite (blip, 154) + SetBlipDisplay(blip, 4) + SetBlipScale (blip, 1.0) + SetBlipColour (blip, 2) + SetBlipAsShortRange(blip, true) + BeginTextCommandSetBlipName("STRING") + AddTextComponentString(_U('map_blip')) + EndTextCommandSetBlipName(blip) + end + end + end end) -- Display markers Citizen.CreateThread(function() - while true do + while true do Wait(0) - local coords = GetEntityCoords(GetPlayerPed(-1)) + local coords = GetEntityCoords(GetPlayerPed(-1)) for k,v in pairs(Config.Zones) do for i = 1, #v.Pos, 1 do if(Config.Type ~= -1 and GetDistanceBetweenCoords(coords, v.Pos[i].x, v.Pos[i].y, v.Pos[i].z, true) < Config.DrawDistance) then DrawMarker(Config.Type, v.Pos[i].x, v.Pos[i].y, v.Pos[i].z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, Config.Size.x, Config.Size.y, Config.Size.z, Config.Color.r, Config.Color.g, Config.Color.b, 100, false, true, 2, false, false, false, false) end - end + end end end end) -- Enter / Exit marker events Citizen.CreateThread(function() - while true do - Wait(0) - local coords = GetEntityCoords(GetPlayerPed(-1)) - local isInMarker = false - local currentZone = nil + while true do + Wait(0) + local coords = GetEntityCoords(GetPlayerPed(-1)) + local isInMarker = false + local currentZone = nil - for k,v in pairs(Config.Zones) do - for i = 1, #v.Pos, 1 do - if(GetDistanceBetweenCoords(coords, v.Pos[i].x, v.Pos[i].y, v.Pos[i].z, true) < Config.Size.x) then - isInMarker = true - ShopItems = v.Items - currentZone = k - LastZone = k - end - end - end - if isInMarker and not HasAlreadyEnteredMarker then - HasAlreadyEnteredMarker = true - TriggerEvent('esx_weashop:hasEnteredMarker', currentZone) - end - if not isInMarker and HasAlreadyEnteredMarker then - HasAlreadyEnteredMarker = false - TriggerEvent('esx_weashop:hasExitedMarker', LastZone) - end - end + for k,v in pairs(Config.Zones) do + for i = 1, #v.Pos, 1 do + if(GetDistanceBetweenCoords(coords, v.Pos[i].x, v.Pos[i].y, v.Pos[i].z, true) < Config.Size.x) then + isInMarker = true + ShopItems = v.Items + currentZone = k + LastZone = k + end + end + end + if isInMarker and not HasAlreadyEnteredMarker then + HasAlreadyEnteredMarker = true + TriggerEvent('esx_weashop:hasEnteredMarker', currentZone) + end + if not isInMarker and HasAlreadyEnteredMarker then + HasAlreadyEnteredMarker = false + TriggerEvent('esx_weashop:hasExitedMarker', LastZone) + end + end end) -- Key Controls @@ -145,21 +145,21 @@ Citizen.CreateThread(function() while true do Citizen.Wait(0) if CurrentAction ~= nil then - + SetTextComponentFormat('STRING') AddTextComponentString(CurrentActionMsg) DisplayHelpTextFromStringLabel(0, 0, 1, -1) - - if IsControlJustReleased(0, 38) then - + + if IsControlJustReleased(0, 38) then + if CurrentAction == 'shop_menu' then OpenShopMenu(CurrentActionData.zone) end - - CurrentAction = nil - + + CurrentAction = nil + end end end -end) \ No newline at end of file +end) diff --git a/config.lua b/config.lua index cca587a4..00e32e1d 100644 --- a/config.lua +++ b/config.lua @@ -1,36 +1,35 @@ Config = {} Config.DrawDistance = 100 -Config.Size = {x = 1.5, y = 1.5, z = 1.5} -Config.Color = {r = 0, g = 128, b = 255} +Config.Size = { x = 1.5, y = 1.5, z = 1.5 } +Config.Color = { r = 0, g = 128, b = 255 } Config.Type = 1 Config.Locale = 'fr' Config.Zones = { GunShop = { - legal=0, + legal = 0, Items = {}, - Pos = { - {x = -662.180053710938, y =-934.961120605469, z = 20.8292293548584}, - {x = 810.25, y =-2157.60, z = 28.62}, - {x = 1693.44, y =3760.16, z = 33.71}, - {x = -330.24, y =6083.88, z = 30.45}, - {x = 252.63, y =-50.00, z = 68.94}, - {x = 22.09, y =-1107.28, z = 28.80}, - {x = 2567.69, y =294.38, z = 107.73}, - {x = -1117.58, y =2698.61, z = 17.55}, - {x = 842.44, y =-1033.42, z = 27.19} - + Pos = { + { x = -662.180, y = -934.961, z = 20.829 }, + { x = 810.25, y = -2157.60, z = 28.62 }, + { x = 1693.44, y = 3760.16, z = 33.71 }, + { x = -330.24, y = 6083.88, z = 30.45 }, + { x = 252.63, y = -50.00, z = 68.94 }, + { x = 22.09, y = -1107.28, z = 28.80 }, + { x = 2567.69, y = 294.38, z = 107.73 }, + { x = -1117.58, y = 2698.61, z = 17.55 }, + { x = 842.44, y = -1033.42, z = 27.19 }, + } }, - - BlackWeashop = { - legal=1, + + BlackWeashop = { + legal = 1, Items = {}, - Pos = { - {x = -1306.23986816406, y =-394.018707275391, z = 35.6958122253418} - + Pos = { + { x = -1306.239, y = -394.018, z = 35.695 }, } }, diff --git a/locales/br.lua b/locales/br.lua index 86c0b715..2c67d44d 100644 --- a/locales/br.lua +++ b/locales/br.lua @@ -1,10 +1,10 @@ Locales ['br'] = { - ['buy'] = 'Você comprou', - ['not_enough_black'] = 'Você não tem dinheiro sujo suficiente', - ['not_enough'] = 'você não tem dinheiro suficiente', - ['shop'] = 'Comprar', - ['shop_menu'] = 'Pressione ~INPUT_CONTEXT~ para comprar armas.', - ['map_blip'] = 'Loja de Armas', + ['buy'] = 'Você comprou', + ['not_enough_black'] = 'Você não tem dinheiro sujo suficiente', + ['not_enough'] = 'você não tem dinheiro suficiente', + ['shop'] = 'Comprar', + ['shop_menu'] = 'Pressione ~INPUT_CONTEXT~ para comprar armas.', + ['map_blip'] = 'Loja de Armas', -} \ No newline at end of file +} diff --git a/locales/de.lua b/locales/de.lua index 7415e576..d18dc9a1 100644 --- a/locales/de.lua +++ b/locales/de.lua @@ -1,10 +1,10 @@ Locales ['de'] = { - ['buy'] = 'du kaufst', - ['not_enough_black'] = 'du hast nicht genug Schwarzgeld', - ['not_enough'] = 'du hast nicht genug Geld', - ['shop'] = 'Geschäft', - ['shop_menu'] = 'Drücke ~INPUT_CONTEXT~ um auf das Geschäft zuzugreifen.', - ['map_blip'] = 'Waffenladen', + ['buy'] = 'du kaufst', + ['not_enough_black'] = 'du hast nicht genug Schwarzgeld', + ['not_enough'] = 'du hast nicht genug Geld', + ['shop'] = 'Geschäft', + ['shop_menu'] = 'Drücke ~INPUT_CONTEXT~ um auf das Geschäft zuzugreifen.', + ['map_blip'] = 'Waffenladen', -} \ No newline at end of file +} diff --git a/locales/en.lua b/locales/en.lua index e52445a0..ff62d147 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -1,10 +1,10 @@ Locales ['en'] = { - ['buy'] = 'you bought', - ['not_enough_black'] = 'you do not have enough dirty money', - ['not_enough'] = 'you do not have enough money', - ['shop'] = 'shop', - ['shop_menu'] = 'Press ~INPUT_CONTEXT~ to access the shop.', - ['map_blip'] = 'gun shop', + ['buy'] = 'you bought', + ['not_enough_black'] = 'you do not have enough dirty money', + ['not_enough'] = 'you do not have enough money', + ['shop'] = 'shop', + ['shop_menu'] = 'Press ~INPUT_CONTEXT~ to access the shop.', + ['map_blip'] = 'gun shop', -} \ No newline at end of file +} diff --git a/locales/es.lua b/locales/es.lua index 71ea20a9..de77e82e 100644 --- a/locales/es.lua +++ b/locales/es.lua @@ -1,10 +1,10 @@ Locales ['es'] = { - ['buy'] = 'Has comprado ~b~1 ', - ['not_enough_black'] = 'Usted no tiene ~r~suficiente~s~ dinero negro', - ['not_enough'] = 'Usted no tiene ~r~suficiente~s~ dinero', - ['shop'] = 'Tienda', - ['shop_menu'] = 'Presione ~INPUT_CONTEXT~ para acceder a la tienda.', - ['map_blip'] = 'Arsenal', + ['buy'] = 'Has comprado ~b~1 ', + ['not_enough_black'] = 'Usted no tiene ~r~suficiente~s~ dinero negro', + ['not_enough'] = 'Usted no tiene ~r~suficiente~s~ dinero', + ['shop'] = 'Tienda', + ['shop_menu'] = 'Presione ~INPUT_CONTEXT~ para acceder a la tienda.', + ['map_blip'] = 'Arsenal', } diff --git a/locales/fr.lua b/locales/fr.lua index 1b3b5ca1..91eb81d5 100644 --- a/locales/fr.lua +++ b/locales/fr.lua @@ -1,10 +1,10 @@ Locales ['fr'] = { - ['buy'] = 'vous avez acheté ~b~1x ', - ['not_enough_black'] = 'Vous n\'avez ~r~pas assez~s~ d\'argent sale', - ['not_enough'] = 'vous n\'avez ~r~pas assez~s~ d\'argent', - ['shop'] = 'magasin', - ['shop_menu'] = 'appuyez sur ~INPUT_CONTEXT~ pour accéder au magasin.', - ['map_blip'] = 'armurerie', + ['buy'] = 'vous avez acheté ~b~1x ', + ['not_enough_black'] = 'Vous n\'avez ~r~pas assez~s~ d\'argent sale', + ['not_enough'] = 'vous n\'avez ~r~pas assez~s~ d\'argent', + ['shop'] = 'magasin', + ['shop_menu'] = 'appuyez sur ~INPUT_CONTEXT~ pour accéder au magasin.', + ['map_blip'] = 'armurerie', -} \ No newline at end of file +} diff --git a/server/main.lua b/server/main.lua index 413999c7..e8822f8b 100644 --- a/server/main.lua +++ b/server/main.lua @@ -5,62 +5,62 @@ TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) ESX.RegisterServerCallback('esx_weashop:requestDBItems', function(source, cb) - MySQL.Async.fetchAll( - 'SELECT * FROM weashops', - {}, - function(result) - - local shopItems = {} + MySQL.Async.fetchAll( + 'SELECT * FROM weashops', + {}, + function(result) - for i=1, #result, 1 do + local shopItems = {} - if shopItems[result[i].name] == nil then - shopItems[result[i].name] = {} - end + for i=1, #result, 1 do - table.insert(shopItems[result[i].name], { - name = result[i].item, - price = result[i].price, - label = ESX.GetWeaponLabel(result[i].item) - }) + if shopItems[result[i].name] == nil then + shopItems[result[i].name] = {} + end - end + table.insert(shopItems[result[i].name], { + name = result[i].item, + price = result[i].price, + label = ESX.GetWeaponLabel(result[i].item) + }) - cb(shopItems) + end - end - ) + cb(shopItems) + + end + ) end) RegisterServerEvent('esx_weashop:buyItem') AddEventHandler('esx_weashop:buyItem', function(itemName, price, zone) - - local _source = source - local xPlayer = ESX.GetPlayerFromId(source) - local account = xPlayer.getAccount('black_money') - - if zone=="BlackWeashop" then - if account.money >= price then - xPlayer.removeAccountMoney('black_money', price) - xPlayer.addWeapon(itemName, 42) - TriggerClientEvent('esx:showNotification', _source, _U('buy') .. ESX.GetWeaponLabel(itemName)) + local _source = source + local xPlayer = ESX.GetPlayerFromId(source) + local account = xPlayer.getAccount('black_money') - else - TriggerClientEvent('esx:showNotification', _source, _U('not_enough_black')) - end + if zone=="BlackWeashop" then + if account.money >= price then - else if xPlayer.get('money') >= price then + xPlayer.removeAccountMoney('black_money', price) + xPlayer.addWeapon(itemName, 42) + TriggerClientEvent('esx:showNotification', _source, _U('buy') .. ESX.GetWeaponLabel(itemName)) - xPlayer.removeMoney(price) - xPlayer.addWeapon(itemName, 42) + else + TriggerClientEvent('esx:showNotification', _source, _U('not_enough_black')) + end - TriggerClientEvent('esx:showNotification', _source, _U('buy') .. ESX.GetWeaponLabel(itemName)) + else if xPlayer.get('money') >= price then - else - TriggerClientEvent('esx:showNotification', _source, _U('not_enough')) - end - end + xPlayer.removeMoney(price) + xPlayer.addWeapon(itemName, 42) + + TriggerClientEvent('esx:showNotification', _source, _U('buy') .. ESX.GetWeaponLabel(itemName)) + + else + TriggerClientEvent('esx:showNotification', _source, _U('not_enough')) + end + end end)