-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathserver.lua
More file actions
60 lines (45 loc) · 2.12 KB
/
Copy pathserver.lua
File metadata and controls
60 lines (45 loc) · 2.12 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
local Config = require 'config'
local timeoutVehs = {}
exports('useDevice', function(event, item, inventory, slot, data)
if event == 'usingItem' then
local src = inventory.id
TriggerClientEvent('randol_vehhack:client:useItem', src)
end
end)
local function handleFee(player, fee)
if fee == 0 then return true end
local balance = GetAccountBalance(player, 'bank') -- refer to bridge of your framework for custom currencies.
if balance >= fee then
RemoveMoney(player, 'bank', fee, 'Vehicle Maintenance')
return true
end
return false
end
RegisterNetEvent('randol_vehhack:server:performAction', function(netId, action)
local src = source
local player = GetPlayer(src)
if not player then return end
local entity = NetworkGetEntityFromNetworkId(netId)
if not DoesEntityExist(entity) then return end
if timeoutVehs[entity] then
return DoNotification(src, 'There is a cooldown between sabotages for this specific vehicle.', 'error')
end
if not hasItem(src, Config.ItemName) then return end
local pos = GetEntityCoords(GetPlayerPed(src))
local coords = GetEntityCoords(entity)
if #(pos - coords) > Config.MaxDistance then return end
local driver = GetPedInVehicleSeat(entity, -1)
if driver == 0 then return end
local owner = NetworkGetEntityOwner(entity)
if owner <= 0 then return end -- I dont think I need this as it would only return -1 when the server owns it because nobody is in scope to take ownership iirc but i'll put it here regardless.
local isPlayer = IsPedAPlayer(driver)
local success = handleFee(player, isPlayer and Config.VehicleActions[action].playerFee or Config.VehicleActions[action].npcFee)
if not success then
return DoNotification(src, 'You do not have the funds for this action.', 'error')
end
TriggerClientEvent('randol_vehhack:client:performAction', owner, netId, action, isPlayer)
timeoutVehs[entity] = true
SetTimeout(Config.TimeBetweenVehicleActions, function()
timeoutVehs[entity] = nil
end)
end)