Minor code cleanup

This commit is contained in:
ElPumpo
2019-11-09 17:25:41 +01:00
parent 967cde347e
commit 956fe5f183
4 changed files with 164 additions and 198 deletions
+86 -106
View File
@@ -1,29 +1,17 @@
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
}
local HasAlreadyEnteredMarker = false
local LastZone = nil
local CurrentAction = nil
local LastZone
local CurrentAction
local CurrentActionMsg = ''
local CurrentActionData = {}
local IsInShopMenu = false
local Categories = {}
local Vehicles = {}
local LastVehicles = {}
local CurrentVehicleData = nil
local CurrentVehicleData
ESX = nil
ESX = nil
Citizen.CreateThread(function ()
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
@@ -31,11 +19,11 @@ Citizen.CreateThread(function ()
Citizen.Wait(10000)
ESX.TriggerServerCallback('esx_vehicleshop:getCategories', function (categories)
ESX.TriggerServerCallback('esx_vehicleshop:getCategories', function(categories)
Categories = categories
end)
ESX.TriggerServerCallback('esx_vehicleshop:getVehicles', function (vehicles)
ESX.TriggerServerCallback('esx_vehicleshop:getVehicles', function(vehicles)
Vehicles = vehicles
end)
@@ -74,12 +62,12 @@ AddEventHandler('esx:playerLoaded', function(xPlayer)
end)
RegisterNetEvent('esx_vehicleshop:sendCategories')
AddEventHandler('esx_vehicleshop:sendCategories', function (categories)
AddEventHandler('esx_vehicleshop:sendCategories', function(categories)
Categories = categories
end)
RegisterNetEvent('esx_vehicleshop:sendVehicles')
AddEventHandler('esx_vehicleshop:sendVehicles', function (vehicles)
AddEventHandler('esx_vehicleshop:sendVehicles', function(vehicles)
Vehicles = vehicles
end)
@@ -93,9 +81,10 @@ function DeleteShopInsideVehicles()
end
function ReturnVehicleProvider()
ESX.TriggerServerCallback('esx_vehicleshop:getCommercialVehicles', function (vehicles)
ESX.TriggerServerCallback('esx_vehicleshop:getCommercialVehicles', function(vehicles)
local elements = {}
local returnPrice
for i=1, #vehicles, 1 do
returnPrice = ESX.Math.Round(vehicles[i].price * 0.75)
@@ -109,13 +98,13 @@ function ReturnVehicleProvider()
title = _U('return_provider_menu'),
align = 'top-left',
elements = elements
}, function (data, menu)
}, function(data, menu)
TriggerServerEvent('esx_vehicleshop:returnProvider', data.current.value)
Citizen.Wait(300)
menu.close()
ReturnVehicleProvider()
end, function (data, menu)
end, function(data, menu)
menu.close()
end)
end)
@@ -124,7 +113,7 @@ end
function StartShopRestriction()
Citizen.CreateThread(function()
while IsInShopMenu do
Citizen.Wait(1)
Citizen.Wait(0)
DisableControlAction(0, 75, true) -- Disable exit vehicle
DisableControlAction(27, 75, true) -- Disable exit vehicle
@@ -142,7 +131,7 @@ function OpenShopMenu()
FreezeEntityPosition(playerPed, true)
SetEntityVisible(playerPed, false)
SetEntityCoords(playerPed, Config.Zones.ShopInside.Pos.x, Config.Zones.ShopInside.Pos.y, Config.Zones.ShopInside.Pos.z)
SetEntityCoords(playerPed, Config.Zones.ShopInside.Pos)
local vehiclesByCategory = {}
local elements = {}
@@ -189,7 +178,7 @@ function OpenShopMenu()
title = _U('car_dealer'),
align = 'top-left',
elements = elements
}, function (data, menu)
}, function(data, menu)
local vehicleData = vehiclesByCategory[data.current.name][data.current.value + 1]
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'shop_confirm', {
@@ -198,8 +187,7 @@ function OpenShopMenu()
elements = {
{label = _U('no'), value = 'no'},
{label = _U('yes'), value = 'yes'}
}
}, function(data2, menu2)
}}, function(data2, menu2)
if data2.current.value == 'yes' then
if Config.EnablePlayerManagement then
ESX.TriggerServerCallback('esx_vehicleshop:buyVehicleSociety', function(hasEnoughMoney)
@@ -216,7 +204,7 @@ function OpenShopMenu()
FreezeEntityPosition(playerPed, false)
SetEntityVisible(playerPed, true)
SetEntityCoords(playerPed, Config.Zones.ShopEntering.Pos.x, Config.Zones.ShopEntering.Pos.y, Config.Zones.ShopEntering.Pos.z)
SetEntityCoords(playerPed, Config.Zones.ShopEntering.Pos)
menu2.close()
menu.close()
@@ -236,7 +224,7 @@ function OpenShopMenu()
elements = {
{label = _U('staff_type'), value = 'personnal'},
{label = _U('society_type'), value = 'society'}
}}, function (data3, menu3)
}}, function(data3, menu3)
if data3.current.value == 'personnal' then
@@ -249,7 +237,7 @@ function OpenShopMenu()
menu.close()
DeleteShopInsideVehicles()
ESX.Game.SpawnVehicle(vehicleData.model, Config.Zones.ShopOutside.Pos, Config.Zones.ShopOutside.Heading, function (vehicle)
ESX.Game.SpawnVehicle(vehicleData.model, Config.Zones.ShopOutside.Pos, Config.Zones.ShopOutside.Heading, function(vehicle)
TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
local newPlate = GeneratePlate()
@@ -273,7 +261,7 @@ function OpenShopMenu()
elseif data3.current.value == 'society' then
ESX.TriggerServerCallback('esx_vehicleshop:buyVehicleSociety', function (hasEnoughMoney)
ESX.TriggerServerCallback('esx_vehicleshop:buyVehicleSociety', function(hasEnoughMoney)
if hasEnoughMoney then
IsInShopMenu = false
@@ -283,7 +271,7 @@ function OpenShopMenu()
DeleteShopInsideVehicles()
ESX.Game.SpawnVehicle(vehicleData.model, Config.Zones.ShopOutside.Pos, Config.Zones.ShopOutside.Heading, function (vehicle)
ESX.Game.SpawnVehicle(vehicleData.model, Config.Zones.ShopOutside.Pos, Config.Zones.ShopOutside.Heading, function(vehicle)
TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
local newPlate = GeneratePlate()
@@ -302,18 +290,18 @@ function OpenShopMenu()
end, playerData.job.name, vehicleData.model)
end
end, function (data3, menu3)
end, function(data3, menu3)
menu3.close()
end)
else
ESX.TriggerServerCallback('esx_vehicleshop:buyVehicle', function (hasEnoughMoney)
ESX.TriggerServerCallback('esx_vehicleshop:buyVehicle', function(hasEnoughMoney)
if hasEnoughMoney then
IsInShopMenu = false
menu2.close()
menu.close()
DeleteShopInsideVehicles()
ESX.Game.SpawnVehicle(vehicleData.model, Config.Zones.ShopOutside.Pos, Config.Zones.ShopOutside.Heading, function (vehicle)
ESX.Game.SpawnVehicle(vehicleData.model, Config.Zones.ShopOutside.Pos, Config.Zones.ShopOutside.Heading, function(vehicle)
TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
local newPlate = GeneratePlate()
@@ -337,10 +325,10 @@ function OpenShopMenu()
end
end
end
end, function (data2, menu2)
end, function(data2, menu2)
menu2.close()
end)
end, function (data, menu)
end, function(data, menu)
menu.close()
DeleteShopInsideVehicles()
local playerPed = PlayerPedId()
@@ -351,17 +339,17 @@ function OpenShopMenu()
FreezeEntityPosition(playerPed, false)
SetEntityVisible(playerPed, true)
SetEntityCoords(playerPed, Config.Zones.ShopEntering.Pos.x, Config.Zones.ShopEntering.Pos.y, Config.Zones.ShopEntering.Pos.z)
SetEntityCoords(playerPed, Config.Zones.ShopEntering.Pos)
IsInShopMenu = false
end, function (data, menu)
end, function(data, menu)
local vehicleData = vehiclesByCategory[data.current.name][data.current.value + 1]
local playerPed = PlayerPedId()
DeleteShopInsideVehicles()
WaitForVehicleToLoad(vehicleData.model)
ESX.Game.SpawnLocalVehicle(vehicleData.model, Config.Zones.ShopInside.Pos, Config.Zones.ShopInside.Heading, function (vehicle)
ESX.Game.SpawnLocalVehicle(vehicleData.model, Config.Zones.ShopInside.Pos, Config.Zones.ShopInside.Heading, function(vehicle)
table.insert(LastVehicles, vehicle)
TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
FreezeEntityPosition(vehicle, true)
@@ -372,13 +360,12 @@ function OpenShopMenu()
DeleteShopInsideVehicles()
WaitForVehicleToLoad(firstVehicleData.model)
ESX.Game.SpawnLocalVehicle(firstVehicleData.model, Config.Zones.ShopInside.Pos, Config.Zones.ShopInside.Heading, function (vehicle)
ESX.Game.SpawnLocalVehicle(firstVehicleData.model, Config.Zones.ShopInside.Pos, Config.Zones.ShopInside.Heading, function(vehicle)
table.insert(LastVehicles, vehicle)
TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
FreezeEntityPosition(vehicle, true)
SetModelAsNoLongerNeeded(firstVehicleData.model)
end)
end
function WaitForVehicleToLoad(modelHash)
@@ -392,7 +379,7 @@ function WaitForVehicleToLoad(modelHash)
EndTextCommandBusyString(4)
while not HasModelLoaded(modelHash) do
Citizen.Wait(1)
Citizen.Wait(0)
DisableAllControlActions(0)
end
@@ -418,8 +405,7 @@ function OpenResellerMenu()
{label = _U('set_vehicle_owner_sell_society'), value = 'set_vehicle_owner_sell_society'},
{label = _U('deposit_stock'), value = 'put_stock'},
{label = _U('take_stock'), value = 'get_stock'}
}
}, function (data, menu)
}}, function(data, menu)
local action = data.current.value
if action == 'buy_vehicle' then
@@ -444,7 +430,7 @@ function OpenResellerMenu()
ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'set_vehicle_owner_sell_amount', {
title = _U('invoice_amount')
}, function (data2, menu2)
}, function(data2, menu2)
local amount = tonumber(data2.value)
if amount == nil then
@@ -459,7 +445,7 @@ function OpenResellerMenu()
TriggerServerEvent('esx_billing:sendBill', GetPlayerServerId(closestPlayer), 'society_cardealer', _U('car_dealer'), tonumber(data2.value))
end
end
end, function (data2, menu2)
end, function(data2, menu2)
menu2.close()
end)
@@ -496,7 +482,7 @@ function OpenResellerMenu()
if closestPlayer == -1 or closestDistance > 3.0 then
ESX.ShowNotification(_U('no_players'))
else
ESX.TriggerServerCallback('esx:getOtherPlayerData', function (xPlayer)
ESX.TriggerServerCallback('esx:getOtherPlayerData', function(xPlayer)
local newPlate = GeneratePlate()
local vehicleProps = ESX.Game.GetVehicleProperties(LastVehicles[#LastVehicles])
@@ -520,7 +506,7 @@ function OpenResellerMenu()
ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'set_vehicle_owner_rent_amount', {
title = _U('rental_amount')
}, function (data2, menu2)
}, function(data2, menu2)
local amount = tonumber(data2.value)
if amount == nil then
@@ -545,14 +531,13 @@ function OpenResellerMenu()
end
ESX.ShowNotification(_U('vehicle_set_rented', vehicleProps.plate, GetPlayerName(closestPlayer)))
TriggerServerEvent('esx_vehicleshop:setVehicleForAllPlayers', vehicleProps, Config.Zones.ShopInside.Pos.x, Config.Zones.ShopInside.Pos.y, Config.Zones.ShopInside.Pos.z, 5.0)
end
end
end, function (data2, menu2)
end, function(data2, menu2)
menu2.close()
end)
end
end, function (data, menu)
end, function(data, menu)
menu.close()
CurrentAction = 'reseller_menu'
@@ -562,7 +547,7 @@ function OpenResellerMenu()
end
function OpenPopVehicleMenu()
ESX.TriggerServerCallback('esx_vehicleshop:getCommercialVehicles', function (vehicles)
ESX.TriggerServerCallback('esx_vehicleshop:getCommercialVehicles', function(vehicles)
local elements = {}
for i=1, #vehicles, 1 do
@@ -576,12 +561,12 @@ function OpenPopVehicleMenu()
title = _U('vehicle_dealer'),
align = 'top-left',
elements = elements
}, function (data, menu)
}, function(data, menu)
local model = data.current.value
DeleteShopInsideVehicles()
ESX.Game.SpawnVehicle(model, Config.Zones.ShopInside.Pos, Config.Zones.ShopInside.Heading, function (vehicle)
ESX.Game.SpawnVehicle(model, Config.Zones.ShopInside.Pos, Config.Zones.ShopInside.Heading, function(vehicle)
table.insert(LastVehicles, vehicle)
for i=1, #Vehicles, 1 do
@@ -591,14 +576,14 @@ function OpenPopVehicleMenu()
end
end
end)
end, function (data, menu)
end, function(data, menu)
menu.close()
end)
end)
end
function OpenRentedVehiclesMenu()
ESX.TriggerServerCallback('esx_vehicleshop:getRentedVehicles', function (vehicles)
ESX.TriggerServerCallback('esx_vehicleshop:getRentedVehicles', function(vehicles)
local elements = {}
for i=1, #vehicles, 1 do
@@ -612,7 +597,7 @@ function OpenRentedVehiclesMenu()
title = _U('rent_vehicle'),
align = 'top-left',
elements = elements
}, nil, function (data, menu)
}, nil, function(data, menu)
menu.close()
end)
end)
@@ -627,7 +612,7 @@ function OpenBossActionsMenu()
elements = {
{label = _U('boss_actions'), value = 'boss_actions'},
{label = _U('boss_sold'), value = 'sold_vehicles'}
}}, function (data, menu)
}}, function(data, menu)
if data.current.value == 'boss_actions' then
TriggerEvent('esx_society:openBossMenu', 'cardealer', function(data2, menu2)
menu2.close()
@@ -661,7 +646,7 @@ function OpenBossActionsMenu()
end)
end
end, function (data, menu)
end, function(data, menu)
menu.close()
CurrentAction = 'boss_actions_menu'
@@ -671,7 +656,7 @@ function OpenBossActionsMenu()
end
function OpenGetStocksMenu()
ESX.TriggerServerCallback('esx_vehicleshop:getStockItems', function (items)
ESX.TriggerServerCallback('esx_vehicleshop:getStockItems', function(items)
local elements = {}
for i=1, #items, 1 do
@@ -685,12 +670,12 @@ function OpenGetStocksMenu()
title = _U('dealership_stock'),
align = 'top-left',
elements = elements
}, function (data, menu)
}, function(data, menu)
local itemName = data.current.value
ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'stocks_menu_get_item_count', {
title = _U('amount')
}, function (data2, menu2)
}, function(data2, menu2)
local count = tonumber(data2.value)
if count == nil then
@@ -701,18 +686,17 @@ function OpenGetStocksMenu()
menu.close()
OpenGetStocksMenu()
end
end, function (data2, menu2)
end, function(data2, menu2)
menu2.close()
end)
end, function (data, menu)
end, function(data, menu)
menu.close()
end)
end)
end
function OpenPutStocksMenu()
ESX.TriggerServerCallback('esx_vehicleshop:getPlayerInventory', function (inventory)
ESX.TriggerServerCallback('esx_vehicleshop:getPlayerInventory', function(inventory)
local elements = {}
for i=1, #inventory.items, 1 do
@@ -731,12 +715,12 @@ function OpenPutStocksMenu()
title = _U('inventory'),
align = 'top-left',
elements = elements
}, function (data, menu)
}, function(data, menu)
local itemName = data.current.value
ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'stocks_menu_put_item_count', {
title = _U('amount')
}, function (data2, menu2)
}, function(data2, menu2)
local count = tonumber(data2.value)
if count == nil then
@@ -747,17 +731,17 @@ function OpenPutStocksMenu()
menu.close()
OpenPutStocksMenu()
end
end, function (data2, menu2)
end, function(data2, menu2)
menu2.close()
end)
end, function (data, menu)
end, function(data, menu)
menu.close()
end)
end)
end
RegisterNetEvent('esx:setJob')
AddEventHandler('esx:setJob', function (job)
AddEventHandler('esx:setJob', function(job)
ESX.PlayerData.job = job
if Config.EnablePlayerManagement then
@@ -774,7 +758,7 @@ AddEventHandler('esx:setJob', function (job)
end
end)
AddEventHandler('esx_vehicleshop:hasEnteredMarker', function (zone)
AddEventHandler('esx_vehicleshop:hasEnteredMarker', function(zone)
if zone == 'ShopEntering' then
if Config.EnablePlayerManagement then
@@ -845,7 +829,7 @@ AddEventHandler('esx_vehicleshop:hasEnteredMarker', function (zone)
end
end)
AddEventHandler('esx_vehicleshop:hasExitedMarker', function (zone)
AddEventHandler('esx_vehicleshop:hasExitedMarker', function(zone)
if not IsInShopMenu then
ESX.UI.Menu.CloseAll()
end
@@ -863,14 +847,14 @@ AddEventHandler('onResourceStop', function(resource)
FreezeEntityPosition(playerPed, false)
SetEntityVisible(playerPed, true)
SetEntityCoords(playerPed, Config.Zones.ShopEntering.Pos.x, Config.Zones.ShopEntering.Pos.y, Config.Zones.ShopEntering.Pos.z)
SetEntityCoords(playerPed, Config.Zones.ShopEntering.Pos)
end
end
end)
if Config.EnablePlayerManagement then
RegisterNetEvent('esx_phone:loaded')
AddEventHandler('esx_phone:loaded', function (phoneNumber, contacts)
AddEventHandler('esx_phone:loaded', function(phoneNumber, contacts)
local specialContact = {
name = _U('dealership'),
number = 'cardealer',
@@ -883,7 +867,7 @@ end
-- Create Blips
Citizen.CreateThread(function()
local blip = AddBlipForCoord(Config.Zones.ShopEntering.Pos.x, Config.Zones.ShopEntering.Pos.y, Config.Zones.ShopEntering.Pos.z)
local blip = AddBlipForCoord(Config.Zones.ShopEntering.Pos)
SetBlipSprite (blip, 326)
SetBlipDisplay(blip, 4)
@@ -895,40 +879,32 @@ Citizen.CreateThread(function()
EndTextCommandSetBlipName(blip)
end)
-- Display markers
-- Enter / Exit marker events & Draw Markers
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
local coords = GetEntityCoords(PlayerPedId())
local playerCoords = GetEntityCoords(PlayerPedId())
local isInMarker, letSleep, currentZone = false, true
for k,v in pairs(Config.Zones) do
if(v.Type ~= -1 and GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < Config.DrawDistance) then
DrawMarker(v.Type, v.Pos.x, v.Pos.y, v.Pos.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, v.Size.x, v.Size.y, v.Size.z, Config.MarkerColor.r, Config.MarkerColor.g, Config.MarkerColor.b, 100, false, true, 2, false, false, false, false)
end
end
end
end)
local distance = #(playerCoords - v.Pos)
-- Enter / Exit marker events
Citizen.CreateThread(function ()
while true do
Citizen.Wait(0)
if distance < Config.DrawDistance then
letSleep = false
local coords = GetEntityCoords(PlayerPedId())
local isInMarker = false
local currentZone = nil
if v.Type ~= -1 then
DrawMarker(v.Type, v.Pos, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, v.Size.x, v.Size.y, v.Size.z, Config.MarkerColor.r, Config.MarkerColor.g, Config.MarkerColor.b, 100, false, true, 2, false, nil, nil, false)
end
for k,v in pairs(Config.Zones) do
if(GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < v.Size.x) then
isInMarker = true
currentZone = k
if distance < v.Size.x then
isInMarker, currentZone = true, k
end
end
end
if (isInMarker and not HasAlreadyEnteredMarker) or (isInMarker and LastZone ~= currentZone) then
HasAlreadyEnteredMarker = true
LastZone = currentZone
HasAlreadyEnteredMarker, LastZone = true, currentZone
LastZone = currentZone
TriggerEvent('esx_vehicleshop:hasEnteredMarker', currentZone)
end
@@ -936,20 +912,22 @@ Citizen.CreateThread(function ()
HasAlreadyEnteredMarker = false
TriggerEvent('esx_vehicleshop:hasExitedMarker', LastZone)
end
if letSleep then
Citizen.Wait(500)
end
end
end)
-- Key controls
Citizen.CreateThread(function()
while true do
Citizen.Wait(10)
Citizen.Wait(0)
if CurrentAction == nil then
Citizen.Wait(500)
else
if CurrentAction then
ESX.ShowHelpNotification(CurrentActionMsg)
if IsControlJustReleased(0, Keys['E']) then
if IsControlJustReleased(0, 38) then
if CurrentAction == 'shop_menu' then
if Config.LicenseEnable then
ESX.TriggerServerCallback('esx_license:checkLicense', function(hasDriversLicense)
@@ -988,6 +966,8 @@ Citizen.CreateThread(function()
CurrentAction = nil
end
else
Citizen.Wait(500)
end
end
end)