-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathfirstperson.lua
69 lines (55 loc) · 2.69 KB
/
firstperson.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
local PLUGIN = PLUGIN
PLUGIN.name = "Immersive Firstperson"
PLUGIN.description = "Adds a Plugin which lets you view your full body and on your head."
PLUGIN.author = "Riggs"
PLUGIN.schema = "Any"
PLUGIN.license = [[
Copyright 2024 Riggs
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
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 OR COPYRIGHT HOLDERS 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.
]]
ix.option.Add("FirstPersonEnable", ix.type.bool, false, {
category = "First Person",
phrase = "First Person Enable"
})
ix.option.Add("FullBody", ix.type.bool, false, {
category = "First Person",
phrase = "Full Body"
})
function PLUGIN:CalcView(ply, origin, angles, fov)
local view = {
origin = origin,
angles = angles,
fov = 90,
drawviewer = true
}
local head = ply:LookupAttachment("eyes")
head = ply:GetAttachment(head)
if not head or not head.Pos then return end
if IsValid(ix.gui.menu) or IsValid(ix.gui.characterMenu) then return end
if not ix.option.Get("FirstPersonEnable", false) then return end
if (ply:GetMoveType() == MOVETYPE_NOCLIP) then return end
if not ply.BonesRattled then
ply.BonesRattled = true
ply:InvalidateBoneCache()
ply:SetupBones()
local matrix
for bone = 0, (ply:GetBoneCount() or 1) do
if ply:GetBoneName(bone):lower():find("head") then
matrix = ply:GetBoneMatrix(bone)
break
end
end
if IsValid(matrix) then
matrix:SetScale(Vector(0, 0, 0))
end
end
view.origin = head.Pos + head.Ang:Up()
if ix.option.Get("FullBody", false) then
view.angles = head.Ang
else
view.angles = Angle(head.Ang.p, head.Ang.y, angles.r)
end
return view
end