-
Notifications
You must be signed in to change notification settings - Fork 61
/
legs.lua
317 lines (265 loc) · 10.1 KB
/
legs.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
PLUGIN.name = "Legs"
PLUGIN.author = "Valkyrie & blackops7799"
PLUGIN.description = "Renders the characters legs to the local player."
PLUGIN.license = [[
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.
In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
]]
ix.lang.AddTable("english", {
legs = "Legs",
optLegsEnabled = "Enable legs",
optLegsInVehicle = "Enable legs in vehicles"
})
if (CLIENT) then
ix.option.Add("legsEnabled", ix.type.bool, true, {
category = "legs"
})
ix.option.Add("legsInVehicle", ix.type.bool, true, {
category = "legs"
})
local Legs = {}
Legs.LegEnt = nil
function Legs:CheckDrawVehicle()
if (LocalPlayer():InVehicle()) then
if (ix.option.Get("legsEnabled", true) and !ix.option.Get("legsInVehicle", true)) then
return true
end
return false
end
end
local function ShouldDrawLegs()
if (hook.Run("ShouldDisableLegs") == true) then
return false
end
if (ix.option.Get("legsEnabled", true)) then
local client = LocalPlayer()
return IsValid(Legs.LegEnt) and
(client:Alive() or (client.IsGhosted and client:IsGhosted())) and
!Legs:CheckDrawVehicle() and GetViewEntity() == client and
!client:ShouldDrawLocalPlayer() and !IsValid(client:GetObserverTarget()) and
!client:GetNoDraw() and !client.ShouldDisableLegs
end
end
function Legs:Setup(model)
model = model or LocalPlayer():GetModel()
if (!IsValid(self.LegEnt)) then
self.LegEnt = ClientsideModel(model, RENDER_GROUP_OPAQUE_ENTITY)
else
self.LegEnt:SetModel(model)
end
self.LegEnt:SetNoDraw(true)
for _, v in pairs(LocalPlayer():GetBodyGroups()) do
local current = LocalPlayer():GetBodygroup(v.id)
self.LegEnt:SetBodygroup(v.id, current)
end
for k, _ in ipairs(LocalPlayer():GetMaterials()) do
self.LegEnt:SetSubMaterial(k - 1, LocalPlayer():GetSubMaterial(k - 1))
end
self.LegEnt:SetSkin(LocalPlayer():GetSkin())
self.LegEnt:SetMaterial(LocalPlayer():GetMaterial())
self.LegEnt:SetColor(LocalPlayer():GetColor())
self.LegEnt.GetPlayerColor = function()
return LocalPlayer():GetPlayerColor()
end
self.LegEnt.Anim = nil
self.PlaybackRate = 1
self.Sequence = nil
self.Velocity = 0
self.BonesToRemove = {}
self.LegEnt.LastTick = 0
self:Update(0)
end
Legs.PlaybackRate = 1
Legs.Sequence = nil
Legs.Velocity = 0
Legs.BonesToRemove = {}
Legs.BreathScale = 0.5
Legs.NextBreath = 0
function Legs:Think(maxSeqGroundSpeed)
if (!LocalPlayer():Alive()) then
Legs:Setup()
return
end
self:Update(maxSeqGroundSpeed)
end
function Legs:Update(maxSeqGroundSpeed)
if (IsValid(self.LegEnt)) then
self.Velocity = LocalPlayer():GetVelocity():Length2D()
self.PlaybackRate = 1
if (self.Velocity > 0.5) then
if (maxSeqGroundSpeed < 0.001) then
self.PlaybackRate = 0.01
else
self.PlaybackRate = self.Velocity / maxSeqGroundSpeed
self.PlaybackRate = math.Clamp(self.PlaybackRate, 0.01, 10)
end
end
self.LegEnt:SetPlaybackRate(self.PlaybackRate)
self.Sequence = LocalPlayer():GetSequence()
if (self.LegEnt.Anim != self.Sequence) then
self.LegEnt.Anim = self.Sequence
self.LegEnt:ResetSequence(self.Sequence)
end
self.LegEnt:FrameAdvance(CurTime() - self.LegEnt.LastTick)
self.LegEnt.LastTick = CurTime()
Legs.BreathScale = sharpeye and sharpeye.GetStamina and math.Clamp(math.floor(sharpeye.GetStamina() * 5 * 10) / 10, 0.5, 5) or 0.5
if (Legs.NextBreath <= CurTime()) then
Legs.NextBreath = CurTime() + 1.95 / Legs.BreathScale
self.LegEnt:SetPoseParameter("breathing", Legs.BreathScale)
end
self.LegEnt:SetPoseParameter("move_x", (LocalPlayer():GetPoseParameter("move_x") * 2) - 1) -- Translate the walk x direction
self.LegEnt:SetPoseParameter("move_y", (LocalPlayer():GetPoseParameter("move_y") * 2) - 1) -- Translate the walk y direction
self.LegEnt:SetPoseParameter("move_yaw", (LocalPlayer():GetPoseParameter("move_yaw") * 360) - 180) -- Translate the walk direction
self.LegEnt:SetPoseParameter("body_yaw", (LocalPlayer():GetPoseParameter("body_yaw") * 180) - 90) -- Translate the body yaw
self.LegEnt:SetPoseParameter("spine_yaw",(LocalPlayer():GetPoseParameter("spine_yaw") * 180) - 90) -- Translate the spine yaw
if (LocalPlayer():InVehicle()) then
self.LegEnt:SetPoseParameter("vehicle_steer", (LocalPlayer():GetVehicle():GetPoseParameter("vehicle_steer") * 2) - 1) -- Translate the vehicle steering
end
end
end
Legs.RenderAngle = nil
Legs.BiaisAngle = nil
Legs.RadAngle = nil
Legs.RenderPos = nil
Legs.RenderColor = {}
Legs.ClipVector = vector_up * -1
Legs.ForwardOffset = -24
function Legs:DoFinalRender()
cam.Start3D(EyePos(), EyeAngles())
if (ShouldDrawLegs()) then
self.RenderPos = LocalPlayer():GetPos()
if (LocalPlayer():InVehicle()) then
self.RenderAngle = LocalPlayer():GetVehicle():GetAngles()
self.RenderAngle:RotateAroundAxis(self.RenderAngle:Up(), 90)
else
self.BiaisAngles = sharpeye_focus and sharpeye_focus.GetBiaisViewAngles and sharpeye_focus:GetBiaisViewAngles() or LocalPlayer():EyeAngles()
self.RenderAngle = Angle(0, self.BiaisAngles.y, 0)
self.RadAngle = math.rad(self.BiaisAngles.y)
self.ForwardOffset = -22
self.RenderPos.x = self.RenderPos.x + math.cos(self.RadAngle) * self.ForwardOffset
self.RenderPos.y = self.RenderPos.y + math.sin(self.RadAngle) * self.ForwardOffset
if (LocalPlayer():GetGroundEntity() == NULL) then
self.RenderPos.z = self.RenderPos.z + 8
if (LocalPlayer():KeyDown(IN_DUCK)) then
self.RenderPos.z = self.RenderPos.z - 28
end
end
end
self.RenderColor = LocalPlayer():GetColor()
local bEnabled = render.EnableClipping(true)
render.PushCustomClipPlane(self.ClipVector, self.ClipVector:Dot(EyePos()))
render.SetColorModulation(self.RenderColor.r / 255, self.RenderColor.g / 255, self.RenderColor.b / 255)
render.SetBlend(self.RenderColor.a / 255)
self.LegEnt:SetRenderOrigin(self.RenderPos)
self.LegEnt:SetRenderAngles(self.RenderAngle)
self.LegEnt:SetupBones()
self.LegEnt:DrawModel()
self.LegEnt:SetRenderOrigin()
self.LegEnt:SetRenderAngles()
render.SetBlend(1)
render.SetColorModulation(1, 1, 1)
render.PopCustomClipPlane()
render.EnableClipping(bEnabled)
end
cam.End3D()
end
function Legs:FixBones()
for i = 0, self.LegEnt:GetBoneCount() do
self.LegEnt:ManipulateBoneScale(i, Vector(1, 1, 1))
self.LegEnt:ManipulateBonePosition(i, vector_origin)
end
self.BonesToRemove =
{
"ValveBiped.Bip01_Head1",
"ValveBiped.Bip01_L_Hand",
"ValveBiped.Bip01_L_Forearm",
"ValveBiped.Bip01_L_Upperarm",
"ValveBiped.Bip01_L_Clavicle",
"ValveBiped.Bip01_R_Hand",
"ValveBiped.Bip01_R_Forearm",
"ValveBiped.Bip01_R_Upperarm",
"ValveBiped.Bip01_R_Clavicle",
"ValveBiped.Bip01_L_Finger4",
"ValveBiped.Bip01_L_Finger41",
"ValveBiped.Bip01_L_Finger42",
"ValveBiped.Bip01_L_Finger3",
"ValveBiped.Bip01_L_Finger31",
"ValveBiped.Bip01_L_Finger32",
"ValveBiped.Bip01_L_Finger2",
"ValveBiped.Bip01_L_Finger21",
"ValveBiped.Bip01_L_Finger22",
"ValveBiped.Bip01_L_Finger1",
"ValveBiped.Bip01_L_Finger11",
"ValveBiped.Bip01_L_Finger12",
"ValveBiped.Bip01_L_Finger0",
"ValveBiped.Bip01_L_Finger01",
"ValveBiped.Bip01_L_Finger02",
"ValveBiped.Bip01_R_Finger4",
"ValveBiped.Bip01_R_Finger41",
"ValveBiped.Bip01_R_Finger42",
"ValveBiped.Bip01_R_Finger3",
"ValveBiped.Bip01_R_Finger31",
"ValveBiped.Bip01_R_Finger32",
"ValveBiped.Bip01_R_Finger2",
"ValveBiped.Bip01_R_Finger21",
"ValveBiped.Bip01_R_Finger22",
"ValveBiped.Bip01_R_Finger1",
"ValveBiped.Bip01_R_Finger11",
"ValveBiped.Bip01_R_Finger12",
"ValveBiped.Bip01_R_Finger0",
"ValveBiped.Bip01_R_Finger01",
"ValveBiped.Bip01_R_Finger02",
"ValveBiped.Bip01_Spine4",
"ValveBiped.Bip01_Spine2",
}
if (LocalPlayer():InVehicle()) then
self.BonesToRemove =
{
"ValveBiped.Bip01_Head1",
}
end
for _, v in pairs(self.BonesToRemove) do
local bone = self.LegEnt:LookupBone(v)
if (bone) then
self.LegEnt:ManipulateBoneScale(bone, vector_origin)
if (!LocalPlayer():InVehicle()) then
self.LegEnt:ManipulateBonePosition(bone, Vector(0, -100, 0))
self.LegEnt:ManipulateBoneAngles(bone, angle_zero)
end
end
end
end
function PLUGIN:PlayerWeaponChanged(client, weapon)
if (client == LocalPlayer() and IsValid(Legs.LegEnt)) then
Legs:FixBones()
end
end
function PLUGIN:UpdateAnimation(client, velocity, maxSeqGroundSpeed)
if (client == LocalPlayer()) then
if (IsValid(Legs.LegEnt)) then
Legs:Think(maxSeqGroundSpeed)
else
Legs:Setup()
end
end
end
function PLUGIN:PlayerModelChanged(client, model)
if (client == LocalPlayer()) then
Legs:Setup(model)
Legs:FixBones()
end
end
function PLUGIN:PostDrawTranslucentRenderables()
if (LocalPlayer() and !LocalPlayer():InVehicle()) then
Legs:DoFinalRender()
end
end
function PLUGIN:RenderScreenspaceEffects()
if (LocalPlayer():InVehicle()) then
Legs:DoFinalRender()
end
end
end