This commit is contained in:
2026-07-07 21:08:52 +02:00
commit 4c20cfc716
2613 changed files with 318021 additions and 0 deletions

View File

@@ -0,0 +1,241 @@
isInShopMenu = false
local spawnedVehicles = {}
function OpenBoatShop(shop)
isInShopMenu = true
local playerPed = PlayerPedId()
local elements = {
{unselectable = true, icon = "fas fa-ship", title = TranslateCap('boat_shop')}
}
for k,v in ipairs(Config.Vehicles) do
elements[#elements+1] = {
icon = "fas fa-ship",
title = ('%s - <span style="color:green;">$%s</span>'):format(v.label, ESX.Math.GroupDigits(v.price)),
name = v.label,
model = v.model,
price = v.price,
props = v.props or nil
}
end
ESX.OpenContext("right", elements, function(menu,element)
local elements2 = {
{unselectable = true, icon = "fas fa-ship", title = element.title},
{icon = "fas fa-eye", title = "View", val = "view"}
}
ESX.OpenContext("right", elements2, function(menu2,element2)
if element2.val == "view" then
DeleteSpawnedVehicles()
ESX.Game.SpawnLocalVehicle(element.model, shop.Inside, shop.Inside.w, function (vehicle)
table.insert(spawnedVehicles, vehicle)
TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
FreezeEntityPosition(vehicle, true)
if element.props then
ESX.Game.SetVehicleProperties(vehicle, element.props)
end
local elements3 = {
{unselectable = true, icon = "fas fa-ship", title = element.title},
{icon = "fas fa-check-double", title = "Buy", value = "buy"},
{icon = "fas fa-eye", title = "Stop Viewing", value = "stop"}
}
ESX.OpenContext("right", elements3, function(menu3,element3)
if element3.value == "buy" then
local plate = exports['esx_vehicleshop']:GeneratePlate()
local vehicle = GetVehiclePedIsIn(playerPed, false)
local props = ESX.Game.GetVehicleProperties(vehicle)
props.plate = plate
ESX.TriggerServerCallback('esx_boat:buyBoat', function(bought)
if bought then
ESX.ShowNotification(TranslateCap('boat_shop_bought', element.name, ESX.Math.GroupDigits(element.price)))
DeleteSpawnedVehicles()
isInShopMenu = false
ESX.CloseContext()
CurrentAction = 'boat_shop'
CurrentActionMsg = TranslateCap('boat_shop_open')
FreezeEntityPosition(playerPed, false)
SetEntityVisible(playerPed, true)
SetEntityCoords(playerPed, shop.Outside.x, shop.Outside.y, shop.Outside.z)
else
ESX.ShowNotification(TranslateCap('boat_shop_nomoney'))
end
end, props)
elseif element3.value == "stop" then
reset(shop)
end
end, function ()
reset(shop)
end)
end)
end
end, function(menu)
isInShopMenu = false
CurrentAction = 'boat_shop'
CurrentActionMsg = TranslateCap('boat_shop_open')
end)
end, function(menu)
isInShopMenu = false
CurrentAction = 'boat_shop'
CurrentActionMsg = TranslateCap('boat_shop_open')
end)
end
function OpenBoatGarage(garage)
ESX.TriggerServerCallback('esx_boat:getGarage', function (ownedBoats)
if #ownedBoats == 0 then
ESX.ShowNotification(TranslateCap('garage_noboats'))
else
-- get all available boats
local elements = {
{unselectable = true, icon = "fas fa-ship", title = TranslateCap('garage')}
}
for i=1, #ownedBoats, 1 do
ownedBoats[i] = json.decode(ownedBoats[i])
elements[#elements+1] = {
icon = "fas fa-ship",
title = getVehicleLabelFromHash(ownedBoats[i].model),
vehicleProps = ownedBoats[i]
}
end
ESX.OpenContext("right", elements, function(menu,element)
local playerPed = PlayerPedId()
local vehicleProps = element.vehicleProps
if ESX.Game.IsSpawnPointClear(garage.SpawnPoint, 4.0) then
TriggerServerEvent('esx_boat:takeOutVehicle', vehicleProps.plate)
ESX.ShowNotification(TranslateCap('garage_taken'))
ESX.Game.SpawnVehicle(vehicleProps.model, garage.SpawnPoint, garage.SpawnPoint.w, function(vehicle)
TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
ESX.Game.SetVehicleProperties(vehicle, vehicleProps)
end)
ESX.CloseContext()
else
ESX.ShowNotification(TranslateCap('garage_blocked'))
end
end, function(menu)
CurrentAction = 'garage_out'
CurrentActionMsg = TranslateCap('garage_open')
end)
end
end)
end
function OpenLicenceMenu(shop)
local elements = {
{unselectable = true, icon = "fas fa-ship", title = TranslateCap('license_menu')},
{icon = "fas fa-ship", title = "Purchase Boat License"}
}
ESX.OpenContext("right", elements, function(menu,element)
local elements2 = {
{unselectable = true, icon = "fas fa-ship", title = element.title},
{icon = "fas fa-check-double", title = TranslateCap('license_buy_yes', Config.LicensePrice), val = "yes"},
{icon = "fas fa-window-close", title = TranslateCap('license_buy_no'), val = "no"}
}
ESX.OpenContext("right", elements2, function(menu2,element2)
-- If the value is no, close the menu and stop the script.
if element2.val == "no" then
ESX.CloseContext()
return;
end
ESX.TriggerServerCallback('esx_boat:buyBoatLicense', function (boughtLicense)
if boughtLicense then
ESX.ShowNotification(TranslateCap('license_bought', ESX.Math.GroupDigits(Config.LicensePrice)))
ESX.CloseContext()
OpenBoatShop(shop) -- parse current shop
else
ESX.ShowNotification(TranslateCap('license_nomoney'))
end
end)
end, function(menu)
CurrentAction = 'boat_shop'
CurrentActionMsg = TranslateCap('boat_shop_open')
end)
end, function(menu)
CurrentAction = 'boat_shop'
CurrentActionMsg = TranslateCap('boat_shop_open')
end)
end
function StoreBoatInGarage(vehicle, teleportCoords)
local vehicleProps = ESX.Game.GetVehicleProperties(vehicle)
ESX.TriggerServerCallback('esx_boat:storeVehicle', function (rowsChanged)
if rowsChanged > 0 then
ESX.Game.DeleteVehicle(vehicle)
ESX.ShowNotification(TranslateCap('garage_stored'))
local playerPed = PlayerPedId()
ESX.Game.Teleport(playerPed, teleportCoords, function()
SetEntityHeading(playerPed, teleportCoords.w)
end)
else
ESX.ShowNotification(TranslateCap('garage_notowner'))
end
end, vehicleProps.plate)
end
-- Key controls
CreateThread(function()
while true do
Wait(0)
if isInShopMenu then
DisableControlAction(0, 75, true) -- Disable exit vehicle
DisableControlAction(27, 75, true) -- Disable exit vehicle
else
Wait(500)
end
end
end)
function DeleteSpawnedVehicles()
while #spawnedVehicles > 0 do
local vehicle = spawnedVehicles[1]
if DoesEntityExist(vehicle) then
ESX.Game.DeleteVehicle(vehicle)
end
table.remove(spawnedVehicles, 1)
end
end
function getVehicleLabelFromHash(modelHash)
local model = string.lower(GetDisplayNameFromVehicleModel(modelHash))
for i=1, #Config.Vehicles, 1 do
if joaat(Config.Vehicles[i].model) == modelHash then
return Config.Vehicles[i].label
end
end
return 'Unknown model [' .. model .. ']'
end
function reset(shop)
local playerPed = PlayerPedId()
isInShopMenu = false
CurrentAction = 'boat_shop'
CurrentActionMsg = TranslateCap('boat_shop_open')
DeleteSpawnedVehicles()
FreezeEntityPosition(playerPed, false)
SetEntityVisible(playerPed, true)
SetEntityCoords(playerPed, shop.Outside.x, shop.Outside.y, shop.Outside.z)
ESX.CloseContext()
end

View File

@@ -0,0 +1,199 @@
local HasAlreadyEnteredMarker = false
local LastZone = nil
CurrentAction = nil
CurrentActionMsg = ''
CurrentActionData = {}
-- Key controls
CreateThread(function()
while true do
Wait(0)
if CurrentAction then
if IsControlJustReleased(0, 38) then
if CurrentAction == 'boat_shop' then
if not Config.LicenseEnable then
OpenBoatShop(Config.Zones.BoatShops[CurrentActionData.zoneNum])
else -- check for license
ESX.TriggerServerCallback('esx_license:checkLicense', function(hasBoatLicense)
if hasBoatLicense then
OpenBoatShop(Config.Zones.BoatShops[CurrentActionData.zoneNum])
else
OpenLicenceMenu(Config.Zones.BoatShops[CurrentActionData.zoneNum])
end
end, GetPlayerServerId(PlayerId()), 'boat')
end
elseif CurrentAction == 'garage_out' then
OpenBoatGarage(Config.Zones.Garages[CurrentActionData.zoneNum])
elseif CurrentAction == 'garage_in' then
StoreBoatInGarage(CurrentActionData.vehicle, Config.Zones.Garages[CurrentActionData.zoneNum].StoreTP)
end
CurrentAction = nil
ESX.HideUI()
end
else
Wait(500)
end
end
end)
AddEventHandler('esx_boat:hasEnteredMarker', function(zone, zoneNum)
if zone == 'boat_shop' then
CurrentAction = 'boat_shop'
CurrentActionMsg = TranslateCap('boat_shop_open')
CurrentActionData = { zoneNum = zoneNum }
elseif zone == 'garage_out' then
CurrentAction = 'garage_out'
CurrentActionMsg = TranslateCap('garage_open')
CurrentActionData = { zoneNum = zoneNum }
elseif zone == 'garage_in' then
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
if IsPedInAnyVehicle(playerPed, false) then
local vehicle = GetVehiclePedIsIn(playerPed, false)
if DoesEntityExist(vehicle) and GetPedInVehicleSeat(vehicle, -1) == playerPed then
CurrentAction = 'garage_in'
CurrentActionMsg = TranslateCap('garage_store')
CurrentActionData = { vehicle = vehicle, zoneNum = zoneNum }
end
end
end
ESX.TextUI(CurrentActionMsg)
end)
AddEventHandler('esx_boat:hasExitedMarker', function()
if not isInShopMenu then
ESX.CloseContext()
end
CurrentAction = nil
ESX.HideUI()
end)
-- Enter / Exit marker events
CreateThread(function()
while true do
Wait(0)
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 = #(coords - Config.Zones.BoatShops[i].Outside)
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 = #(coords - Config.Zones.Garages[i].GaragePos)
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
distance = #(coords - Config.Zones.Garages[i].StorePos)
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
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)
then
TriggerEvent('esx_boat:hasExitedMarker', LastZone)
hasExited = true
end
HasAlreadyEnteredMarker = true
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
Wait(500)
end
end
end)
-- Blips
CreateThread(function()
local blipList = {}
for i=1, #Config.Zones.Garages, 1 do
table.insert(blipList, {
coords = Config.Zones.Garages[i].GaragePos,
text = TranslateCap('blip_garage'),
sprite = 356,
color = 3,
scale = 1.0
})
end
for i=1, #Config.Zones.BoatShops, 1 do
table.insert(blipList, {
coords = Config.Zones.BoatShops[i].Outside,
text = TranslateCap('blip_shop'),
sprite = 427,
color = 3,
scale = 1.0
})
end
for i=1, #blipList, 1 do
CreateBlip(blipList[i].coords, blipList[i].text, blipList[i].sprite, blipList[i].color, blipList[i].scale)
end
end)
function CreateBlip(coords, text, sprite, color, scale)
local blip = AddBlipForCoord(coords.x, coords.y)
SetBlipSprite(blip, sprite)
SetBlipScale(blip, scale)
SetBlipColour(blip, color)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName('STRING')
AddTextComponentSubstringPlayerName(text)
EndTextCommandSetBlipName(blip)
end