Repository navigation
Expand file tree
/
Copy pathclient.lua
More file actions
162 lines (151 loc) · 5.31 KB
/
Copy pathclient.lua
File metadata and controls
162 lines (151 loc) · 5.31 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
local isAccident = false -- 是否发生车祸
local oldBodyDamage = 0 -- veh生命值 上次记录数据
local oldSpeed = 0 -- veh速度 上次记录数据
-- 封装 黑屏函数
local function blackOut()
if not isAccident then
isAccident = true
-- 此线程将在指定时间内使得玩家屏幕黑屏
Citizen.CreateThread(function()
DoScreenFadeOut(100) -- 淡入
-- 在过渡时间内等待
while not IsScreenFadedOut() do
Citizen.Wait(0)
end
Citizen.Wait(Config.BlackoutTime) -- 配置的黑屏时间
DoScreenFadeIn(500) -- 淡出
isAccident = false
end)
end
end
-- 封装 窗口抖动函数
local function shakeCam()
if not isAccident then
isAccident = true
-- 此线程将在指定时间内使得玩家窗口抖动
Citizen.CreateThread(function()
ShakeGameplayCam(Config.ShakeGameplayCam, 1.0) -- 抖动
-- 抖动类型 (更新版本 b617d):
-- DEATH_FAIL_IN_EFFECT_SHAKE
-- DRUNK_SHAKE
-- FAMILY5_DRUG_TRIP_SHAKE
-- HAND_SHAKE
-- JOLT_SHAKE
-- LARGE_EXPLOSION_SHAKE
-- MEDIUM_EXPLOSION_SHAKE
-- SMALL_EXPLOSION_SHAKE (目前使用)
-- ROAD_VIBRATION_SHAKE
-- SKY_DIVING_SHAKE
-- VIBRATE_SHAKE
isAccident = false
end)
end
end
-- 封装 视觉模糊函数
local function BlurredVision()
if not isAccident then
isAccident = true
-- 此线程将在指定时间内使得玩家窗口视觉模糊
Citizen.CreateThread(function()
SetTimecycleModifier(Config.SetTimecycleModifier) -- 模糊效果
Citizen.Wait(Config.BlurredVisionTime) -- 配置的黑屏时间
ClearTimecycleModifier() -- 清除模糊效果
isAccident = false
end)
end
end
-- 封装 窗口抖动 and 视觉模糊 函数
local function shakeCamAndBlurredVision()
if not isAccident then
isAccident = true
-- 此线程将在指定时间内使得玩家窗口视觉模糊
Citizen.CreateThread(function()
ShakeGameplayCam(Config.ShakeGameplayCam, 1.0) -- 抖动
-- 抖动类型 (更新版本 b617d):
-- DEATH_FAIL_IN_EFFECT_SHAKE
-- DRUNK_SHAKE
-- FAMILY5_DRUG_TRIP_SHAKE
-- HAND_SHAKE
-- JOLT_SHAKE
-- LARGE_EXPLOSION_SHAKE
-- MEDIUM_EXPLOSION_SHAKE
-- SMALL_EXPLOSION_SHAKE (目前使用)
-- ROAD_VIBRATION_SHAKE
-- SKY_DIVING_SHAKE
-- VIBRATE_SHAKE
SetTimecycleModifier(Config.SetTimecycleModifier) -- 模糊效果
Citizen.Wait(Config.BlurredVisionTime) -- 配置的黑屏时间
ClearTimecycleModifier() -- 清除模糊效果
isAccident = false
end)
end
end
-- 主线程 函数
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
-- 获取玩家所乘坐的车辆,如果存在则继续
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
-- 检查实体是否存在
if DoesEntityExist(vehicle) then
local currentDamage = GetVehicleBodyHealth(vehicle)
-- 最大 1000,最小 0 (实际可能会出现负数)
-- 车辆在 0 时不一定会爆炸或无法驾驶。
-- 检查是否启用
if Config.SlightFromDamage then
-- 如果损坏情况发生变化,查看是否超出阈值
if currentDamage ~= oldBodyDamage then
if not isAccident and (currentDamage < oldBodyDamage) and ((oldBodyDamage - currentDamage) >= Config.SlightDamageRequired) and ((oldBodyDamage - currentDamage) < Config.NormalDamageRequired) then
shakeCam() -- 调用窗口抖动函数
end
end
end
-- 检查是否启用
if Config.NormalFromDamage then
-- 如果损坏情况发生变化,查看是否超出阈值
if currentDamage ~= oldBodyDamage then
if not isAccident and (currentDamage < oldBodyDamage) and ((oldBodyDamage - currentDamage) >= Config.NormalDamageRequired) and ((oldBodyDamage - currentDamage) < Config.SevereDamageRequired) then
shakeCamAndBlurredVision() -- 调用窗口抖动 and 视觉模糊
end
end
end
-- 检查是否启用
if Config.SevereFromDamage then
-- 如果损坏情况发生变化,查看是否超出阈值
if currentDamage ~= oldBodyDamage then
if not isAccident and (currentDamage < oldBodyDamage) and ((oldBodyDamage - currentDamage) >= Config.SevereDamageRequired) then
blackOut() -- 调用黑屏函数
end
end
end
oldBodyDamage = currentDamage -- 记录损伤
-- 是否启用速度检测
if Config.BlackoutFromSpeed then
local currentSpeed = GetEntitySpeed(vehicle) * 2.236936 -- 获取 车辆当前速度 速度单位:MPH
--local currentSpeed = GetVehicleDashboardSpeed(vehicle) * 2.236936 -- 获取 车辆当前速度 速度单位:MPH
-- 转换为 MPH: speed * 2.236936
-- 转换为 KPH: speed * 3.6
-- 速度检测
if currentSpeed ~= oldSpeed then
-- 当速度发生变化时,且属于减速并大于检测值时
if not isAccident and (currentSpeed < oldSpeed) and ((oldSpeed - currentSpeed) >= Config.BlackoutSpeedRequired) then
blackOut() -- 调用黑屏函数
end
oldSpeed = currentSpeed -- 记录速度
end
end
else
oldBodyDamage = 0
oldSpeed = 0
end
-- 禁用玩家的控制
if isAccident and Config.DisableControlsOnBlackout then
-- https://github.com/Sighmir/FiveM-Scripts/blob/master/vrp/vrp_hotkeys/client.lua
DisableControlAction(0,71,true)
DisableControlAction(0,72,true)
DisableControlAction(0,63,true)
DisableControlAction(0,64,true)
DisableControlAction(0,75,true)
end
end
end)