-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverstart.lua
326 lines (260 loc) · 7.57 KB
/
serverstart.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
318
319
320
321
322
323
324
325
326
--For now dynamic types are used for creating both static and dynamic physics/mesh objects
--The player
brickhead = newDynamicType("brickhead","Assets/brickhead/brickhead.txt",0.02,0.02,0.02)
addAnimation(brickhead,"walk",0,30,0.04,200,400) --For now it just uses the first added animation as the walk cycle
--Different floor tile types
smallPlate = newDynamicType("small","Assets/cube/cube.txt",0.01,0.01,0.01)
mediumPlate = newDynamicType("medium","Assets/cube/cube.txt",0.02,0.01,0.02)
largePlate = newDynamicType("large","Assets/cube/cube.txt",0.04,0.01,0.04)
centerPlate = newDynamicType("center","Assets/cube/cube.txt",0.1,0.01,0.1)
button = newDynamicType("button","Assets/button/button.txt",1,1,1)
--Different arrays of kinds of plates that can be made to dissapear with their own button
larges = {}
mediums = {}
smalls = {}
lefts = {}
rights = {}
whites = {}
blacks = {}
reds = {}
greens = {}
blues = {}
buttonColor = 1
function jumpButtonColor()
buttonColor = buttonColor + 1
if buttonColor > 3 then
buttonColor = 1
end
if buttonColor == 1 then
jumpButton:setMeshColor("Button",1,0,0,1)
elseif buttonColor == 2 then
jumpButton:setMeshColor("Button",0,1,0,1)
else
jumpButton:setMeshColor("Button",0,0,1,1)
end
buttonColorSch = schedule(500,"jumpButtonColor")
end
doingAHide = false
function hide(obj)
obj:setHidden(true)
end
function show(obj)
obj:setHidden(false)
end
function reappear(obj)
obj:setColliding(true)
obj:setHidden(false)
doingAHide = false
end
function dissapear(obj)
obj:setColliding(false)
obj:setHidden(true)
end
function selectPanel(obj)
if doingAHide == true then
return
end
hide(obj)
schedule(500,"show",obj)
schedule(1000,"hide",obj)
schedule(1500,"show",obj)
schedule(2000,"dissapear",obj)
schedule(8000,"reappear",obj)
end
function gravityOn(d)
for i=0,getNumDynamics()-1,1 do
getDynamicIdx(i):setGravity(0,-50,0)
end
end
function click(client,posX,posY,posZ,dirX,dirY,dirZ,mask)
ignore = nil
if client:getNumControlled() > 0 then
ignore = client:getControlledIdx(0)
end
result = raycast(posX,posY,posZ,posX + dirX * 30,posY + dirY * 30,posZ + dirZ * 30,ignore)
if result == nil then
return client,posX,posY,posZ,dirX,dirY,dirZ,mask
end
if result.id == jumpButton.id then
ignore:setPosition(50,50,0)
end
if result.id == redButton.id then
for k,v in pairs(reds) do
selectPanel(v)
end
doingAHide = true
end
if result.id == greenButton.id then
for k,v in pairs(greens) do
selectPanel(v)
end
doingAHide = true
end
if result.id == blueButton.id then
for k,v in pairs(blues) do
selectPanel(v)
end
doingAHide = true
end
if result.id == gravityButton.id then
for i=0,getNumDynamics()-1,1 do
getDynamicIdx(i):setGravity(0,-5,0)
end
schedule(8000,"gravityOn")
end
return client,posX,posY,posZ,dirX,dirY,dirZ,mask
end
registerEventListener("ClientClick","click")
--z > 0 left
--z < 0 right
function setUpLevel()
levelSetUp = true
gravityButton = createStatic(button,40,42,5)
gravityButton:setMeshColor("Button",1,1,0,1)
redButton = createStatic(button,45,42,5)
redButton:setMeshColor("Button",1,0,0,1)
blueButton = createStatic(button,50,42,5)
blueButton:setMeshColor("Button",0,0,1,1)
greenButton = createStatic(button,55,42,5)
greenButton:setMeshColor("Button",0,1,0,1)
jumpButton = createStatic(button,0,1,0)
jumpButtonColor()
createStatic(centerPlate,50,40,0)
last = createStatic(centerPlate,0,30,0)
last:setMeshColor("Cube",1,1,1,1)
table.insert(larges,last)
table.insert(whites,last)
last = createStatic(largePlate,0,30,15)
last:setMeshColor("Cube",1,0,0,1)
table.insert(larges,last)
table.insert(reds,last)
table.insert(lefts,last)
last = createStatic(largePlate,0,30,-15)
last:setMeshColor("Cube",0,1,0,1)
table.insert(larges,last)
table.insert(greens,last)
table.insert(rights,last)
last = createStatic(largePlate,15,30,0)
last:setMeshColor("Cube",0,0,0,1)
table.insert(larges,last)
table.insert(blacks,last)
last = createStatic(largePlate,-15,30,0)
last:setMeshColor("Cube",0,0,0,1)
table.insert(larges,last)
table.insert(blacks,last)
last = createStatic(mediumPlate,10,30,15)
last:setMeshColor("Cube",1,1,1,1)
table.insert(whites,last)
table.insert(mediums,last)
table.insert(lefts,last)
last = createStatic(mediumPlate,-10,30,15)
last:setMeshColor("Cube",0,0,0,1)
table.insert(blacks,last)
table.insert(mediums,last)
table.insert(lefts,last)
last = createStatic(mediumPlate,10,30,-15)
last:setMeshColor("Cube",1,0,0,1)
table.insert(reds,last)
table.insert(mediums,last)
table.insert(rights,last)
last = createStatic(mediumPlate,-10,30,-15)
last:setMeshColor("Cube",0,0,1,1)
table.insert(blues,last)
table.insert(mediums,last)
table.insert(rights,last)
last = createStatic(mediumPlate,15,30,10)
last:setMeshColor("Cube",0,0,1,1)
table.insert(blues,last)
table.insert(mediums,last)
table.insert(lefts,last)
last = createStatic(mediumPlate,15,30,-10)
last:setMeshColor("Cube",0,1,0,1)
table.insert(greens,last)
table.insert(mediums,last)
table.insert(rights,last)
last = createStatic(mediumPlate,-15,30,10)
last:setMeshColor("Cube",1,0,0,1)
table.insert(reds,last)
table.insert(mediums,last)
table.insert(lefts,last)
last = createStatic(mediumPlate,-15,30,-10)
last:setMeshColor("Cube",0,1,0,1)
table.insert(greens,last)
table.insert(mediums,last)
table.insert(rights,last)
last = createStatic(smallPlate,-25,30,0)
last:setMeshColor("Cube",1,1,1,1)
table.insert(smalls,last)
table.insert(whites,last)
last = createStatic(smallPlate,-22,30,15)
last:setMeshColor("Cube",0,0,0,1)
table.insert(smalls,last)
table.insert(blacks,last)
table.insert(lefts,last)
last = createStatic(smallPlate,-22,30,-15)
last:setMeshColor("Cube",0,1,0,1)
table.insert(smalls,last)
table.insert(greens,last)
table.insert(rights,last)
last = createStatic(smallPlate,25,30,0)
last:setMeshColor("Cube",0,1,0,1)
table.insert(smalls,last)
table.insert(greens,last)
last = createStatic(smallPlate,22,30,15)
last:setMeshColor("Cube",1,0,0,1)
table.insert(smalls,last)
table.insert(reds,last)
table.insert(lefts,last)
last = createStatic(smallPlate,22,30,-15)
last:setMeshColor("Cube",0,0,1,1)
table.insert(smalls,last)
table.insert(blues,last)
table.insert(rights,last)
last = createStatic(smallPlate,0,30,25)
last:setMeshColor("Cube",0,1,0,1)
table.insert(smalls,last)
table.insert(greens,last)
table.insert(lefts,last)
last = createStatic(smallPlate,0,30,-25)
last:setMeshColor("Cube",0,0,0,1)
table.insert(smalls,last)
table.insert(blacks,last)
table.insert(rights,last)
end
if levelSetUp == nil then
setUpLevel()
end
--Client confirms finishes loading SimObject types
function join(client)
--Create a player for the client
dynamic = createDynamic(0,0,50,0)
--Dynamic cannot tip over
dynamic:setAngularFactor(0,0,0);
--Client is responcible for physics simulation of this object
client:giveControl(dynamic)
--Max camera distance: 20
client:bindCamera(dynamic,true,20)
--This function will be replaced with something better, for now the only way to un-control the object is to delete it
client:setDefaultController(dynamic)
return client
end
registerEventListener("ClientJoin","join")
--Called right after client disconnects but client object is not deleted
function leave(client)
--Destroy the client's player(s)
for i = 0, client:getNumControlled() - 1, 1 do
client:getControlledIdx(i):destroy()
end
return client
end
registerEventListener("ClientLeave","leave")
--For easy testing
function gc()
return getClientIdx(0)
end
function gp(client)
return client:getControlledIdx(0)
end
function me()
return gp(gc())
end