-
Notifications
You must be signed in to change notification settings - Fork 11
/
splinehelper.lua
189 lines (174 loc) · 5.87 KB
/
splinehelper.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
local function throw(msg)
local _, err = pcall(error, msg, 4)
error(err)
end
local function correctAxis(axis)
local caxis={}
local validAxis={
{'x','X'},
{'movex','X'},
{'y','Y'},
{'movey','Y'},
{'z','Z'},
{'movez','Z'},
{'rotx','RotX'},
{'rx','RotX'},
{'rotationx','RotX'},
{'roty','RotY'},
{'ry','RotY'},
{'rotationy','RotY'},
{'rotz','RotZ'},
{'rz','RotZ'},
{'rotationz','RotZ'},
{'size','Size'},
{'tiny','Size'},
{'skew','Skew'},
{'stealth','Stealth'}
}
for _,i in pairs(axis) do
local axisfound=false
for _,v in pairs(validAxis) do
if string.lower(i)==v[1] then
table.insert(caxis,v[2])
axisfound=true
end
end
if not axisfound then throw('invalid axis: '..i) end
end
if caxis~={} then
return caxis
end
end
local function setSpline(players,column,pointlist,axis,activation)
for _,plr in pairs(players) do
for _,col in pairs(column) do
for index,point in pairs(pointlist) do
if index<=40 then
if axis=='X' then
P[plr]:SetXSpline(index-1,col,point[2],point[1],activation)
elseif axis=='Y' then
P[plr]:SetYSpline(index-1,col,point[2],point[1],activation)
elseif axis=='Z' then
P[plr]:SetZSpline(index-1,col,point[2],point[1],activation)
elseif axis=='RotX' then
P[plr]:SetRotXSpline(index-1,col,point[2],point[1],activation)
elseif axis=='RotY' then
P[plr]:SetRotYSpline(index-1,col,point[2],point[1],activation)
elseif axis=='RotZ' then
P[plr]:SetRotZSpline(index-1,col,point[2],point[1],activation)
elseif axis=='Size' then
P[plr]:SetSizeSpline(index-1,col,point[2],point[1],activation)
elseif axis=='Skew' then
P[plr]:SetSkewSpline(index-1,col,point[2],point[1],activation)
elseif axis=='Stealth' then
P[plr]:SetStealthSpline(index-1,col,point[2],point[1],activation)
end
end
end
end
end
end
local function resetSpline(players,column,axis)
for _,plr in pairs(players) do
for _,col in pairs(column) do
if axis=='X' then
P[plr]:ResetXSplines(col)
elseif axis=='Y' then
P[plr]:ResetYSplines(col)
elseif axis=='Z' then
P[plr]:ResetZSplines(col)
elseif axis=='RotX' then
P[plr]:ResetRotXSplines(col)
elseif axis=='RotY' then
P[plr]:ResetRotYSplines(col)
elseif axis=='RotZ' then
P[plr]:ResetRotZSplines(col)
elseif axis=='Size' then
P[plr]:ResetSizeSplines(col)
elseif axis=='Skew' then
P[plr]:ResetSkewSplines(col)
elseif axis=='Stealth' then
P[plr]:ResetStealthSplines(col)
end
end
end
end
local function set(t)
local axis=t[1]
if type(axis) == 'string' then axis = {axis} end
axis=correctAxis(axis)
local pointlist={}
if type(t[2])=='table' then
pointlist=t[2]
else
local i = 2
while t[i] do
if type(t[i]) ~= 'number' then
throw('invalid offset at index '..i)
end
if type(t[i + 1]) ~= 'number' then
throw('invalid value at index '..(i+1))
end
table.insert(pointlist,{t[i],t[i+1]})
i = i + 2
end
end
local players = t.plr or rawget(xero, 'plr') or {1, 2}
if type(players) == 'number' then players = {players} end
local column = t.col or -1
if type(column) == 'number' then column = {column} end
local activation=t.speed or -1
local cl,cd,cu,cr,ca=false
for _,v in pairs(column) do
if v==-1 then ca=true
elseif v==0 then cl=true
elseif v==1 then cd=true
elseif v==2 then cu=true
elseif v==3 then cr=true
else
throw('invalid column: '..v)
end
end
if ca or (cl and cd and cu and cr) then
column={-1}
end
for _,v in pairs(axis) do
setSpline(players,column,pointlist,v,activation)
end
return set
end
local function reset(t)
if t[1]==nil then t[1]={'all'} end
local axis=t[1]
if type(axis) == 'string' then axis = {axis} end
if axis[1]=='all' then
axis={'X','Y','Z','RotX','RotY','RotZ','Size','Skew','Stealth'}
else
axis=correctAxis(axis)
end
local players = t.plr or rawget(xero, 'plr') or {1, 2}
if type(players) == 'number' then players = {players} end
local column = t.col or {0,1,2,3}
if type(column) == 'number' then column = {column} end
local cl,cd,cu,cr,ca=false
for _,v in pairs(column) do
if v==-1 then ca=true
elseif v==0 then cl=true
elseif v==1 then cd=true
elseif v==2 then cu=true
elseif v==3 then cr=true
else
throw('invalid column: '..v)
end
end
if ca or (cl and cd and cu and cr) then
column={0,1,2,3}
end
for _,v in pairs(axis) do
resetSpline(players,column,v)
end
end
return {
reset = reset,
set = set
}