esx garage update, impounds, fix on the ui

This commit is contained in:
Benzo
2022-06-13 08:59:40 +02:00
committed by GitHub
parent c75c2ade8f
commit 54810522b8
10 changed files with 791 additions and 162 deletions
+16
View File
@@ -0,0 +1,16 @@
# esx_garage
ESX Garage
[INSTALLATION]
1) CD in your resources/[esx] folder
2) Clone the repository
```
git clone https://github.com/esx-framework/esx-legacy esx_garage
```
3) Import esx_garage.sql in your database
4) Add this in your server.cfg :
```
start esx_garage
```
+310 -71
View File
@@ -1,17 +1,18 @@
local LastGarage, LastPart, thisGarage = nil, nil, nil
local next = next
local nearMarker, menuIsShowed = false, false
local vehiclesList = {}
local LastMarker, LastPart, thisGarage, thisPound = nil, nil, nil, nil
local next = next
local nearMarker, menuIsShowed = false, false
local vehiclesList, vehiclesImpoundedList = {}, {}
RegisterNetEvent('esx_garage:closemenu')
AddEventHandler('esx_garage:closemenu', function()
menuIsShowed = false
vehiclesList = {}
menuIsShowed = false
vehiclesList, vehiclesImpoundedList = {}, {}
SetNuiFocus(false)
SendNUIMessage({hideAll = true})
if not menuIsShowed and thisGarage then ESX.TextUI(_U('access_parking')) end
if not menuIsShowed and thisPound then ESX.TextUI(_U('access_pound')) end
end)
RegisterNUICallback('escape', function(data, cb)
@@ -26,22 +27,71 @@ RegisterNUICallback('spawnVehicle', function(data, cb)
z = data.spawnPoint.z
}
if ESX.Game.IsSpawnPointClear(spawnCoords, 2.5) then
ESX.Game.SpawnVehicle(data.vehicleProps.model, spawnCoords,
data.spawnPoint.heading, function(vehicle)
TaskWarpPedIntoVehicle(PlayerPedId(), vehicle, -1)
ESX.Game.SetVehicleProperties(vehicle, data.vehicleProps)
SetVehicleEngineOn(vehicle, (not GetIsVehicleEngineRunning(vehicle)), true, true)
end)
thisGarage = nil
TriggerServerEvent('esx_garage:updateOwnedVehicle', false, nil, data.vehicleProps)
TriggerEvent('esx_garage:closemenu')
if thisGarage ~= nil then
if ESX.Game.IsSpawnPointClear(spawnCoords, 2.5) then
ESX.Game.SpawnVehicle(data.vehicleProps.model, spawnCoords,
data.spawnPoint.heading, function(vehicle)
TaskWarpPedIntoVehicle(PlayerPedId(), vehicle, -1)
ESX.Game.SetVehicleProperties(vehicle, data.vehicleProps)
SetVehicleEngineOn(vehicle, (not GetIsVehicleEngineRunning(vehicle)), true, true)
end)
thisGarage = nil
TriggerServerEvent('esx_garage:updateOwnedVehicle', false, nil, nil, data.vehicleProps)
TriggerEvent('esx_garage:closemenu')
ESX.ShowNotification(_U('veh_released'))
else
ESX.ShowNotification(_U('veh_block'), 'error')
end
elseif thisPound ~= nil then
ESX.TriggerServerCallback('esx_garage:checkMoney',
function(hasMoney)
if hasMoney then
if ESX.Game.IsSpawnPointClear(spawnCoords, 2.5) then
TriggerServerEvent('esx_garage:payPound', data.exitVehicleCost)
ESX.Game.SpawnVehicle(data.vehicleProps.model, spawnCoords,
data.spawnPoint.heading, function(vehicle)
TaskWarpPedIntoVehicle(PlayerPedId(), vehicle, -1)
ESX.Game.SetVehicleProperties(vehicle, data.vehicleProps)
SetVehicleEngineOn(vehicle, (not GetIsVehicleEngineRunning(vehicle)), true, true)
end)
thisPound = nil
TriggerServerEvent('esx_garage:updateOwnedVehicle', false, nil, nil, data.vehicleProps)
TriggerEvent('esx_garage:closemenu')
else
ESX.ShowNotification(_U('veh_block'), 'error')
end
else
ESX.ShowNotification(_U('missing_money'))
end
end, data.exitVehicleCost)
else
ESX.ShowNotification(_U('veh_block'), 'error')
end
cb('ok')
end)
RegisterNUICallback('impound', function(data, cb)
local poundCoords = {
x = data.poundSpawnPoint.x,
y = data.poundSpawnPoint.y,
}
TriggerServerEvent('esx_garage:setImpound', data.poundName, data.vehicleProps)
TriggerEvent('esx_garage:closemenu')
SetNewWaypoint(poundCoords.x, poundCoords.y)
cb('ok')
end)
@@ -50,14 +100,28 @@ CreateThread(function()
for k, v in pairs(Config.Garages) do
local blip = AddBlipForCoord(v.EntryPoint.x, v.EntryPoint.y, v.EntryPoint.z)
SetBlipSprite(blip, Config.Blips.Sprite)
SetBlipSprite(blip, Config.Blips.Parking.Sprite)
SetBlipDisplay(blip, 4)
SetBlipScale(blip, Config.Blips.Scale)
SetBlipColour(blip, Config.Blips.Colour)
SetBlipScale(blip, Config.Blips.Parking.Scale)
SetBlipColour(blip, Config.Blips.Parking.Colour)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentSubstringPlayerName(_U('blip_name'))
AddTextComponentSubstringPlayerName(_U('parking_blip_name'))
EndTextCommandSetBlipName(blip)
end
for k, v in pairs(Config.Pounds) do
local blip = AddBlipForCoord(v.GetOutPoint.x, v.GetOutPoint.y, v.GetOutPoint.z)
SetBlipSprite(blip, Config.Blips.Pound.Sprite)
SetBlipDisplay(blip, 4)
SetBlipScale(blip, Config.Blips.Pound.Scale)
SetBlipColour(blip, Config.Blips.Pound.Colour)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentSubstringPlayerName(_U('pound_blip_name'))
EndTextCommandSetBlipName(blip)
end
end)
@@ -65,7 +129,7 @@ end)
AddEventHandler('esx_garage:hasEnteredMarker', function(name, part)
if part == 'EntryPoint' then
local garage = Config.Garages[name]
thisGarage = garage
thisGarage = garage
ESX.TextUI(_U('access_parking'))
end
@@ -78,10 +142,18 @@ AddEventHandler('esx_garage:hasEnteredMarker', function(name, part)
if isInVehicle then ESX.TextUI(_U('park_veh')) end
end
if part == 'GetOutPoint' then
local pound = Config.Pounds[name]
thisPound = pound
ESX.TextUI(_U('access_pound'))
end
end)
AddEventHandler('esx_garage:hasExitedMarker', function()
thisGarage = nil
thisPound = nil
ESX.HideUI()
TriggerEvent('esx_garage:closemenu')
end)
@@ -95,18 +167,28 @@ CreateThread(function()
local coords = GetEntityCoords(playerPed)
local inVehicle = IsPedInAnyVehicle(playerPed, false)
-- parking
for k, v in pairs(Config.Garages) do
if (#(coords - vector3(v.EntryPoint.x, v.EntryPoint.y, v.EntryPoint.z)) < Config.DrawDistance) then
DrawMarker(Config.Markers.EntryPoint.Type, v.EntryPoint.x, v.EntryPoint.y, v.EntryPoint.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, Config.Markers.EntryPoint.Size.x, Config.Markers.EntryPoint.Size.y, Config.Markers.EntryPoint.Size.z, Config.Markers.EntryPoint.Color.r, Config.Markers.EntryPoint.Color.g, Config.Markers.EntryPoint.Color.b, 100, false, true, 2, false, false, false, false)
sleep = 0
break
end
if IsPedInAnyVehicle(playerPed, true) then
if (#(coords -
vector3(v.StorePoint.x, v.StorePoint.y, v.StorePoint.z)) < Config.DrawDistance) then
DrawMarker(Config.Markers.StorePoint.Type, v.StorePoint.x, v.StorePoint.y, v.StorePoint.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, Config.Markers.StorePoint.Size.x, Config.Markers.StorePoint.Size.y, Config.Markers.StorePoint.Size.z, Config.Markers.StorePoint.Color.r, Config.Markers.StorePoint.Color.g, Config.Markers.StorePoint.Color.b, 100, false, true, 2, false, false, false, false)
sleep = 0
end
end
end
-- pound
for k, v in pairs(Config.Pounds) do
if (#(coords - vector3(v.GetOutPoint.x, v.GetOutPoint.y, v.GetOutPoint.z)) < Config.DrawDistance) then
DrawMarker(Config.Markers.GetOutPoint.Type, v.GetOutPoint.x, v.GetOutPoint.y, v.GetOutPoint.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, Config.Markers.GetOutPoint.Size.x, Config.Markers.GetOutPoint.Size.y, Config.Markers.GetOutPoint.Size.z, Config.Markers.GetOutPoint.Color.r, Config.Markers.GetOutPoint.Color.g, Config.Markers.GetOutPoint.Color.b, 100, false, true, 2, false, false, false, false)
sleep = 0
break
end
end
@@ -115,25 +197,26 @@ CreateThread(function()
else
nearMarker = false
end
Wait(sleep)
end
end)
-- Enter / Exit marker events
-- Enter / Exit marker events (parking)
CreateThread(function()
while true do
if nearMarker then
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
local isInMarker = false
local currentGarage = nil
local currentMarker = nil
local currentPart = nil
for k, v in pairs(Config.Garages) do
if (#(coords - vector3(v.EntryPoint.x, v.EntryPoint.y, v.EntryPoint.z)) < Config.Markers.EntryPoint.Size.x) then
isInMarker = true
currentGarage = k
currentPart = 'EntryPoint'
isInMarker = true
currentMarker = k
currentPart = 'EntryPoint'
if IsControlJustReleased(0, 38) and not menuIsShowed then
ESX.TriggerServerCallback('esx_garage:getVehiclesInParking',
@@ -141,15 +224,10 @@ CreateThread(function()
if next(vehicles) ~= nil then
menuIsShowed = true
-- vehicles[i].vehicle.bodyHealth
-- vehicles[i].vehicle.engineHealth
-- vehicles[i].vehicle.tankHealth
for i = 1, #vehicles, 1 do
table.insert(vehiclesList, {
model = GetDisplayNameFromVehicleModel(vehicles[i].vehicle.model),
plate = vehicles[i].plate,
damage = vehicles[i].damage,
props = vehicles[i].vehicle
})
@@ -162,14 +240,199 @@ CreateThread(function()
heading = v.SpawnPoint.heading
}
ESX.TriggerServerCallback('esx_garage:getVehiclesImpounded',
function(vehicles)
if next(vehicles) ~= nil then
for i = 1, #vehicles, 1 do
table.insert(vehiclesImpoundedList, {
model = GetDisplayNameFromVehicleModel(vehicles[i].vehicle.model),
plate = vehicles[i].plate,
props = vehicles[i].vehicle
})
end
local poundSpawnPoint = {
x = Config.Pounds[v.ImpoundedName].GetOutPoint.x,
y = Config.Pounds[v.ImpoundedName].GetOutPoint.y,
}
SendNUIMessage({
showMenu = true,
type = 'garage',
vehiclesList = {
json.encode(vehiclesList)
},
vehiclesImpoundedList = {
json.encode(vehiclesImpoundedList)
},
poundName = v.ImpoundedName,
poundSpawnPoint = poundSpawnPoint,
spawnPoint = spawnPoint,
locales = {
action = _U('veh_exit'),
veh_model = _U('veh_model'),
veh_plate = _U('veh_plate'),
veh_condition = _U('veh_condition'),
veh_action = _U('veh_action'),
impound_action = _U('impound_action'),
}
})
else
SendNUIMessage({
showMenu = true,
type = 'garage',
vehiclesList = {
json.encode(vehiclesList)
},
spawnPoint = spawnPoint,
locales = {
action = _U('veh_exit'),
veh_model = _U('veh_model'),
veh_plate = _U('veh_plate'),
veh_condition = _U('veh_condition'),
veh_action = _U('veh_action'),
no_veh_impounded = _U('no_veh_impounded'),
}
})
end
end)
SetNuiFocus(true, true)
if menuIsShowed then
ESX.HideUI()
end
else
menuIsShowed = true
ESX.TriggerServerCallback('esx_garage:getVehiclesImpounded',
function(vehicles)
if next(vehicles) ~= nil then
for i = 1, #vehicles, 1 do
table.insert(vehiclesImpoundedList, {
model = GetDisplayNameFromVehicleModel(vehicles[i].vehicle.model),
plate = vehicles[i].plate,
props = vehicles[i].vehicle
})
end
local poundSpawnPoint = {
x = Config.Pounds[v.ImpoundedName].GetOutPoint.x,
y = Config.Pounds[v.ImpoundedName].GetOutPoint.y,
}
SendNUIMessage({
showMenu = true,
type = 'garage',
vehiclesImpoundedList = {
json.encode(vehiclesImpoundedList)
},
poundName = v.ImpoundedName,
poundSpawnPoint = poundSpawnPoint,
locales = {
action = _U('veh_exit'),
veh_model = _U('veh_model'),
veh_plate = _U('veh_plate'),
veh_condition = _U('veh_condition'),
veh_action = _U('veh_action'),
no_veh_parking = _U('no_veh_parking'),
no_veh_impounded = _U('no_veh_impounded'),
impound_action = _U('impound_action'),
}
})
else
SendNUIMessage({
showMenu = true,
type = 'garage',
locales = {
action = _U('veh_exit'),
veh_model = _U('veh_model'),
veh_plate = _U('veh_plate'),
veh_condition = _U('veh_condition'),
veh_action = _U('veh_action'),
no_veh_parking = _U('no_veh_parking')
}
})
end
end)
SetNuiFocus(true, true)
if menuIsShowed then
ESX.HideUI()
end
-- ESX.ShowNotification(_U('no_veh_parking'))
end
end, currentMarker)
end
break
end
if (#(coords - vector3(v.StorePoint.x, v.StorePoint.y, v.StorePoint.z)) < Config.Markers.StorePoint.Size.x) then
isInMarker = true
currentMarker = k
currentPart = 'StorePoint'
local isInVehicle = IsPedInAnyVehicle(playerPed, false)
if isInVehicle then
if IsControlJustReleased(0, 38) then
local vehicle = GetVehiclePedIsIn(playerPed, false)
local vehicleProps = ESX.Game.GetVehicleProperties(vehicle)
ESX.TriggerServerCallback('esx_garage:checkVehicleOwner', function(owner)
if owner then
ESX.Game.DeleteVehicle(vehicle)
TriggerServerEvent('esx_garage:updateOwnedVehicle', true, currentMarker, nil, vehicleProps)
else
ESX.ShowNotification(_U('not_owning_veh'), 'error')
end
end, vehicleProps.plate)
end
end
end
end
for k, v in pairs(Config.Pounds) do
if (#(coords - vector3(v.GetOutPoint.x, v.GetOutPoint.y, v.GetOutPoint.z)) < Config.Markers.GetOutPoint.Size.x) then
isInMarker = true
currentMarker = k
currentPart = 'GetOutPoint'
if IsControlJustReleased(0, 38) and not menuIsShowed then
ESX.TriggerServerCallback('esx_garage:getVehiclesInPound',
function(vehicles)
if next(vehicles) ~= nil then
menuIsShowed = true
for i = 1, #vehicles, 1 do
table.insert(vehiclesList, {
model = GetDisplayNameFromVehicleModel(vehicles[i].vehicle.model),
plate = vehicles[i].plate,
props = vehicles[i].vehicle
})
end
local spawnPoint = {
x = v.SpawnPoint.x,
y = v.SpawnPoint.y,
z = v.SpawnPoint.z,
heading = v.SpawnPoint.heading
}
SendNUIMessage({
showMenu = true,
type = 'impound',
vehiclesList = {
json.encode(vehiclesList)
},
spawnPoint = spawnPoint,
poundCost = v.Cost,
locales = {
action = _U('veh_exit'),
action = _U('pay_pound'),
veh_model = _U('veh_model'),
veh_plate = _U('veh_plate'),
veh_condition = _U('veh_condition'),
@@ -183,49 +446,25 @@ CreateThread(function()
ESX.HideUI()
end
else
ESX.ShowNotification(_U('no_veh_parking'))
ESX.ShowNotification(_U('no_veh_pound'))
end
end, currentGarage)
end, currentMarker)
end
break
end
if (#(coords -
vector3(v.StorePoint.x, v.StorePoint.y, v.StorePoint.z)) < Config.Markers.StorePoint.Size.x) then
isInMarker = true
currentGarage = k
currentPart = 'StorePoint'
local isInVehicle = IsPedInAnyVehicle(playerPed, false)
if isInVehicle then
if IsControlJustReleased(0, 38) then
local vehicle = GetVehiclePedIsIn(playerPed, false)
local vehicleProps = ESX.Game.GetVehicleProperties(vehicle)
ESX.TriggerServerCallback('esx_garage:checkVehicleOwner', function(owner)
if owner then
ESX.Game.DeleteVehicle(vehicle)
TriggerServerEvent('esx_garage:updateOwnedVehicle', true, currentGarage, vehicleProps)
else
ESX.ShowNotification(_U('not_owning_veh'), 'error')
end
end, vehicleProps.plate)
end
end
end
end
if isInMarker and not HasAlreadyEnteredMarker or (isInMarker and (LastGarage ~= currentGarage or LastPart ~= currentPart)) then
if LastGarage ~= currentGarage or LastPart ~= currentPart then
TriggerEvent('esx_garage:hasExitedMarker', LastGarage,
LastPart)
if isInMarker and not HasAlreadyEnteredMarker or (isInMarker and (LastMarker ~= currentMarker or LastPart ~= currentPart)) then
if LastMarker ~= currentMarker or LastPart ~= currentPart then
TriggerEvent('esx_garage:hasExitedMarker')
end
HasAlreadyEnteredMarker = true
LastGarage = currentGarage
LastPart = currentPart
LastMarker = currentMarker
LastPart = currentPart
TriggerEvent('esx_garage:hasEnteredMarker', currentGarage, currentPart)
TriggerEvent('esx_garage:hasEnteredMarker', currentMarker, currentPart)
end
if not isInMarker and HasAlreadyEnteredMarker then
+71 -4
View File
@@ -2,9 +2,16 @@ Config = {}
Config.Locale = 'en'
Config.Blips = {
Sprite = 357,
Scale = 1.0,
Colour = 3,
Parking = {
Sprite = 357,
Scale = 1.0,
Colour = 3,
},
Pound = {
Sprite = 794,
Scale = 1.0,
Colour = 1,
},
}
Config.DrawDistance = 10.0
@@ -35,7 +42,20 @@ Config.Markers = {
g = 51,
b = 51,
}
}
},
GetOutPoint = {
Type = 1,
Size = {
x = 2.0,
y = 2.0,
z = 1.0
},
Color = {
r = 54,
g = 51,
b = 255,
}
},
}
Config.Garages = {
@@ -56,6 +76,7 @@ Config.Garages = {
z = 31.0,
heading = 351.8
},
ImpoundedName = 'LosSantos',
},
SanAndreasAvenue = {
EntryPoint = {
@@ -74,5 +95,51 @@ Config.Garages = {
z = 30.8,
heading = 338.8
},
ImpoundedName = 'LosSantos',
},
}
Config.Pounds = {
LosSantos = {
GetOutPoint = {
x = 400.7,
y = -1630.5,
z = 28.3
},
SpawnPoint = {
x = 401.9,
y = -1647.4,
z = 29.2,
heading = 323.3
},
Cost = 3000
},
PaletoBay = {
GetOutPoint = {
x = -211.4,
y = 6206.5,
z = 30.4
},
SpawnPoint = {
x = -204.6,
y = 6221.6,
z = 30.5,
heading = 227.2
},
Cost = 3000
},
SandyShores = {
GetOutPoint = {
x = 1728.2,
y = 3709.3,
z = 33.2,
},
SpawnPoint = {
x = 1722.7,
y = 3713.6,
z = 33.2,
heading = 19.9
},
Cost = 3000
},
}
+3 -1
View File
@@ -1 +1,3 @@
ALTER TABLE `owned_vehicles` ADD `parking` VARCHAR(60) NULL AFTER `stored`;
DROP TABLE `user_parkings`;
ALTER TABLE `owned_vehicles` ADD `parking` VARCHAR(60) NULL AFTER `stored`;
ALTER TABLE `owned_vehicles` ADD `pound` VARCHAR(60) NULL AFTER `parking`;
+23 -13
View File
@@ -1,15 +1,25 @@
Locales["en"] = {
["blip_name"] = 'Garage',
["access_parking"] = 'press [E] to access the car park.',
["park_veh"] = 'press [E] to park the vehicle.',
["not_owning_veh"] = 'this vehicle does not belong to you.',
['veh_released'] = 'the vehicle has been released from the parking.',
['veh_stored'] = 'the vehicle has been stored.',
['no_veh_parking'] = 'you have no vehicle in this car park.',
['veh_model'] = 'model',
['veh_plate'] = 'plate',
['veh_condition'] = 'condition',
['veh_action'] = 'action',
['veh_exit'] = 'exit the vehicle',
['veh_block'] = 'it looks like a vehicle is blocking the exit.'
["parking_blip_name"] = 'Garage',
["pound_blip_name"] = 'Pound',
["access_parking"] = 'press [E] to access the car park.',
["access_pound"] = 'press [E] to access the pound.',
["park_veh"] = 'press [E] to park the vehicle.',
["not_owning_veh"] = 'this vehicle does not belong to you.',
['veh_released'] = 'the vehicle has been released from the parking.',
['veh_pound_released'] = 'the vehicle has been released from the pound.',
['veh_stored'] = 'the vehicle has been stored.',
['veh_impounded'] = 'the vehicle was impounded.',
['no_veh_parking'] = 'no vehicles in this garage.',
['no_veh_impounded'] = 'no vehicles impounded.',
['no_veh_pound'] = 'you have no vehicle in this pound.',
['veh_model'] = 'model',
['veh_plate'] = 'plate',
['veh_condition'] = 'condition',
['veh_action'] = 'action',
['impound_action'] = 'impound',
['veh_exit'] = 'exit the vehicle',
['pay_pound'] = 'pay the pound bill',
['veh_block'] = 'it looks like a vehicle is blocking the exit.',
['pay_pound_bill'] = 'you just paid ~g~$%s~s~ at the pound.',
['missing_money'] = 'you do not have enough money.',
}
+23 -13
View File
@@ -1,15 +1,25 @@
Locales["fr"] = {
["blip_name"] = "Garage",
["access_parking"] = "appuyez sur [E] pour accéder au parking.",
["park_veh"] = "appuyez sur [E] pour ranger le véhicule.",
["not_owning_veh"] = "ce véhicule ne t'appartient pas.",
['veh_released'] = 'le véhicule a été sorti du parking.',
['veh_stored'] = 'le véhicule a bien été rangé.',
['no_veh_parking'] = 'vous n\'avez aucun véhicule dans ce parking.',
['veh_model'] = 'modèle',
['veh_plate'] = 'immatriculation',
['veh_condition'] = 'etat',
['veh_action'] = 'action',
['veh_exit'] = 'sortir le véhicule',
['veh_block'] = 'il semble qu\'un véhicule gêne la sortie.'
["parking_blip_name"] = 'Garage',
["pound_blip_name"] = 'Fourrière',
["access_parking"] = "appuyez sur [E] pour accéder au parking.",
["access_pound"] = 'appuyez sur [E] pour accéder à la fourrière.',
["park_veh"] = "appuyez sur [E] pour ranger le véhicule.",
["not_owning_veh"] = "ce véhicule ne t'appartient pas.",
['veh_released'] = 'le véhicule a été sorti du parking.',
['veh_pound_released'] = 'the vehicle has been released from the pound.',
['veh_stored'] = 'le véhicule a bien été rangé.',
['veh_impounded'] = 'le véhicule a bien été mis en fourrière.',
['no_veh_parking'] = 'aucun véhicule dans ce parking.',
['no_veh_impounded'] = 'aucun véhicule à mettre en fourrière.',
['no_veh_pound'] = 'vous n\'avez aucun véhicule dans cette fourrière.',
['veh_model'] = 'modèle',
['veh_plate'] = 'immatriculation',
['veh_condition'] = 'etat',
['veh_action'] = 'action',
['impound_action'] = 'impound',
['veh_exit'] = 'sortir le véhicule',
['pay_pound'] = 'payer la fourrière',
['veh_block'] = 'il semble qu\'un véhicule gêne la sortie.',
['pay_pound_bill'] = 'vous venez de payer $%s à la fourrière.',
['missing_money'] = 'vous n\'avez pas assez d\'argent.'
}
+82 -8
View File
@@ -35,18 +35,44 @@ body {
color: white;
font-size: 44px;
border-radius: 0px 0px 0px 10px;
text-align: center;
padding: 50px;
background: #353e4f;
display: flex;
flex-wrap: wrap;
align-content: space-between;
justify-content: center;
width: 10%;
justify-content: space-between;
flex-direction: column;
align-items: baseline;
}
#header .title {
padding: 50px;
}
#header ul {
font-size: 15px;
margin-top: -150px;
padding: 0px;
list-style-type: none;
}
#header li {
cursor: pointer;
padding: 15px;
width: 296px;
}
#header li:hover {
font-weight: bold;
background-color: rgba(0, 0, 0, 0.356);
border-right: 3px solid #7186ad;
}
#header li.selected {
font-weight: bold;
background-color: rgba(0, 0, 0, 0.356);
border-right: 3px solid #7186ad;
}
#header .close {
float: right;
text-align: center;
color: #b90000;
font-size: 20px;
font-weight: bold;
@@ -60,6 +86,7 @@ body {
-webkit-border-radius: 50%;
height: 25px;
width: 25px;
margin: 30px 144px;
}
#header .close:hover {
@@ -91,10 +118,45 @@ body {
scrollbar-width: none; /* Firefox */
}
.content h2 {
width: 290px;
height: 290px;
position: absolute;
top: 50%;
left: 55%;
margin: -25px 0 0 -25px;
text-align: center;
}
.content::-webkit-scrollbar {
display: none;
}
.impounded_content {
display: none;
width: 100%;
margin: 20px;
color: white;
height: 655px;
overflow-y: auto;
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}
.impounded_content h2 {
width: 290px;
height: 290px;
position: absolute;
top: 50%;
left: 55%;
margin: -25px 0 0 -25px;
text-align: center;
}
.impounded_content::-webkit-scrollbar {
display: none;
}
.webgl {
position: fixed;
left: 0;
@@ -158,7 +220,7 @@ input::-webkit-inner-spin-button {
padding: 20px 35px;
font-size: 18px;
text-align: center;
width: 274px;
width: 229px;
}
.vehicle-listing div {
@@ -194,7 +256,7 @@ input::-webkit-inner-spin-button {
color: #ffffff;
font-size: 17px;
font-weight: bold;
padding: 20px 45px;
padding: 20px 30px;
margin: 15px;
text-shadow: -1px 1px 2px #00000026;
}
@@ -203,3 +265,15 @@ input::-webkit-inner-spin-button {
background: linear-gradient(to bottom, #72b352 5%, #77b55a 100%);
background-color: #72b352;
}
.vehicle-action.red {
border: 1px solid #8f2929;
background: linear-gradient(to bottom, #b55a5a 5%, #b35252 100%);
background-color: #b55a5a;
}
.vehicle-action.red:hover {
border: 1px solid #8f2c29;
background: linear-gradient(to bottom, #b55a5a 5%, #b35852 100%);
background-color: #b55a5a;
}
+160 -39
View File
@@ -4,16 +4,49 @@ $(window).ready(function () {
if (data.showMenu) {
$("#container").fadeIn();
$("#container").data("spawnpoint", data.spawnPoint);
$("#menu").fadeIn();
$("#vehicle-list").html(getVehicles(data.locales, data.vehiclesList));
if (data.type === 'impound') {
$('#header ul').hide();
} else {
$('#header ul').show();
}
if (data.vehiclesList != undefined) {
$("#container").data("spawnpoint", data.spawnPoint);
if (data.poundCost) $("#container").data("poundcost", data.poundCost);
$(".content .vehicle-list").html(getVehicles(data.locales, data.vehiclesList));
$('.content h2').hide();
} else {
$('.content h2').show();
$('.content .vehicle-list').empty();
}
if (data.vehiclesImpoundedList != undefined) {
$(".impounded_content").data("poundName", data.poundName);
$(".impounded_content").data("poundSpawnPoint", data.poundSpawnPoint);
if (data.poundCost) $("#container").data("poundcost", data.poundCost);
$(".impounded_content .vehicle-list").html(getImpoundedVehicles(data.locales, data.vehiclesImpoundedList));
$('.impounded_content h2').hide();
} else {
$('.impounded_content h2').show();
$('.impounded_content .vehicle-list').empty();
}
// Locales
// $(".vehicle-listing").html($(".vehicle-listing").html().replace("Model", data.locales.veh_model));
// $(".vehicle-listing").html($(".vehicle-listing").html().replace("Plate", data.locales.veh_plate));
// $(".vehicle-listing").html($(".vehicle-listing").html().replace("Vehicle condition", data.locales.veh_condition));
// $(".vehicle-listing").html($(".vehicle-listing").html().replace("Action", data.locales.veh_action));
// needs a rework
// $(".content h2").html(function (i, text) {
// return text.replace("No vehicle in this garage.", data.locales.no_veh_parking);
// });
// $(".impounded_content h2").html(function (i, text) {
// return text.replace("No vehicle impounded.", data.locales.no_veh_impounded);
// });
$(".vehicle-listing").html(function (i, text) {
return text.replace("Model", data.locales.veh_model);
@@ -34,59 +67,147 @@ $(window).ready(function () {
$(".close").click(function (event) {
$("#container").hide();
$.post("https://esx_garage/escape", "{}");
$(".impounded_content").hide();
$(".content").show();
$('li[data-page="garage"]').addClass("selected")
$('li[data-page="impounded"]').removeClass("selected")
});
document.onkeyup = function (data) {
if (data.which == 27) {
$.post("https://esx_garage/escape", "{}");
$(".impounded_content").hide();
$(".content").show();
$('li[data-page="garage"]').addClass("selected")
$('li[data-page="impounded"]').removeClass("selected")
}
};
function getVehicles(locale, vehicle) {
let html = "";
let vehicleData = JSON.parse(vehicle);
let bodyHealth = 1000;
let engineHealth = 1000;
let tankHealth = 1000;
let vehicleDamagePercent = "";
function getVehicles(locale, vehicle) {
let html = "";
let vehicleData = JSON.parse(vehicle);
let bodyHealth = 1000;
let engineHealth = 1000;
let tankHealth = 1000;
let vehicleDamagePercent = "";
for (let i = 0; i < vehicleData.length; i++) {
bodyHealth = (vehicleData[i].props.bodyHealth / 1000) * 100;
engineHealth = (vehicleData[i].props.engineHealth / 1000) * 100;
tankHealth = (vehicleData[i].props.tankHealth / 1000) * 100;
for (let i = 0; i < vehicleData.length; i++) {
bodyHealth = (vehicleData[i].props.bodyHealth / 1000) * 100;
engineHealth = (vehicleData[i].props.engineHealth / 1000) * 100;
tankHealth = (vehicleData[i].props.tankHealth / 1000) * 100;
vehicleDamagePercent =
Math.round(((bodyHealth + engineHealth + tankHealth) / 300) * 100) +
"%";
vehicleDamagePercent =
Math.round(((bodyHealth + engineHealth + tankHealth) / 300) * 100) +
"%";
html += "<div class='vehicle-listing'>";
html += "<div>Model: <strong>" + vehicleData[i].model + "</strong></div>";
html += "<div>Plate: <strong>" + vehicleData[i].plate + "</strong></div>";
html +=
"<div>Condition: <strong>" + vehicleDamagePercent + "</strong></div>";
html +=
"<button class='vehicle-action unstyled-button' data-vehprops='" +
JSON.stringify(vehicleData[i].props) +
"'>" +
locale.action +
"</button>";
html += "</div>";
}
return html;
html += "<div class='vehicle-listing'>";
html += "<div>Model: <strong>" + vehicleData[i].model + "</strong></div>";
html += "<div>Plate: <strong>" + vehicleData[i].plate + "</strong></div>";
html +=
"<div>Condition: <strong>" + vehicleDamagePercent + "</strong></div>";
html +=
"<button data-button='spawn' class='vehicle-action unstyled-button' data-vehprops='" +
JSON.stringify(vehicleData[i].props) +
"'>" +
locale.action +
"</button>";
html += "</div>";
}
$(document).on("click", "button.vehicle-action", function (event) {
let spawnPoint = $("#container").data("spawnpoint");
let vehicleProps = $(this).data("vehprops");
let vehicleDamage = $(this).data("vehdamage");
return html;
}
function getImpoundedVehicles(locale, vehicle) {
let html = "";
let vehicleData = JSON.parse(vehicle);
let bodyHealth = 1000;
let engineHealth = 1000;
let tankHealth = 1000;
let vehicleDamagePercent = "";
for (let i = 0; i < vehicleData.length; i++) {
bodyHealth = (vehicleData[i].props.bodyHealth / 1000) * 100;
engineHealth = (vehicleData[i].props.engineHealth / 1000) * 100;
tankHealth = (vehicleData[i].props.tankHealth / 1000) * 100;
vehicleDamagePercent =
Math.round(((bodyHealth + engineHealth + tankHealth) / 300) * 100) +
"%";
html += "<div class='vehicle-listing'>";
html += "<div>Model: <strong>" + vehicleData[i].model + "</strong></div>";
html += "<div>Plate: <strong>" + vehicleData[i].plate + "</strong></div>";
html +=
"<div>Condition: <strong>" + vehicleDamagePercent + "</strong></div>";
html +=
"<button data-button='impounded' class='vehicle-action red unstyled-button' data-vehprops='" +
JSON.stringify(vehicleData[i].props) +
"'>" +
locale.impound_action +
"</button>";
html += "</div>";
}
return html;
}
$('li[data-page="garage"]').click(function(event) {
$(".impounded_content").hide();
$(".content").show();
$('li[data-page="garage"]').addClass("selected")
$('li[data-page="impounded"]').removeClass("selected")
});
$('li[data-page="impounded"]').click(function(event) {
$(".content").hide();
$(".impounded_content").show();
$('li[data-page="impounded"]').addClass("selected")
$('li[data-page="garage"]').removeClass("selected")
});
$(document).on("click", "button[data-button='spawn'].vehicle-action", function (event) {
let spawnPoint = $("#container").data("spawnpoint");
let poundCost = $("#container").data("poundcost");
let vehicleProps = $(this).data("vehprops");
// prevent empty cost
if (poundCost === undefined) poundCost = 0;
$.post(
"https://esx_garage/spawnVehicle",
JSON.stringify({
vehicleProps: vehicleProps,
spawnPoint: spawnPoint,
exitVehicleCost: poundCost
})
);
$(".impounded_content").hide();
$(".content").show();
$('li[data-page="garage"]').addClass("selected")
$('li[data-page="impounded"]').removeClass("selected")
});
$(document).on("click", "button[data-button='impounded'].vehicle-action", function (event) {
let vehicleProps = $(this).data("vehprops");
let poundName = $(".impounded_content").data("poundName");
let poundSpawnPoint = $(".impounded_content").data("poundSpawnPoint");
$.post(
"https://esx_garage/impound",
JSON.stringify({
vehicleProps: vehicleProps,
poundName: poundName,
poundSpawnPoint: poundSpawnPoint
})
);
$(".impounded_content").hide();
$(".content").show();
$('li[data-page="garage"]').addClass("selected")
$('li[data-page="impounded"]').removeClass("selected")
});
});
+13 -2
View File
@@ -6,12 +6,23 @@
<body>
<div id="container">
<div id="header">
<div style="display: inline">ESX garage</div>
<div class="title" style="display: inline">ESX garage</div>
<ul>
<li data-page="garage" class="selected">Garage</li>
<li data-page="impounded">Impounded</li>
</ul>
<div class="close">X</div>
</div>
<div id="menu">
<div class="content">
<div id="vehicle-list"></div>
<h2>No vehicle in this garage.</h2>
<div class="vehicle-list"></div>
</div>
<div class="impounded_content">
<h2>No vehicle impounded.</h2>
<div class="vehicle-list"></div>
</div>
</div>
</div>
+90 -11
View File
@@ -1,28 +1,46 @@
RegisterServerEvent('esx_garage:updateOwnedVehicle')
AddEventHandler('esx_garage:updateOwnedVehicle', function(stored, parking, vehicleProps)
AddEventHandler('esx_garage:updateOwnedVehicle', function(stored, parking, pound, vehicleProps)
local source = source
local xPlayer = ESX.GetPlayerFromId(source)
MySQL.update('UPDATE owned_vehicles SET stored = @stored, parking = @parking, vehicle = @vehicle WHERE plate = @plate AND owner = @identifier',
MySQL.update('UPDATE owned_vehicles SET `stored` = @stored, `parking` = @parking, `pound` = @pound, `vehicle` = @vehicle WHERE `plate` = @plate AND `owner` = @identifier',
{
['@identifier'] = xPlayer.identifier,
['@vehicle'] = json.encode(vehicleProps),
['@plate'] = vehicleProps.plate,
['@stored'] = stored,
['@parking'] = parking
['@parking'] = parking,
['@pound'] = pound
})
if stored then
xPlayer.showNotification(_U('veh_stored'))
else
xPlayer.showNotification(_U('veh_released'))
end
end)
RegisterServerEvent('esx_garage:setImpound')
AddEventHandler('esx_garage:setImpound', function(pound, vehicleProps)
local source = source
local xPlayer = ESX.GetPlayerFromId(source)
MySQL.update('UPDATE owned_vehicles SET `stored` = @stored, `pound` = @pound, `vehicle` = @vehicle WHERE `plate` = @plate AND `owner` = @identifier',
{
['@identifier'] = xPlayer.identifier,
['@vehicle'] = json.encode(vehicleProps),
['@plate'] = vehicleProps.plate,
['@stored'] = 2,
['@pound'] = pound
})
xPlayer.showNotification(_U('veh_impounded'))
end)
ESX.RegisterServerCallback('esx_garage:getVehiclesInParking', function(source, cb, parking)
local xPlayer = ESX.GetPlayerFromId(source)
MySQL.query('SELECT * FROM `owned_vehicles` WHERE `owner` = @identifier AND parking = @parking AND stored = 1',
MySQL.query('SELECT * FROM `owned_vehicles` WHERE `owner` = @identifier AND `parking` = @parking AND `stored` = 1',
{
['@identifier'] = xPlayer.identifier,
['@parking'] = parking
@@ -31,8 +49,8 @@ ESX.RegisterServerCallback('esx_garage:getVehiclesInParking', function(source, c
local vehicles = {}
for i = 1, #result, 1 do
table.insert(vehicles, {
vehicle = json.decode(result[i].vehicle),
plate = result[i].plate
vehicle = json.decode(result[i].vehicle),
plate = result[i].plate
})
end
@@ -43,10 +61,10 @@ end)
ESX.RegisterServerCallback('esx_garage:checkVehicleOwner', function(source, cb, plate)
local xPlayer = ESX.GetPlayerFromId(source)
MySQL.query('SELECT COUNT(*) as count FROM owned_vehicles WHERE owner = @identifier AND plate = @plate',
MySQL.query('SELECT COUNT(*) as count FROM `owned_vehicles` WHERE `owner` = @identifier AND `plate` = @plate',
{
['@identifier'] = xPlayer.identifier,
['@plate'] = plate
['@identifier'] = xPlayer.identifier,
['@plate'] = plate
}, function(result)
if tonumber(result[1].count) > 0 then
@@ -55,4 +73,65 @@ ESX.RegisterServerCallback('esx_garage:checkVehicleOwner', function(source, cb,
return cb(false)
end
end)
end)
-- Pounds part
ESX.RegisterServerCallback('esx_garage:getVehiclesImpounded', function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)
MySQL.query('SELECT * FROM `owned_vehicles` WHERE `owner` = @identifier AND `stored` = 0',
{
['@identifier'] = xPlayer.identifier,
}, function(result)
local vehicles = {}
for i = 1, #result, 1 do
table.insert(vehicles, {
vehicle = json.decode(result[i].vehicle),
plate = result[i].plate
})
end
cb(vehicles)
end)
end)
ESX.RegisterServerCallback('esx_garage:getVehiclesInPound', function(source, cb, pound)
local xPlayer = ESX.GetPlayerFromId(source)
MySQL.query('SELECT * FROM `owned_vehicles` WHERE `owner` = @identifier AND `pound` = @pound AND `stored` = 2',
{
['@identifier'] = xPlayer.identifier,
['@pound'] = pound
}, function(result)
local vehicles = {}
for i = 1, #result, 1 do
table.insert(vehicles, {
vehicle = json.decode(result[i].vehicle),
plate = result[i].plate
})
end
cb(vehicles)
end)
end)
ESX.RegisterServerCallback('esx_garage:checkMoney', function(source, cb, amount)
local xPlayer = ESX.GetPlayerFromId(source)
cb(xPlayer.getMoney() >= amount)
end)
RegisterServerEvent("esx_garage:payPound")
AddEventHandler("esx_garage:payPound", function(amount)
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer.getMoney() >= amount then
xPlayer.removeMoney(amount)
xPlayer.showNotification(_U('pay_pound_bill', amount))
else
xPlayer.showNotification(_U('missing_money'))
end
end)