/
client.lua
210 lines (171 loc) · 6.07 KB
/
client.lua
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
-- Define what weapon GROUPS are allowed to hipfire
groups = {
[860033945] = true, -- SHOTGUN
[970310034] = true, -- ASSAULT RIFLE
[-957766203] = true, -- SUBMACHINE GUN
-- [1159398588] = true, -- LIGHT MACHINE GUN
[3082541095] = true, -- SNIPER
[-1212426201] = true, -- SNIPER TOO I THINK??
}
-- Define individual WEAPONS that are allowed to hipfire
weapons = {
-- Grenade Launcher is a 'heavy', so is the rpg, but we don't want to hipfire that
[`WEAPON_GRENADELAUNCHER`] = true,
-- Railgun is a 'heavy' but is fine to hipfire
[`WEAPON_RAILGUN`] = true,
[`WEAPON_RAILGUNXM3`] = true,
}
-- Define individual WEAPONS that aren't allowed to hipfire
-- This and 'weapons' above bypasses category.
weapons_disabled = {
-- These are the only SMGs that won't like this hipfire
[`WEAPON_MICROSMG`] = true,
[`WEAPON_TECPISTOL`] = true,
[`WEAPON_MINISMG`] = true,
[`WEAPON_GUSENBERG`] = true,
[`WEAPON_MACHINEPISTOL`] = true,
}
-- the code
function lerp(x1, x2, t)
return x1 + (x2 - x1) * t
end
last_sync = 0
sync_interval = 100 -- sync every nth ms
local recoil = vec(0.0, 0.0, 0.0)
CreateThread(function()
while true do Wait(0)
-- you don't need this, look away
debug_render = GlobalState.debug
for i,v in pairs(GetActivePlayers()) do
local ped = GetPlayerPed(v)
if ped ~= PlayerPedId() then
local pos = GetPedBoneCoords(ped, 57005, 0.0, 0.0, 0.0)
local h = GetEntityHeading(ped) - 161.3
local pitch_u = Entity(ped).state.hipfire_pitch_u or 0.0
local pitch_d = Entity(ped).state.hipfire_pitch_d or 0.0
if debug_render then
DrawMarker(
28,
pos,
0.0, 0.0, 0.0,
0.0, 0.0, 0.0,
vec(1.0, 1.0, 1.0) * 0.05,
64, 64, 255, 64,
false, false, 0, false
)
end
local off = vec(math.sin(math.rad(-h)), math.cos(math.rad(-h))) * 0.15 * (1.0 - pitch_u / 90.0)
pos += vec(off.x, off.y, 0.0) -- * (1.0 - pitch_d / 90.0)
pos += vec(0.0, 0.0, -0.25) * (1.0 - pitch_d / 90.0) / (1.0 - pitch_u / 180.0)
if debug_render then
DrawMarker(
28,
pos,
0.0, 0.0, 0.0,
0.0, 0.0, 0.0,
vec(1.0, 1.0, 1.0) * 0.05,
255, 0, 0, 64,
false, false, 0, false
)
end
local hipfiring = Entity(ped).state.hipfire
if hipfiring then
SetIkTarget(ped, 4, nil, nil, pos.x, pos.y, pos.z, 0.0, 200, 200)
if debug_render then
DrawMarker(
28,
pos,
0.0, 0.0, 0.0,
0.0, 0.0, 0.0,
vec(1.0, 1.0, 1.0) * 0.1,
0, 255, 0, 64,
false, false, 0, false
)
end
end
end
end
local pos = GetPedBoneCoords(PlayerPedId(), 57005, 0.0, 0.0, 0.0)
local pitch_u = math.max(0.0, GetGameplayCamRelativePitch())
local pitch_d = math.max(0.0, -GetGameplayCamRelativePitch())
local h = GetEntityHeading(PlayerPedId()) - 161.3
if debug_render then
DrawMarker(
28,
pos,
0.0, 0.0, 0.0,
0.0, 0.0, 0.0,
vec(1.0, 1.0, 1.0) * 0.05,
64, 64, 255, 64,
false, false, 0, false
)
end
local off = vec(math.sin(math.rad(-h)), math.cos(math.rad(-h))) * 0.15 * (1.0 - pitch_u / 90.0)
pos += vec(off.x, off.y, 0.0) -- * (1.0 - pitch_d / 90.0)
pos += vec(0.0, 0.0, -0.25) * (1.0 - pitch_d / 90.0) / (1.0 - pitch_u / 180.0)
if debug_render then
DrawMarker(
28,
pos,
0.0, 0.0, 0.0,
0.0, 0.0, 0.0,
vec(1.0, 1.0, 1.0) * 0.05,
255, 0, 0, 64,
false, false, 0, false
)
end
local hipfiring = not IsPedRunningMeleeTask(PlayerPedId()) and not IsPedGoingIntoCover(PlayerPedId()) and not IsPedInCover(PlayerPedId()) and not IsPedReloading(PlayerPedId()) and IsAimCamActive() and not IsControlPressed(0, 25) and not IsControlPressed(0, 37)
local _, wep = GetCurrentPedWeapon(PlayerPedId())
local group = GetWeapontypeGroup(wep)
hipfiring = hipfiring and (weapons[wep] or groups[group])
hipfiring = hipfiring and not weapons_disabled[wep]
if hipfiring then
SetIkTarget(PlayerPedId(), 4, nil, nil, pos.x, pos.y, pos.z, 0.0, 200, 200)
-- hide crosshair!
HideHudComponentThisFrame(14)
if debug_render then
DrawMarker(
28,
pos,
0.0, 0.0, 0.0,
0.0, 0.0, 0.0,
vec(1.0, 1.0, 1.0) * 0.1,
0, 255, 0, 64,
false, false, 0, false
)
end
else
if IsAimCamActive() then
DisableControlAction(0, 21, true)
end
/*
-- local pos = GetPedBoneCoords(PlayerPedId(), 57005, 0.0, 0.0, 0.0)
local x = math.sin(math.rad(-GetEntityHeading(PlayerPedId())))
local y = math.cos(math.rad(-GetEntityHeading(PlayerPedId())))
local pos = GetPedBoneCoords(PlayerPedId(), 18905, 0.0, 0.0, 0.0) + vec(x, y, 0.2)
local rayEnd = pos + vec(0.0, 0.0, -0.25)
local ray = StartExpensiveSynchronousShapeTestLosProbe(pos.x, pos.y, pos.z, rayEnd.x, rayEnd.y, rayEnd.z, 1 | 2 | 16, -1, 0)
local ret1, hit, _end, ret2, hitEnt = GetShapeTestResult(ray)
-- DrawLine(pos.x, pos.y, pos.z, rayEnd.x, rayEnd.y, rayEnd.z, 255, 255, 255, 255)
if hit ~= 0 and IsAimCamActive() then
local rpos = GetPedBoneCoords(PlayerPedId(), 57005, 0.0, 0.0, 0.0)
SetIkTarget(PlayerPedId(), 4, nil, nil, rpos.x, rpos.y, _end.z + 0.1, 0.0, 200, 200)
end
*/
-- if IsPedShooting(PlayerPedId()) then
-- -- recoil += vec(0.0, 0.0, 0.25)
-- local x = math.sin(math.rad(-GetEntityHeading(PlayerPedId()) + 180.0))
-- local y = math.cos(math.rad(-GetEntityHeading(PlayerPedId()) + 180.0))
-- recoil += vec(x, y, 0.0) * 0.25
-- end
-- recoil = lerp(recoil, vec(0.0, 0.0, 0.0), GetFrameTime() * 10.0)
-- SetIkTarget(PlayerPedId(), 4, nil, nil, pos.x + recoil.x, pos.y + recoil.y, pos.z + recoil.z, 0.0, 200, 200)
end
if GetGameTimer() > last_sync + sync_interval then
Entity(PlayerPedId()).state:set('hipfire', hipfiring, true)
Entity(PlayerPedId()).state:set('hipfire_pitch_u', pitch_u, true)
Entity(PlayerPedId()).state:set('hipfire_pitch_d', pitch_d, true)
last_sync = GetGameTimer()
end
end
end)