2026-04-14 17:41:39 +02:00

279 lines
8.1 KiB
Lua

function RemoveMoney(src, amount)
local Player = GetPlayer(src)
if Config.Framework == 'esx' or Config.Framework == 'oldesx' then
if Player.getMoney() >= amount then
Player.removeMoney(amount)
return true
else
return false
end
else
if Player.Functions.RemoveMoney('cash', amount) then
return true
else
return false
end
end
return false
end
function RemoveBankMoney(src, amount)
local Player = GetPlayer(src)
if Config.Framework == 'esx' or Config.Framework == 'oldesx' then
if Player.getAccount("bank").money >= amount then
Player.removeAccountMoney('bank', amount)
return true
else
return false
end
else
local bankBalance = Player.PlayerData.money["bank"]
if bankBalance >= amount then
Player.Functions.RemoveMoney('bank', amount)
return true
else
return false
end
end
return false
end
function AddBankMoney(src, amount)
local Player = GetPlayer(src)
if Config.Framework == 'esx' or Config.Framework == 'oldesx' then
Player.addAccountMoney('bank', amount)
else
Player.Functions.AddMoney('bank', amount)
end
end
function AddMoney(src, amount)
local Player = GetPlayer(src)
if Config.Framework == 'esx' or Config.Framework == 'oldesx' then
Player.addMoney(amount)
else
Player.Functions.AddMoney('cash', amount)
end
end
function GiveVehicle(identifier, name, helicopter, custom_plate, color, license)
local plate = GeneratePlate(custom_plate)
local vehicleProps = GetVehicleProperties(name, plate, helicopter, color)
if identifier then
if Config.Framework == 'esx' or Config.Framework == 'oldesx' then
ExecuteSql(string.format("INSERT INTO owned_vehicles (owner, plate, vehicle) VALUES ('%s', '%s', %q)", identifier, plate, json.encode(vehicleProps)))
else
local garage = Config.GarageQBCore or 'motelgarage'
ExecuteSql(string.format("INSERT INTO `player_vehicles` (license, citizenid, vehicle, hash, mods, plate, garage, state) VALUES ('%s', '%s', '%s', '%s', %q, '%s', '%s', %f)",
license, identifier, name, GetHashKey(name), json.encode(vehicleProps), plate, garage, 0))
end
end
return plate, vehicleProps
end
function Round(value, numDecimalPlaces)
if numDecimalPlaces then
local power = 10^numDecimalPlaces
return math.floor((value * power) + 0.5) / (power)
else
return math.floor(value + 0.5)
end
end
function GetVehicleProperties(name, plate, helicopter, color)
local extras = {}
for i=1, 12 do
extras[i] = false
end
if Config.Framework == 'esx' or Config.Framework == 'oldesx' then
local defaultProps = {
model = GetHashKey(name),
plate = plate,
plateIndex = 0,
bodyHealth = 1000,
engineHealth = 1000,
tankHealth = 1000,
fuelLevel = 100,
dirtLevel = 0,
color1 = color or 0,
color1Custom = {255, 255, 255},
color2 = color or 0,
color2Custom = {255, 255, 255},
color1Type = 0,
color2Type = 0,
customPrimaryColor = nil,
customSecondaryColor = nil,
pearlescentColor = 111,
wheelColor = 156,
wheels = 0,
windowTint = -1,
xenonColor = 255,
neonEnabled = {
false,
false,
false,
false
},
neonColor = {255,0,255},
extras = extras,
tyreSmokeColor = {255,255,255},
dashboardColor = 0,
interiorColor = 0,
modSpoilers = -1,
modFrontBumper = -1,
modRearBumper = -1,
modSideSkirt = -1,
modExhaust = -1,
modFrame = -1,
modGrille = -1,
modHood = -1,
modFender = -1,
modRightFender = -1,
modRoof = -1,
modEngine = -1,
modBrakes = -1,
modTransmission = -1,
modHorns = -1,
modSuspension = -1,
modArmor = -1,
modTurbo = false,
modSmokeEnabled = false,
modXenon = false,
modFrontWheels = -1,
modBackWheels = -1,
modPlateHolder = -1,
modVanityPlate = -1,
modTrimA = -1,
modOrnaments = -1,
modDashboard = -1,
modDial = -1,
modDoorSpeaker = -1,
modSeats = -1,
modSteeringWheel = -1,
modShifterLeavers = -1,
modAPlate = -1,
modSpeakers = -1,
modTrunk = -1,
modHydrolic = -1,
modEngineBlock = -1,
modAirFilter = -1,
modStruts = -1,
modArchCover = -1,
modAerials = -1,
modTrimB = -1,
modTank = -1,
modWindows = -1,
modDoorR = -1,
modLivery = -1,
modLightbar = -1,
livery = -1,
}
if helicopter then
defaultProps.liveryRoof = -1
defaultProps.extras = {
["1"] = true,
["2"] = true,
["7"] = true,
}
defaultProps.windowStatus = {
["1"] = true,
["2"] = true,
["3"] = true,
["4"] = true,
["5"] = true,
["6"] = true,
["7"] = false,
["0"] = true,
}
end
return defaultProps
else
local defaultProps = {
model = GetHashKey(name),
plate = plate,
color1 = color,
color2 = color,
}
if helicopter then
defaultProps.liveryRoof = -1
defaultProps.extras = {
["1"] = true,
["2"] = true,
["7"] = true,
}
defaultProps.windowStatus = {
["1"] = true,
["2"] = true,
["3"] = true,
["4"] = true,
["5"] = true,
["6"] = true,
["7"] = false,
["0"] = true,
}
end
return defaultProps
end
end
local StringCharset = {}
local NumberCharset = {}
for i = 48, 57 do NumberCharset[#NumberCharset+1] = string.char(i) end
for i = 65, 90 do StringCharset[#StringCharset+1] = string.char(i) end
for i = 97, 122 do StringCharset[#StringCharset+1] = string.char(i) end
function RandomStr(length)
if length <= 0 then return '' end
return RandomStr(length - 1) .. StringCharset[math.random(1, #StringCharset)]
end
function RandomInt(length)
if length <= 0 then return '' end
return RandomInt(length - 1) .. NumberCharset[math.random(1, #NumberCharset)]
end
function CheckPlateExists(plate)
local tableName = 'player_vehicles'
if Config.Framework == 'esx' or Config.Framework == 'oldesx' then
tableName = 'owned_vehicles'
end
plate = plate:upper()
local result = ExecuteSql(string.format("SELECT plate FROM %s WHERE plate = '%s'", tableName, plate))
if result[1] then
return true
else
return false
end
end
function GeneratePlate(custom_plate)
local tableName = 'player_vehicles'
local plate = custom_plate and custom_plate or (RandomInt(1) .. RandomStr(2) .. RandomInt(3) .. RandomStr(2))
if Config.Framework == 'esx' or Config.Framework == 'oldesx' then
tableName = 'owned_vehicles'
plate = custom_plate and custom_plate or (RandomStr(3) .. ' ' .. RandomInt(3))
end
plate = plate:upper()
local result = ExecuteSql(string.format("SELECT plate FROM %s WHERE plate = '%s'", tableName, plate))
if result[1] then
return GeneratePlate(false)
else
return plate:upper()
end
end