-
Notifications
You must be signed in to change notification settings - Fork 15
/
client.lua
193 lines (169 loc) · 6.2 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
---@class HeadBlendData
---@field shapeFirst integer
---@field shapeSecond integer
---@field shapeThird integer
---@field skinFirst integer
---@field skinSecond integer
---@field skinThird integer
---@field shapeMix number
---@field skinMix number
---@field thirdMix number
local freemodeModels<const> = {
[`mp_m_freemode_01`] = 'mp_m_freemode_01',
[`mp_f_freemode_01`] = 'mp_f_freemode_01'
}
---Is the model either of the freemode models?
---@param modelHash integer
local function isFreemodeModel(modelHash)
return freemodeModels[modelHash] ~= nil
end
---Gets head blend data
---@param ped integer
---@return HeadBlendData
local function getHeadBlendData(ped)
-- GTA returns some dumb struct with pointers
-- This is a goofy way to get the data in Lua.
-- Alternatively, you would need a C# or JS
-- script to get the data. However, this is
-- a lot less work.
-- People discussed this here:
-- https://forum.cfx.re/t/head-blend-data/212575/24
local tbl<const> = {
Citizen.InvokeNative(0x2746BD9D88C5C5D0, ped,
Citizen.PointerValueIntInitialized(0),
Citizen.PointerValueIntInitialized(0),
Citizen.PointerValueIntInitialized(0),
Citizen.PointerValueIntInitialized(0),
Citizen.PointerValueIntInitialized(0),
Citizen.PointerValueIntInitialized(0),
Citizen.PointerValueFloatInitialized(0),
Citizen.PointerValueFloatInitialized(0),
Citizen.PointerValueFloatInitialized(0)
)
}
return {
shapeFirst = tbl[1],
shapeSecond = tbl[2],
shapeThird = tbl[3],
skinFirst = tbl[4],
skinSecond = tbl[5],
skinThird = tbl[6],
shapeMix = tbl[7],
skinMix = tbl[8],
thirdMix = tbl[9]
}
end
local savedBlendData, savedFaceFeatures
---Restores saved blend data
---@param ped integer
local function restoreSavedBlendData(ped)
SetPedHeadBlendData(ped,
savedBlendData.shapeFirst, savedBlendData.shapeSecond, savedBlendData.shapeThird,
savedBlendData.skinFirst, savedBlendData.skinSecond, savedBlendData.skinThird,
savedBlendData.shapeMix, savedBlendData.skinMix, savedBlendData.thirdMix,
false
)
end
---Shrinks face features
---@param ped integer
local function restoreSavedFaceFeatures(ped)
for i = 0, 19 do
SetPedFaceFeature(ped, i, savedFaceFeatures[i])
end
end
---Shrinks face features
---@param ped integer
local function shrinkFaceFeatures(ped)
repeat Wait(0) until HasPedHeadBlendFinished(ped)
for i = 0, 19 do
if not savedFaceFeatures[i] then savedFaceFeatures[i] = GetPedFaceFeature(ped, i) end
SetPedFaceFeature(ped, i, 0.0)
end
end
---Shrink ped head
---@param ped integer
---@param pedModelHash integer
local function shrinkHead(ped, pedModelHash)
SetPedHeadBlendData(ped,
freemodeModels[pedModelHash] == 'mp_m_freemode_01' and 0 or 21, 0, 0, -- Reset shape
savedBlendData.skinFirst, savedBlendData.skinSecond, savedBlendData.skinThird, -- Keep skin
0.0, savedBlendData.skinMix, 0.0, -- Reset all but skin mix
false -- isParent (Unk effect)
)
end
-- local lastMaskDrawable, lastMaskTexture = -1, -1
---Handles mask fix
---@param ped integer
---@param pedModelHash integer
local function fixMask(ped, pedModelHash)
local currentMaskDrawable<const> = GetPedDrawableVariation(ped, 1)
local currentMaskTexture<const> = GetPedTextureVariation(ped, 1)
-- if currentMaskDrawable == lastMaskDrawable and currentMaskTexture == lastMaskTexture then return end
-- lastMaskDrawable = currentMaskDrawable
-- lastMaskTexture = currentMaskTexture
local maskHash<const> = GetHashNameForComponent(ped, 1, currentMaskDrawable, currentMaskTexture)
if currentMaskDrawable > 0 then
if maskHash == 0 then return end
local headBlendData<const> = getHeadBlendData(ped)
if
DoesShopPedApparelHaveRestrictionTag(maskHash, `SHRINK_HEAD`, 0) or
-- HARD CODED MASKS
currentMaskDrawable == 108 -- This god damn skull mask has no restriction tag but needs to shrink the head
or currentMaskDrawable == 30 -- Same goes for this hockey mask. It has no tags, but your nose clips through it
then
if not savedBlendData then savedBlendData = headBlendData end
shrinkHead(ped, pedModelHash)
elseif savedBlendData then
restoreSavedBlendData(ped)
savedBlendData = nil
end
if
not DoesShopPedApparelHaveRestrictionTag(maskHash, `HAT`, 0)
and not DoesShopPedApparelHaveRestrictionTag(maskHash, `EAR_PIECE`, 0)
-- HARD CODED MASKS
and not (
currentMaskDrawable == 11 -- Gay super hero
-- or currentMaskDrawable == 73 -- No mask (this will remain as is - it might be useful to put under specific helmets)
or currentMaskDrawable == 114 -- Open face headscarf
-- or currentMaskDrawable == 120 -- No mask bald (this will remain as is - it might be useful to put under specific helmets)
or currentMaskDrawable == 145 -- Cluckin Bell chicken
or currentMaskDrawable == 148 -- Super hero
)
then
if not savedFaceFeatures then savedFaceFeatures = {} end
shrinkFaceFeatures(ped)
elseif savedFaceFeatures then
restoreSavedFaceFeatures(ped)
savedFaceFeatures = nil
end
else
if savedBlendData then
restoreSavedBlendData(ped)
savedBlendData = nil
end
if savedFaceFeatures then
restoreSavedFaceFeatures(ped)
savedFaceFeatures = nil
end
end
end
local function fixClothing()
local ped<const> = PlayerPedId()
if not DoesEntityExist(ped) then return end
local pedModelHash<const> = GetEntityModel(ped)
if not isFreemodeModel(pedModelHash) then return end
fixMask(ped, pedModelHash)
end
-- Usually with FiveM, players can change their clothing
-- freely and on the fly. Ideally, you would want to fix
-- clothing right after the player changes their clothes.
-- However, as there is 1000 different ways of changing
-- clothes, I have decided to fix clothing on a loop.
-- I suggest you replace this with an event handler for
-- yourclothing system.
CreateThread(function()
while true do
fixClothing()
Wait(10)
end
end)