-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathserver.lua
More file actions
80 lines (74 loc) · 2.98 KB
/
server.lua
File metadata and controls
80 lines (74 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
local QBCore = GetResourceState('qb-core') == 'started' and exports['qb-core']:GetCoreObject()
local ESX = GetResourceState('es_extended') == 'started' and exports.es_extended:getSharedObject()
local function PlayerName(src)
if QBCore then
local Player = QBCore.Functions.GetPlayer(src)
return Player.PlayerData.charinfo.firstname..' '..Player.PlayerData.charinfo.lastname
elseif ESX then
local Player = ESX.GetPlayerFromId(src)
local first, last
if Player.get and Player.get('firstName') and Player.get('lastName') then
first = Player.get('firstName')
last = Player.get('lastName')
else
local name = MySQL.Sync.fetchAll('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier`=@identifier', { ['@identifier'] = ESX.GetIdentifier(source) })
first, last = name[1]?.firstname or ESX.GetPlayerName(source), name[1]?.lastname or ''
end
return first..' '..last
end
end
RegisterNetEvent('solos-rentals:server:RentVehicle', function(vehicle, plate)
local src = source
local player_name = PlayerName(src)
exports.ox_inventory:AddItem(src, 'rentalpapers', 1,
{description = 'Owner: '..player_name..' | Plate: '..plate..' | Vehicle: '..vehicle:gsub("^%l", string.upper)}
)
end)
RegisterNetEvent('solos-rentals:server:MoneyAmounts', function(vehiclename, price, location)
local src = source
local moneytype = 'bank'
local price = tonumber(price)
local bank
local cash
if QBCore then
local Player = QBCore.Functions.GetPlayer(src)
bank = Player.PlayerData.money.bank
cash = Player.PlayerData.money.cash
elseif ESX then
local Player = ESX.GetPlayerFromId(src)
bank = Player.getAccount('bank').money
cash = Player.getAccount('money').money
end
if bank < price then
moneytype = 'cash'
if cash < price then
TriggerClientEvent('ox_lib:notify', src, {
id = 'not_enough_money',
description = 'You don\'t have enough money to rent this vehicle.',
position = 'center-right',
icon = 'ban',
iconColor = '#C53030'
})
return
end
end
if QBCore then
local Player = QBCore.Functions.GetPlayer(src)
Player.Functions.RemoveMoney(moneytype, price)
elseif ESX then
local Player = ESX.GetPlayerFromId(src)
if moneytype == 'cash' then
Player.removeMoney(price)
elseif moneytype == 'bank' then
Player.removeAccountMoney('bank', price)
end
end
TriggerClientEvent('ox_lib:notify', src, {
id = 'rental_success',
description = vehiclename:gsub("^%l", string.upper)..' rented for $'..price..'.',
position = 'center-right',
icon = 'car',
iconColor = 'white'
})
TriggerClientEvent('solos-rentals:client:SpawnVehicle', src, vehiclename, location)
end)