Skip to content

Commit

Permalink
Merge pull request #721 from bitpredator/dev
Browse files Browse the repository at this point in the history
convert: esx_boat > bpt_boat
  • Loading branch information
bitpredator authored Jun 14, 2024
2 parents ec81f71 + 63a2655 commit 95d29b5
Show file tree
Hide file tree
Showing 29 changed files with 827 additions and 1,181 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.

Expand Down Expand Up @@ -631,8 +631,8 @@ to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

esx_boat
Copyright (C) 2015-2022 Jérémie N'gadi
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 2024 bitpredator

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -645,14 +645,14 @@ the "copyright" line and a pointer to where the full notice is found.
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
along with this program. If not, see <https://www.gnu.org/licenses/>.

Also add information on how to contact you by electronic and paper mail.

If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:

esx_boat Copyright (C) 2015-2022 Jérémie N'gadi
<program> Copyright (C) 2024 bitpredator
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
Expand All @@ -664,11 +664,11 @@ might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
<https://www.gnu.org/licenses/>.

The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
<https://www.gnu.org/licenses/why-not-lgpl.html>.
19 changes: 19 additions & 0 deletions server-data/resources/[bpt_addons]/bpt_boat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<h1 align='center'>bpt_boat</a></h1>
<p align='center'><a href='https://discord.gg/ksGfNvDEfq'>Discord</a>

Copyright (C) 2024 bitpredator

This program Is free software: you can redistribute it And/Or modify it under the terms Of the GNU General Public License As published by the Free Software Foundation, either version 3 Of the License, Or (at your option) any later version.

This program Is distributed In the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty Of MERCHANTABILITY Or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License For more details.

ATTENTION:
You are not authorized to change the name of the resource and the resources within it.

If you want to contribute you can open a pull request.

You are not authorized to sell this software (this is free project).

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
INSERT INTO `licenses` (`type`, `label`) VALUES
('boat', 'Boat License')
;
;
241 changes: 241 additions & 0 deletions server-data/resources/[bpt_addons]/bpt_boat/client/main.lua
Original file line number Diff line number Diff line change
@@ -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 _, 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 _ = GetVehiclePedIsIn(playerPed, false)
local props = ESX.Game.GetVehicleProperties(vehicle)
props.plate = plate

ESX.TriggerServerCallback("bpt_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()
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("bpt_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("bpt_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("bpt_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()
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("bpt_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
Loading

0 comments on commit 95d29b5

Please sign in to comment.