/
script.cs
558 lines (519 loc) · 13.9 KB
/
script.cs
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
/*
__ __ _
| \/ | /\ ( )
| \ / |_ __ / \ _ __ _ _ ___ _ __ ___|/ ___
| |\/| | '__/ /\ \ | '_ \| | | |/ _ \| '_ \ / _ \ / __|
| | | | | / ____ \| | | | |_| | (_) | | | | __/ \__ \
|_| |_|_|/_/ \_\_| |_|\__, |\___/|_| |_|\___| |___/
__/ |
_____ _ __|___/ _ _
| __ \ (_) / ____| (_) | |
| |__) |__ _ _ _ __ | (___ ___ _ __ _ _ __ | |_
| _ // _` | | '_ \ \___ \ / __| '__| | '_ \| __|
| | \ \ (_| | | | | | ____) | (__| | | | |_) | |_
|_| \_\__,_|_|_| |_| |_____/ \___|_| |_| .__/ \__|
| |
|_|
000 00
0000000 0000
0 00 00000000000000000
0000 0 000000000000000000000000 0
000000000000000000000000000000000000000 000
0000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000
/ / / / / / / / / / / / / / / /
/ / / / / / / / / / / / / / /
/ / / / / / / / / / / / / / /
/ / / / / / / / / / / / / /
/ / / / / / / / / / / / /
/ / / / / / / / / / / /
/ / / / / / / / / /
...........RUN FOR YOUR LIVES!.
*/
// Settings vars
// Stop the rain on gameover?
bool stopOnGameOver = true;
// Primary tick speed ratio,
// affects the rain strenght
int[] tickRand = {200, 900};
// Changes the 'rain stage' after
// some rand time ratio, making it
// heavier or not
int[] rainStageRand = {3000, 5000};
// Drops life time, makes
// them disapear after
// XXX miliseconds
int dropsLifeTime = 2000;
// Destroys or remove the
// objects when they are
// removed
static bool destroyOnDeath = false;
// Remove or not junk
// objects
bool removeJunk = true;
// Sets the drops speed rand
int[] rainDropsSpeed = {-20, 20};
// Sets the drop angular velocity
// (only for objects, players wont be
// affected)
int[] rainDropsAngularSpeed = {-10, 10};
// Objects that will rain list
// "PLAYER" is a special flag
// to make a player rain
// Remove the "//" in the line
// to select which objects.
// The last object MUST NOT HAVE
// A COMMA IN THE END
// as follow: array {
// "firsts",
// "last"
// }
string[] rainDrops = {
"PLAYER",
// "AcidVat00Top",
// "AcidVat00A",
// "AcidVat00B",
// "AcidVat00C",
// "Button00",
// "ButtonPole00",
// "Lever00",
// "AtlasStatue00",
// "AtlasStatue00_D",
// "AtlasStatue00Globe",
// "Balloon00",
// "Balloon00_D",
// "BambooScaffold00A",
// "BambooScaffold00B",
// "BambooScaffold00C",
// "BambooScaffold00D",
// "BambooStick00A",
// "BambooStick00B",
// "BambooStick00C",
// "BambooStick00D",
"Barrel00",
"BarrelExplosive",
// "BarrelWreck",
// "BigMachine00A",
// "BigMachine00Top",
// "BlastDoor00A",
// "BlastDoor00B",
// "BlastDoor00C",
"Bottle00",
// "Bottle00Broken",
// "BridgePlank00",
// "BridgePlank01",
// "Computer00",
// "MetalBucket00",
// "Monitor00",
// "Monitor00_D",
// "Car01A",
"CarWheel00",
"CardboardBox00",
// "CardboardBox00_D",
// "CargoContainer00A",
// "CargoContainer01A",
// "CargoContainer01B",
// "CashRegister00",
"Chair00",
// "Chandelier00",
// "Chandelier01A",
// "Chandelier01B",
// "Chandelier01C",
// "Chandelier01D",
// "ComfyChair",
// "Concrete01ADynamic",
// "Concrete01DDynamic",
// "Concrete01EDynamic",
// "ConcretePipe01",
// "ConveyorBelt00A",
// "ConveyorBelt00B",
// "ConveyorBelt00C",
// "CueStick00",
// "CueStick00Shaft",
// "CueStick00Debris",
"CrabCan00",
// "CrabCan00_D",
// "Boot00",
"Gascan00",
// "GasLamp00_D",
// "GasMask00",
// "Helmet00",
// "Concrete01Weak",
"Crate00",
"Crate01",
"Crate02",
// "CrumpledPaper00",
// "Cup00",
// "Desk00",
// "Cage00",
// "Cage00_D",
// "Dove00",
// "Duct00C_D",
// "DrinkingGlass00",
// "DeskLamp00",
// "Elevator02A",
// "Elevator02B",
// "Elevator02C",
// "Elevator02D",
// "Elevator03A",
// "Elevator03B",
// "Elevator04A",
// "FerrisWheel00",
// "FerrisWheelCart00",
// "CarnivalCart00",
// "CarnivalCart01",
// "CarnivalCart01_D",
// "CarnivalFerrisWheel",
// "FileCab00",
// "Gargoyle00",
// "Gargoyle00_D",
// "HangingCrate00",
// "HangingCrate01",
// "HangingCrateHolder",
// "HangingLamp00",
// "HangingLamp00_D",
// "Lamp00",
// "Lamp00_D",
// "Lamp01",
// "Lamp01_D",
// "Lifeboat00",
// "Hook00",
// "Hook01",
// "Lift00A",
// "Lift00B",
// "Lift00C",
// "Lift00D",
// "MetalHatch00A",
// "MetalHatch00B",
// "MetalDesk00",
// "MetalShelf00A",
// "MetalShelf00B",
// "MetalRailing00",
// "MetalRailing00_D",
// "MetalTable00",
"MoneyClip00",
// "Padlock00",
// "Padlock00_D",
// "Pallet00",
// "PaperBinder00",
// "PaperLantern00",
"PaperStack00",
// "Plank00",
// "Plank02",
// "Plank01",
// "Piano00",
// "Piano00_D",
// "Piston00A",
// "Piston00B",
"PropaneTank",
// "Pulley00",
// "Pulley00Weak",
// "Pulley01",
// "Sampan00",
// "Safe00",
// "Shelf00",
// "SearchLight00",
// "SearchLight00Holder",
// "Spotlight00A",
// "Spotlight00A_D",
// "Spotlight00B",
"Suitcase00",
// "Suitcase00Debris1",
// "Suitcase00Debris2",
// "SupplyCrate00",
// "SteamshipWheel00",
// "StoneWeak00A",
// "StoneWeak00B",
// "StoneWeak00C",
// "SubwayTrain00",
// "SurveillanceCamera00A",
// "SwivelChair01",
// "SwivelChair02",
"Table00",
// "Teapot00",
// "TinRoof00",
// "TinRoof00_D",
// "TrainCar00A",
// "TrainCarLocomotive00A",
// "TrainingTarget00",
"Trashbag00",
// "Trashcan00",
// "Trashcan00_D",
// "Trashcan00Lid",
// "Truck00B",
// "TruckWheel",
// "Van00",
// "WarningLamp00",
// "WarningLamp01",
// "WaterTrough00",
// "WindMill00",
// "WindMillSail00",
// "WindMillSail00_D",
// "WindMillSail00_D2",
// "WiringTube00A",
// "WiringTube00A_D",
// "WiringTube00B",
// "WoodPlat01WeakA",
// "WoodPlat01WeakB",
// "WoodAwning00A",
// "WoodAwning00B",
// "WoodAwning00B_D",
// "WoodBarrel00",
// "WoodBarrel01",
// "WoodLattice00A",
// "WoodRailing00",
// "WoodSupport00A",
// "WoodSupport00B",
// "LightBulb00",
"LightSign00E",
// "LightSign00E_D",
"LightSign00H",
// "LightSign00H_D",
"LightSign00L",
// "LightSign00L_D",
"LightSign00O",
// "LightSign00O_D",
"LightSign00T",
// "LightSign00T_D",
// "LightSign00Debris1",
"XmasPresent00"
// "XmasTree",
// "XmasTree_D",
// "Giblet00",
// "Giblet01",
// "Giblet02",
// "Giblet03",
// "Giblet04",
// "StoneDebris00A",
// "StoneDebris00B",
// "StoneDebris00C",
// "StoneDebris00D",
// "StoneDebris00E",
// "MetalDebris00A",
// "MetalDebris00B",
// "MetalDebris00C",
// "MetalDebris00D",
// "MetalDebris00E",
// "WoodBarrelDebris00A",
// "WoodBarrelDebris00B",
// "WoodBarrelDebris00C",
// "WoodDebris00A",
// "WoodDebris00B",
// "WoodDebris00C",
// "WoodDebris00D",
// "WoodDebris00E",
// "WoodDebrisTable00A",
// "WoodDebrisTable00B",
// "ChairLeg",
// "GlassShard00A"
};
// Script vars
// A list of all players skins loaded
// in the current game
private static List<IProfile> pProfileList = new List<IProfile>();
// Death sentences object, used to delete objects after some time
private static List<Hit> hits = new List<Hit>();
// Tick trigger
private IObjectTimerTrigger tickTrigger;
// Randomize time trigger, used to
// make the rain more dynamic
private IObjectTimerTrigger randomizeTimeTrigger;
// A black list to remove
// junk objects
string[] blackList = {
"CueStick00Debris",
"Suitcase00Debris1",
"Suitcase00Debris2",
"LightSign00Debris1",
"StoneDebris00A",
"StoneDebris00B",
"StoneDebris00C",
"StoneDebris00D",
"StoneDebris00E",
"MetalDebris00A",
"MetalDebris00B",
"MetalDebris00C",
"MetalDebris00D",
"MetalDebris00E",
"WoodBarrelDebris00A",
"WoodBarrelDebris00B",
"WoodBarrelDebris00C",
"WoodDebris00A",
"WoodDebris00B",
"WoodDebris00C",
"WoodDebris00D",
"WoodDebris00E",
"WoodDebrisTable00A",
"WoodDebrisTable00B",
"GlassShard00A",
"AtlasStatue00_D",
"Balloon00_D",
"Monitor00_D",
"CardboardBox00_D",
"CrabCan00_D",
"GasLamp00_D",
"Cage00_D",
"Duct00C_D",
"CarnivalCart01_D",
"Gargoyle00_D",
"HangingLamp00_D",
"Lamp00_D",
"Lamp01_D",
"MetalRailing00_D",
"Padlock00_D",
"Piano00_D",
"Spotlight00A_D",
"TinRoof00_D",
"Trashcan00_D",
"WindMillSail00_D",
"WindMillSail00_D2",
"WiringTube00A_D",
"WoodAwning00B_D",
"LightSign00E_D",
"LightSign00H_D",
"LightSign00L_D",
"LightSign00O_D",
"LightSign00T_D",
"XmasTree_D",
"Bottle00Broken",
"Giblet00",
"Giblet01",
"Giblet02",
"Giblet03",
"Giblet04"
};
//Rand
Random rand = new Random();
// Constants
const float DISTANCE_FROM_TOP = 50f;
public void OnStartup(){
// Get the profiles, from players
// & custom ones
foreach(IObjectPlayerProfileInfo pInfo in Game.GetObjectsByName("PlayerProfileInfo")){
pProfileList.Add(pInfo.GetProfile());
}
foreach (IPlayer ply in Game.GetPlayers()){
pProfileList.Add(ply.GetProfile());
}
// Setup the triggers
tickTrigger = Utils.SetTimer("Tick", "", 0, rand.Next(tickRand[0], tickRand[1]));
randomizeTimeTrigger = Utils.SetTimer("RandomizeDelay", "", rainStageRand[0], rainStageRand[1]);
Utils.SetTimer("DeleteTash", "", 0, 20000);
Utils.SetTimer("CheckHits", "", 0, 100);
Utils.SendMessage("Welcome to rain script!");
Utils.SendMessage("Made by: MrAnyone.");
Utils.SendMessage("Contact me at: m3rc3r99@gmail.com");
Utils.SendMessage("There are a LOT of settings you can setup.");
//Game.CreatePlayer(Game.GetSingleObjectByCustomID("spawn").GetWorldPosition());
}
// Main tick
public void Tick(TriggerArgs args){
//Stop on gameover?
if(!(Game.IsGameOver && stopOnGameOver)) {
SpawnDrop(rainDrops[rand.Next(0, rainDrops.Length)]);
}
}
// Tells which object will be spawned
// PLAYER flags spawns a corpse
public void SpawnDrop(string name) {
if(name == "PLAYER") {
SpawnRandomPlayer();
}
else {
SpawnObject(name);
}
}
// Randomize the rain
public void RandomizeDelay(TriggerArgs args){
tickTrigger.SetIntervalTime(rand.Next(tickRand[0], tickRand[1]));
randomizeTimeTrigger.SetIntervalTime(rand.Next(rainStageRand[0], rainStageRand[1]));
}
// Spawns a dead players
// based in the map top
public void SpawnRandomPlayer(){
IProfile cProfile = pProfileList[rand.Next(pProfileList.Count)];
IPlayer cPly = Game.CreatePlayer(new Vector2((float)rand.Next((int)Game.GetBorderArea().Left, (int)Game.GetBorderArea().Right), (int)Game.GetBorderArea().Top + DISTANCE_FROM_TOP));
cPly.SetProfile(cProfile);
cPly.SetLinearVelocity(new Vector2((float)rand.Next(rainDropsSpeed[0], rainDropsSpeed[1]), (float)rand.Next(rainDropsSpeed[0], rainDropsSpeed[1])));
cPly.Kill();
AddHit((IObject)cPly);
}
// Spawns a object
// based in the map top
public void SpawnObject(string name) {
IObject obj = Game.CreateObject(name, new Vector2((float)rand.Next((int)Game.GetBorderArea().Left, (int)Game.GetBorderArea().Right), (int)Game.GetBorderArea().Top + DISTANCE_FROM_TOP), 0, new Vector2((float)rand.Next(rainDropsSpeed[0], rainDropsSpeed[1]), (float)rand.Next(rainDropsSpeed[0], rainDropsSpeed[1])), (float)rand.Next(rainDropsAngularSpeed[0], rainDropsAngularSpeed[1]));
AddHit(obj);
}
// Adds a object to be removed
// after some time in the game
public void AddHit(IObject obj) {
hits.Add(new Hit(obj, dropsLifeTime));
}
// Checks if some objects must
// be removed after the delays
public void CheckHits(TriggerArgs args){
try{
foreach (Hit hit in hits){
if(hit.MustDie()){
hit.Kill();
hits.Remove(hit);
}
}
}catch(Exception e){
return;
}
}
// Deletes trash objects
// from the map
public void DeleteTash(TriggerArgs args){
if(removeJunk) {
foreach (IObject obj in Game.GetObjectsByName(blackList)){
obj.Remove();
}
}
}
// A class used to control the objects
// life time
private class Hit{
private IObject obj;
private float lifetime;
private float controlTime;
public Hit(IObject obj, float lifetime){
this.obj = obj;
this.lifetime = Game.TotalElapsedGameTime + lifetime;
this.controlTime = lifetime;
}
public bool MustDie(){
if(Game.TotalElapsedGameTime - this.lifetime > this.controlTime){
return true;
}
else {
return false;
}
}
public void Kill(){
if(destroyOnDeath) {
this.obj.Destroy();
}
else {
this.obj.Remove();
}
}
}
// Utils class
private class Utils{
//Sets a timer
public static IObjectTimerTrigger SetTimer(string met, string id, int times, int delay){
IObjectTimerTrigger trigger = (IObjectTimerTrigger)Game.CreateObject("TimerTrigger");
trigger.CustomId = id;
trigger.SetScriptMethod(met);
trigger.SetIntervalTime(delay);
trigger.SetRepeatCount(times);
trigger.Trigger();
return trigger;
}
public static void SendMessage(string msg){
Game.RunCommand("/MSG |RAIN MOD| " + msg);
}
}