forked from Randolio/randol_vehhack
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient.lua
More file actions
189 lines (149 loc) · 6.5 KB
/
Copy pathclient.lua
File metadata and controls
189 lines (149 loc) · 6.5 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
local Config = require 'config'
local awaitAction = false
local function isBlacklisted(vehicle)
local model = GetEntityModel(vehicle)
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 outlinedVehicle = nil
local function setVehicleOutline(vehicle, enabled)
if not vehicle or not DoesEntityExist(vehicle) then return end
SetEntityDrawOutline(vehicle, enabled)
if enabled then
local c = Config.OutlineColor
SetEntityDrawOutlineColor(c[1], c[2], c[3], c[4])
SetEntityDrawOutlineShader(1) -- pulse highlight
end
end
local function clearOutline()
if outlinedVehicle and DoesEntityExist(outlinedVehicle) then
SetEntityDrawOutline(outlinedVehicle, false)
end
outlinedVehicle = nil
end
local function outlineVehicle(vehicle)
if outlinedVehicle == vehicle then return end
clearOutline()
setVehicleOutline(vehicle, true)
outlinedVehicle = vehicle
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
-- thin line test against map + props (flags 1 | 32) so walls block aim
local function hasLineOfSight(vehicle)
if not vehicle or vehicle == 0 or not DoesEntityExist(vehicle) then return false end
local from = GetGameplayCamCoord()
local to = GetEntityCoords(vehicle)
local ray = StartExpensiveSynchronousShapeTestLosProbe(from.x, from.y, from.z, to.x, to.y, to.z, 1 | 32, cache.ped, 0)
local _, hit = GetShapeTestResult(ray)
return hit == 0
end
function ScanForVehicles(action)
if awaitAction or isPlyDead() then return end
if not Config.VehicleActions[action] 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)
local validTarget = false
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)
local driverIsPlayer = driver ~= 0 and IsPedAPlayer(driver)
local allowed = driver ~= 0 and (driverIsPlayer or Config.AllowNpcTargets)
if allowed and dist <= Config.MaxDistance and hasLineOfSight(entity) then
validTarget = true
outlineVehicle(entity)
if IsControlJustPressed(0, 191) then
TriggerServerEvent('randol_vehhack:server:performAction', NetworkGetNetworkIdFromEntity(entity), action)
awaitAction = false
end
end
end
if not validTarget then
clearOutline()
end
if IsControlJustPressed(0, 194) then -- BACKSPACE
awaitAction = false
end
if IsPedDeadOrDying(cache.ped, true) then
awaitAction = false
end
end
clearOutline()
lib.hideTextUI()
end)
end
function IsScanningForVehicle()
return awaitAction
end
RegisterNetEvent('randol_vehhack:client:performAction', function(netId, action, isPlayer)
if GetInvokingResource() then return end
local vehicle = NetToVeh(netId)
performVehicleAction(vehicle, action, isPlayer)
end)
-- server picks a non-attacker client to raycast between two points for wallhack checks
lib.callback.register('randol_vehhack:client:hasLineOfSight', function(data)
if type(data) ~= 'table' then return false end
local from, to = data.from, data.to
if type(from) ~= 'table' or type(to) ~= 'table' then return false end
if type(from.x) ~= 'number' or type(to.x) ~= 'number' then return false end
local ray = StartExpensiveSynchronousShapeTestLosProbe(from.x, from.y, from.z, to.x, to.y, to.z, 1 | 32, 0, 0)
local _, hit = GetShapeTestResult(ray)
return hit == 0
end)