-
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.
- Loading branch information
1 parent
1821fe6
commit 8742676
Showing
1 changed file
with
109 additions
and
0 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
server-data/resources/[bpt_addons]/bpt_boat/server/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,109 @@ | ||
function ParkBoats() | ||
MySQL.update("UPDATE owned_vehicles SET `stored` = true WHERE `stored` = false AND type = @type", { | ||
["@type"] = "boat", | ||
}, function(rowsChanged) | ||
if rowsChanged > 0 then | ||
print(("[^2INFO^7] Stored ^5%s^7 %s !"):format(rowsChanged, rowsChanged > 1 and "boats" or "boat")) | ||
end | ||
end) | ||
end | ||
|
||
MySQL.ready(function() | ||
ParkBoats() | ||
end) | ||
|
||
ESX.RegisterServerCallback("bpt_boat:buyBoat", function(source, cb, vehicleProps) | ||
local xPlayer = ESX.GetPlayerFromId(source) | ||
local price = getPriceFromModel(vehicleProps.model) | ||
|
||
-- vehicle model not found | ||
if price == 0 then | ||
print(("[^2INFO^7] Player ^5%s^7 Attempted To Exploit Shop"):format(xPlayer.source)) | ||
cb(false) | ||
else | ||
if xPlayer.getMoney() >= price then | ||
xPlayer.removeMoney(price, "Boat Purchase") | ||
|
||
MySQL.update("INSERT INTO owned_vehicles (owner, plate, vehicle, type, `stored`) VALUES (@owner, @plate, @vehicle, @type, @stored)", { | ||
["@owner"] = xPlayer.identifier, | ||
["@plate"] = vehicleProps.plate, | ||
["@vehicle"] = json.encode(vehicleProps), | ||
["@type"] = "boat", | ||
["@stored"] = true, | ||
}, function(rowsChanged) | ||
cb(true) | ||
end) | ||
else | ||
cb(false) | ||
end | ||
end | ||
end) | ||
|
||
RegisterServerEvent("bpt_boat:takeOutVehicle") | ||
AddEventHandler("bpt_boat:takeOutVehicle", function(plate) | ||
local xPlayer = ESX.GetPlayerFromId(source) | ||
|
||
MySQL.update("UPDATE owned_vehicles SET `stored` = @stored WHERE owner = @owner AND plate = @plate", { | ||
["@stored"] = false, | ||
["@owner"] = xPlayer.identifier, | ||
["@plate"] = plate, | ||
}, function(rowsChanged) | ||
if rowsChanged == 0 then | ||
print(("[^2INFO^7] Player ^5%s^7 Attempted To Exploit Garage"):format(xPlayer.source)) | ||
end | ||
end) | ||
end) | ||
|
||
ESX.RegisterServerCallback("bpt_boat:storeVehicle", function(source, cb, plate) | ||
local xPlayer = ESX.GetPlayerFromId(source) | ||
|
||
MySQL.update("UPDATE owned_vehicles SET `stored` = @stored WHERE owner = @owner AND plate = @plate", { | ||
["@stored"] = true, | ||
["@owner"] = xPlayer.identifier, | ||
["@plate"] = plate, | ||
}, function(rowsChanged) | ||
cb(rowsChanged) | ||
end) | ||
end) | ||
|
||
ESX.RegisterServerCallback("bpt_boat:getGarage", function(source, cb) | ||
local xPlayer = ESX.GetPlayerFromId(source) | ||
|
||
MySQL.query("SELECT vehicle FROM owned_vehicles WHERE owner = @owner AND type = @type AND `stored` = @stored", { | ||
["@owner"] = xPlayer.identifier, | ||
["@type"] = "boat", | ||
["@stored"] = true, | ||
}, function(result) | ||
local vehicles = {} | ||
|
||
for i = 1, #result, 1 do | ||
table.insert(vehicles, result[i].vehicle) | ||
end | ||
|
||
cb(vehicles) | ||
end) | ||
end) | ||
|
||
ESX.RegisterServerCallback("bpt_boat:buyBoatLicense", function(source, cb) | ||
local xPlayer = ESX.GetPlayerFromId(source) | ||
|
||
if xPlayer.getMoney() >= Config.LicensePrice then | ||
xPlayer.removeMoney(Config.LicensePrice, "Boat License Purchase") | ||
|
||
TriggerEvent("esx_license:addLicense", source, "boat", function() | ||
cb(true) | ||
end) | ||
else | ||
cb(false) | ||
end | ||
end) | ||
|
||
function getPriceFromModel(model) | ||
for k, v in ipairs(Config.Vehicles) do | ||
if joaat(v.model) == model then | ||
return v.price | ||
end | ||
end | ||
|
||
return 0 | ||
end |