Use vector types, digit grouping, improved threads, locale file indent

This commit is contained in:
ElPumpo
2019-03-09 16:53:25 +01:00
parent 54cae91fc4
commit f4265fec52
7 changed files with 147 additions and 173 deletions
+29 -33
View File
@@ -10,7 +10,7 @@ Keys = {
["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118
}
ESX = nil
ESX = nil
isInShopMenu = false
local spawnedVehicles = {}
@@ -35,17 +35,15 @@ function OpenBoatShop(shop)
local elements = {}
for i=1, #Config.Vehicles, 1 do
table.insert(elements, {
label = (string.format ('%s - <span style="color: green;">$%i</span>', Config.Vehicles[i].label, Config.Vehicles[i].price)),
label = ('%s - <span style="color:green;">$%s</span>'):format(Config.Vehicles[i].label, ESX.Math.GroupDigits(Config.Vehicles[i].price)),
name = Config.Vehicles[i].label,
model = Config.Vehicles[i].model,
price = Config.Vehicles[i].price
})
end
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'boat_shop',
{
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'boat_shop', {
title = _U('boat_shop'),
align = 'top-left',
elements = elements
@@ -53,7 +51,7 @@ function OpenBoatShop(shop)
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'boat_shop_confirm',
{
title = _U('boat_shop_confirm', data.current.name, data.current.price),
title = _U('boat_shop_confirm', data.current.name, ESX.Math.GroupDigits(data.current.price)),
align = 'top-left',
elements = {
{ label = _U('confirm_no'), value = 'no' },
@@ -72,15 +70,15 @@ function OpenBoatShop(shop)
ESX.TriggerServerCallback('esx_boat:buyBoat', function (bought)
if bought then
ESX.ShowNotification(_U('boat_shop_bought', data.current.name, data.current.price))
ESX.ShowNotification(_U('boat_shop_bought', data.current.name, ESX.Math.GroupDigits(data.current.price)))
DeleteSpawnedVehicles()
isInShopMenu = false
ESX.UI.Menu.CloseAll()
CurrentAction = 'boat_shop'
CurrentActionMsg = _U('boat_shop_open')
CurrentAction = 'boat_shop'
CurrentActionMsg = _U('boat_shop_open')
FreezeEntityPosition(playerPed, false)
SetEntityVisible(playerPed, true)
SetEntityCoords(playerPed, shop.Outside.x, shop.Outside.y, shop.Outside.z)
@@ -88,7 +86,7 @@ function OpenBoatShop(shop)
ESX.ShowNotification(_U('boat_shop_nomoney'))
menu2.close()
end
end, props)
else
@@ -104,8 +102,8 @@ function OpenBoatShop(shop)
isInShopMenu = false
DeleteSpawnedVehicles()
CurrentAction = 'boat_shop'
CurrentActionMsg = _U('boat_shop_open')
CurrentAction = 'boat_shop'
CurrentActionMsg = _U('boat_shop_open')
FreezeEntityPosition(playerPed, false)
SetEntityVisible(playerPed, true)
@@ -113,8 +111,8 @@ function OpenBoatShop(shop)
end, function (data, menu)
DeleteSpawnedVehicles()
ESX.Game.SpawnLocalVehicle(data.current.model, shop.Inside, shop.Inside.h, function (vehicle)
ESX.Game.SpawnLocalVehicle(data.current.model, shop.Inside, shop.Inside.w, function (vehicle)
table.insert(spawnedVehicles, vehicle)
TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
FreezeEntityPosition(vehicle, true)
@@ -123,7 +121,8 @@ function OpenBoatShop(shop)
-- spawn first vehicle
DeleteSpawnedVehicles()
ESX.Game.SpawnLocalVehicle(Config.Vehicles[1].model, shop.Inside, shop.Inside.h, function (vehicle)
ESX.Game.SpawnLocalVehicle(Config.Vehicles[1].model, shop.Inside, shop.Inside.w, function (vehicle)
table.insert(spawnedVehicles, vehicle)
TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
FreezeEntityPosition(vehicle, true)
@@ -141,28 +140,29 @@ function OpenBoatGarage(garage)
-- get all available boats
local elements = {}
for i=1, #ownedBoats, 1 do
ownedBoats[i] = json.decode(ownedBoats[i])
table.insert(elements, {
label = getVehicleLabelFromHash(ownedBoats[i].model),
label = getVehicleLabelFromHash(ownedBoats[i].model),
vehicleProps = ownedBoats[i]
})
end
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'boat_garage',
{
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'boat_garage', {
title = _U('garage'),
align = 'top-left',
elements = elements
}, function (data, menu)
-- make sure the spawn point isn't blocked
local playerPed = PlayerPedId()
local playerPed = PlayerPedId()
local vehicleProps = data.current.vehicleProps
if ESX.Game.IsSpawnPointClear(garage.SpawnPoint, 4.0) then
TriggerServerEvent('esx_boat:takeOutVehicle', vehicleProps.plate)
ESX.ShowNotification(_U('garage_taken'))
ESX.Game.SpawnVehicle(vehicleProps.model, garage.SpawnPoint, garage.SpawnPoint.h, function(vehicle)
ESX.Game.SpawnVehicle(vehicleProps.model, garage.SpawnPoint, garage.SpawnPoint.w, function(vehicle)
TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
ESX.Game.SetVehicleProperties(vehicle, vehicleProps)
end)
@@ -172,7 +172,6 @@ function OpenBoatGarage(garage)
ESX.ShowNotification(_U('garage_blocked'))
end
end, function (data, menu)
menu.close()
@@ -185,19 +184,18 @@ function OpenBoatGarage(garage)
end
function OpenLicenceMenu(shop)
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'boat_license',
{
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'boat_license', {
title = _U('license_menu'),
align = 'top-left',
elements = {
{ label = _U('license_buy_no'), value = 'no' },
{ label = _U('license_buy_yes', Config.LicensePrice), value = 'yes' }
{ label = _U('license_buy_yes', ESX.Math.GroupDigits(Config.LicensePrice)), value = 'yes' }
}
}, function (data, menu)
if data.current.value == 'yes' then
ESX.TriggerServerCallback('esx_boat:buyBoatLicense', function (boughtLicense)
if boughtLicense then
ESX.ShowNotification(_U('license_bought', Config.LicensePrice))
ESX.ShowNotification(_U('license_bought', ESX.Math.GroupDigits(Config.LicensePrice)))
menu.close()
OpenBoatShop(shop) -- parse current shop
@@ -206,19 +204,18 @@ function OpenLicenceMenu(shop)
end
end)
else
CurrentAction = 'boat_shop'
CurrentActionMsg = _U('boat_shop_open')
CurrentAction = 'boat_shop'
CurrentActionMsg = _U('boat_shop_open')
menu.close()
end
end, function (data, menu)
CurrentAction = 'boat_shop'
CurrentActionMsg = _U('boat_shop_open')
CurrentAction = 'boat_shop'
CurrentActionMsg = _U('boat_shop_open')
menu.close()
end)
end
function StoreBoatInGarage(vehicle, teleportCoords)
local vehicleProps = ESX.Game.GetVehicleProperties(vehicle)
ESX.TriggerServerCallback('esx_boat:storeVehicle', function (rowsChanged)
@@ -228,13 +225,12 @@ function StoreBoatInGarage(vehicle, teleportCoords)
local playerPed = PlayerPedId()
ESX.Game.Teleport(playerPed, teleportCoords, function()
SetEntityHeading(playerPed, teleportCoords.h)
SetEntityHeading(playerPed, teleportCoords.w)
end)
else
ESX.ShowNotification(_U('garage_notowner'))
end
end, vehicleProps.plate)
end
-- Key controls
+37 -57
View File
@@ -79,83 +79,60 @@ AddEventHandler('esx_boat:hasExitedMarker', function()
CurrentAction = nil
end)
-- Draw markers
Citizen.CreateThread(function()
while true do
Citizen.Wait(1)
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
for i=1, #Config.Zones.BoatShops, 1 do
-- draw boat shop marker
local zone = Config.Zones.BoatShops[i].Outside
if GetDistanceBetweenCoords(coords, zone.x, zone.y, zone.z, true) < Config.DrawDistance then
DrawMarker(Config.MarkerType, zone.x, zone.y, zone.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Config.Marker.x, Config.Marker.y, Config.Marker.z, Config.Marker.r, Config.Marker.g, Config.Marker.b, 100, false, true, 2, false, false, false, false)
end
end
for i=1, #Config.Zones.Garages, 1 do
-- draw garage maker
local zoneOut = Config.Zones.Garages[i].GaragePos
if GetDistanceBetweenCoords(coords, zoneOut.x, zoneOut.y, zoneOut.z, true) < Config.DrawDistance then
DrawMarker(Config.MarkerType, zoneOut.x, zoneOut.y, zoneOut.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Config.Marker.x, Config.Marker.y, Config.Marker.z, Config.Marker.r, Config.Marker.g, Config.Marker.b, 100, false, true, 2, false, false, false, false)
end
-- draw store marker
local zoneIn = Config.Zones.Garages[i].StorePos
if GetDistanceBetweenCoords(coords, zoneIn.x, zoneIn.y, zoneIn.z, true) < Config.DrawDistance then
DrawMarker(Config.MarkerType, zoneIn.x, zoneIn.y, zoneIn.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Config.StoreMarker.x, Config.StoreMarker.y, Config.StoreMarker.z, Config.StoreMarker.r, Config.StoreMarker.g, Config.StoreMarker.b, 100, false, true, 2, false, false, false, false)
end
end
end
end)
-- Enter / Exit marker events
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
Citizen.Wait(1)
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
local isInMarker = false
local currentZone = nil
local currentZoneNum = nil
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
local isInMarker, hasExited, letSleep = false, false, true
local currentZone, currentZoneNum
for i=1, #Config.Zones.BoatShops, 1 do
local distance = GetDistanceBetweenCoords(coords, Config.Zones.BoatShops[i].Outside, true)
if GetDistanceBetweenCoords(coords, Config.Zones.BoatShops[i].Outside.x, Config.Zones.BoatShops[i].Outside.y, Config.Zones.BoatShops[i].Outside.z, true) < Config.Marker.x then
if distance < Config.DrawDistance then
DrawMarker(Config.MarkerType, Config.Zones.BoatShops[i].Outside, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Config.Marker.x, Config.Marker.y, Config.Marker.z, Config.Marker.r, Config.Marker.g, Config.Marker.b, 100, false, true, 2, false, nil, nil, false)
letSleep = false
end
if distance < Config.Marker.x then
isInMarker = true
currentZone = 'boat_shop'
currentZoneNum = i
end
end
for i=1, #Config.Zones.Garages, 1 do
local distance = GetDistanceBetweenCoords(coords, Config.Zones.Garages[i].GaragePos, true)
if GetDistanceBetweenCoords(coords, Config.Zones.Garages[i].GaragePos.x, Config.Zones.Garages[i].GaragePos.y, Config.Zones.Garages[i].GaragePos.z, true) < Config.Marker.x then
if distance < Config.DrawDistance then
DrawMarker(Config.MarkerType, Config.Zones.Garages[i].GaragePos, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Config.Marker.x, Config.Marker.y, Config.Marker.z, Config.Marker.r, Config.Marker.g, Config.Marker.b, 100, false, true, 2, false, nil, nil, false)
letSleep = false
end
if distance < Config.Marker.x then
isInMarker = true
currentZone = 'garage_out'
currentZoneNum = i
end
if GetDistanceBetweenCoords(coords, Config.Zones.Garages[i].StorePos.x, Config.Zones.Garages[i].StorePos.y, Config.Zones.Garages[i].StorePos.z, true) < Config.StoreMarker.x then
distance = GetDistanceBetweenCoords(coords, Config.Zones.Garages[i].StorePos, true)
if distance < Config.DrawDistance then
DrawMarker(Config.MarkerType, Config.Zones.Garages[i].StorePos, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Config.StoreMarker.x, Config.StoreMarker.y, Config.StoreMarker.z, Config.StoreMarker.r, Config.StoreMarker.g, Config.StoreMarker.b, 100, false, true, 2, false, nil, nil, false)
letSleep = false
end
if distance < Config.StoreMarker.x then
isInMarker = true
currentZone = 'garage_in'
currentZoneNum = i
end
end
local hasExited = false
if isInMarker and not HasAlreadyEnteredMarker or (isInMarker and (LastZone ~= currentZone or LastZoneNum ~= currentZoneNum) ) then
if isInMarker and not HasAlreadyEnteredMarker or (isInMarker and (LastZone ~= currentZone or LastZoneNum ~= currentZoneNum)) then
if
(LastZone ~= nil and LastZoneNum ~= nil) and
(LastZone ~= currentZone or LastZoneNum ~= currentZoneNum)
@@ -165,18 +142,21 @@ Citizen.CreateThread(function()
end
HasAlreadyEnteredMarker = true
LastZone = currentZone
LastZoneNum = currentZoneNum
LastZone = currentZone
LastZoneNum = currentZoneNum
TriggerEvent('esx_boat:hasEnteredMarker', currentZone, currentZoneNum)
end
if not hasExited and not isInMarker and HasAlreadyEnteredMarker then
HasAlreadyEnteredMarker = false
TriggerEvent('esx_boat:hasExitedMarker')
end
if letSleep then
Citizen.Wait(500)
end
end
end)
@@ -187,7 +167,7 @@ Citizen.CreateThread(function()
for i=1, #Config.Zones.Garages, 1 do
table.insert(blipList, {
coords = { Config.Zones.Garages[i].GaragePos.x, Config.Zones.Garages[i].GaragePos.y },
coords = Config.Zones.Garages[i].GaragePos,
text = _U('blip_garage'),
sprite = 356,
color = 3,
@@ -197,7 +177,7 @@ Citizen.CreateThread(function()
for i=1, #Config.Zones.BoatShops, 1 do
table.insert(blipList, {
coords = { Config.Zones.BoatShops[i].Outside.x, Config.Zones.BoatShops[i].Outside.y },
coords = Config.Zones.BoatShops[i].Outside,
text = _U('blip_shop'),
sprite = 427,
color = 3,
@@ -212,7 +192,7 @@ Citizen.CreateThread(function()
end)
function CreateBlip(coords, text, sprite, color, scale)
local blip = AddBlipForCoord( table.unpack(coords) )
local blip = AddBlipForCoord(coords.x, coords.y)
SetBlipSprite(blip, sprite)
SetBlipScale(blip, scale)