-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #721 from bitpredator/dev
convert: esx_boat > bpt_boat
- Loading branch information
Showing
29 changed files
with
827 additions
and
1,181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/. |
2 changes: 1 addition & 1 deletion
2
...ources/[esx_addons]/esx_boat/esx_boat.sql → ...ources/[bpt_addons]/bpt_boat/bpt_boat.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
241
server-data/resources/[bpt_addons]/bpt_boat/client/main.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.