-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathclient.lua
More file actions
163 lines (129 loc) · 5.91 KB
/
Copy pathclient.lua
File metadata and controls
163 lines (129 loc) · 5.91 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
local Config = require 'config'
local awaitAction = false
local menuOptions = {}
local function isBlacklisted(vehicle)
local model = GetEntityModel(vehicle)
-- can add more specific checks here, i just wanted to make sure i dont hit some big ass trailer logs.
return Config.BlacklistedModels[model]
end
local function performVehicleAction(vehicle, actionName, isPlayer)
local action = Config.VehicleActions[actionName]
if not action then return end
if isPlayer then -- incase the driver is an npc, we dont want anyone to hear the sound/see the fx
AnimpostfxPlay('SwitchSceneMichael', 1000, false)
PlaySoundFrontend(-1, 'Crash', 'DLC_HEIST_HACKING_SNAKE_SOUNDS', 1)
end
if actionName == 'explode' then
return NetworkExplodeVehicle(vehicle, true, false, 0)
end
if actionName == 'doors' then
for i = 0, 4 do SetVehicleDoorOpen(vehicle, i, false, false) end
return
end
if actionName == 'tires' then
for i = 0, 7 do
if not IsVehicleTyreBurst(vehicle, i, false) then
SetVehicleTyreBurst(vehicle, i, true, 1000.0)
end
end
return
end
local driver = GetPedInVehicleSeat(vehicle, -1)
local timer = GetGameTimer() + action.duration
TaskVehicleTempAction(driver, vehicle, action.taskNo, action.duration)
while GetGameTimer() < timer do
if actionName == 'engine' then
SetVehicleEngineOn(vehicle, false, true, true)
end
if isPlayer and action.disableControls then
for i = 1, #action.disableControls do
DisableControlAction(2, action.disableControls[i], true)
end
end
Wait(0)
end
end
local function drawVehicleSphere(vehicle)
local minDim, maxDim = GetModelDimensions(GetEntityModel(vehicle))
local coords = GetEntityCoords(vehicle)
local sizeX = maxDim.x - minDim.x
local sizeY = maxDim.y - minDim.y
local sizeZ = maxDim.z - minDim.z
local radius = math.max(sizeX, sizeY, sizeZ) * 0.6
local centerZ = coords.z + ((minDim.z + maxDim.z) * 0.5)
DrawMarker(28, coords.x, coords.y, centerZ, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, radius, radius, radius, Config.SphereColor[1], Config.SphereColor[2], Config.SphereColor[3], Config.SphereColor[4], false, false, 2, false, nil, nil, false)
end
local function rotationToDirection(rot)
local z = math.rad(rot.z)
local x = math.rad(rot.x)
local num = math.abs(math.cos(x))
return vec3(-math.sin(z) * num, math.cos(z) * num, math.sin(x))
end
local function rayCastGamePlayCamera(distance)
local camRot = GetGameplayCamRot(2)
local camCoord = GetGameplayCamCoord()
local direction = rotationToDirection(camRot)
local destination = vec3(camCoord.x + direction.x * distance, camCoord.y + direction.y * distance, camCoord.z + direction.z * distance)
local radius = 1.5
local ray = StartShapeTestCapsule(camCoord.x, camCoord.y, camCoord.z, destination.x, destination.y, destination.z, radius, 10, cache.ped, 7)
local _, hit, coords, _, entity = GetShapeTestResult(ray)
return hit == 1, coords, entity
end
local function scanForVehicles(action)
if awaitAction or not hasItem(Config.ItemName) or isPlyDead() then return end
awaitAction = true
local label = Config.VehicleActions[action].label
lib.showTextUI(('**%s** \n Press ENTER to perform sabotage/Press BACKSPACE to cancel.'):format(label), {
position = 'bottom-center', icon = 'circle-info', style = { backgroundColor = '#1e1e1e', }
})
CreateThread(function()
while awaitAction do
Wait(0)
local hit, coords, entity = rayCastGamePlayCamera(Config.MaxDistance)
if hit and DoesEntityExist(entity) and IsEntityAVehicle(entity) and GetIsVehicleEngineRunning(entity) and not isBlacklisted(entity) then
local dist = #(GetEntityCoords(cache.ped) - GetEntityCoords(entity))
local driver = GetPedInVehicleSeat(entity, -1)
if driver ~= 0 and dist <= Config.MaxDistance then
drawVehicleSphere(entity)
if IsControlJustPressed(0, 191) then
TriggerServerEvent('randol_vehhack:server:performAction', NetworkGetNetworkIdFromEntity(entity), action)
awaitAction = false
end
end
end
if IsControlJustPressed(0, 194) then -- BACKSPACE
awaitAction = false
end
if IsPedDeadOrDying(cache.ped, true) then
awaitAction = false
end
end
lib.hideTextUI()
end)
end
RegisterNetEvent('randol_vehhack:client:performAction', function(netId, action, isPlayer)
if GetInvokingResource() then return end
local vehicle = NetToVeh(netId)
performVehicleAction(vehicle, action, isPlayer)
end)
RegisterNetEvent('randol_vehhack:client:useItem', function()
if GetInvokingResource() or isPlyDead() then return end
lib.showContext('veh_control_menu')
end)
AddEventHandler('ox_inventory:itemCount', function(itemName, totalCount)
if itemName == Config.ItemName and totalCount == 0 and awaitAction then
awaitAction = false
end
end)
for actionName, data in pairs(Config.VehicleActions) do
menuOptions[#menuOptions + 1] = {
title = data.label,
description = ('**Player Fee: $%s | Local Fee: $%s** \n*%s*'):format(data.playerFee, data.npcFee, data.description),
icon = data.icon,
onSelect = function()
scanForVehicles(actionName)
end
}
end
table.sort(menuOptions, function(a, b) return a.title:lower() < b.title:lower() end) -- my OCD
lib.registerContext({ id = 'veh_control_menu', title = 'Vehicle Sabotage', options = menuOptions })