-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibWeps.mod.gml
625 lines (550 loc) · 19.8 KB
/
libWeps.mod.gml
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
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
/*
This is the Weps package of Lib, for
functions that help with making weapons
*/
//todo: eat hook, script for robot eating
/*
Scripts:
add_junk(_name, _obj, _type, _cost, _pwr)
superforce_push(obj, ?force, ?direction, ?friction, ?canwallhit, ?waittime, ?disableeffects, ?hook_merge)
bullet_recycle(_baseChance, _return, _patron)
wep_raw(_wep)
weapon_get(_name, _wep)
weapon_fire_init(_wep)
weapon_ammo_fire(_wep)
weapon_ammo_hud(_wep)
draw_ammo(_index, _primary, _steroids, _ammo, _ammoMin)
spawn_shell(_angle, _spread, _speed, _sprite)
draw_weapon_huge(sprt)
*/
//For internal use, adds the script to be easily usable.
#define addScript(name)
lq_set(instances_matching(CustomObject, "name", "libGlobal")[0].scriptReferences, name, ["mod", mod_current, name]);
#define init
addScript("add_junk");
addScript("superforce_push");
addScript("bullet_recycle");
addScript("weapon_get");
addScript("weapon_fire_init");
addScript("weapon_ammo_fire");
addScript("weapon_ammo_hud");
addScript("draw_ammo");
addScript("spawn_shell");
addScript("draw_weapon_huge");
script_ref_call(["mod", "lib", "updateRef"]);
global.isLoaded = true;
script_ref_call(["mod", "lib", "getRef"], "mod", mod_current, "scr");
global.sprRecycleShine = sprite_add_base64("iVBORw0KGgoAAAANSUhEUgAAABIAAAAJCAYAAAA/33wPAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAZdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuMjHxIGmVAAAATElEQVQoU82NwQ0AIAgDGc3R3FwFwZQmJvz0kn7OUqV1SRkLdiX46K8hHQnQI9Fjn45veNVwZbja4M/+bqBHosf+lCM8oinBR4+HRCYsc5eZijx2CwAAAABJRU5ErkJggg==",2,5,5);
global.junk = {
laser: {obj: Laser, typ: 5, cost: 1, pwr: 4},
bullet: {obj: Bullet1, typ: 1, cost: 1, pwr: 1},
shell: {obj: Bullet2, typ: 2, cost: 1, pwr: 0.2}
};
#macro scr global.scr
#macro call script_ref_call
#define add_junk(_name, _obj, _type, _cost, _pwr)
//adds a projectile to the "junk" pool of projectiles to spawn (basically, random projectile but balanced)
lq_set(global.junk, string_lower(_name), {obj:_obj, typ:_typ, cost:_cost, pwr:_pwr});
#define superforce_push
//obj, ?force, ?direction, ?friction, ?canwallhit, ?waittime, ?disableeffects, ?hook_merge
//Thank you JSBurg and Karmelyth for letting me use this from Defpack!
//Use for crazy knockback mechanics
//Usable hooks are: hook_kill, hook_step, hook_hit, hook_bounce, hook_wallhit, hook_wallkill
//Set the variable of the hook to a script reference, and it'll be called when appropriate.
//IMPORTANT: for all the hooks, such as hook_wallhit, if you return 1 you override the usual code
// Useful for cool stuff, but completely ignorable.
//on_hit passes in the hit object and itself
//Also, on_merge is different than the other hooks - the first argument is the object that will stay, the second is the one that will be destroyed. Leave as-is to have the latest object completely override the previous superforce.
with argument[0] if !instance_is(self, prop) with instance_create(x, y, CustomObject)
{
name = "SuperForce";
team = other.team;
creator = other;
or_maxspeed = "maxspeed" in other ? other.maxspeed : -1
mask_index = other.mask_index;
sprite_index = mskNothing;
if(argument_count > 1){
superforce = argument[1];
}else{
superforce = 18
}
if(argument_count > 2){
superdirection = argument[2];
}else{
superdirection = other.direction
}
if(argument_count > 3){
superfriction = argument[3];
}else{
superfriction = 1
}
if(argument_count > 4){
canwallhit = argument[4];
}else{
canwallhit = true
}
if(argument_count > 5){
timer = argument[5];
}else{
timer = 4
}
if(argument_count > 6){
disableeffects = argument[6];
}else{
disableeffects = false
}
motion_set(superdirection, superforce); // for easier direction manipulation on wall hit
on_step = script_ref_create(superforce_step);
with instances_matching_ne(instances_matching(CustomObject, "name", "SuperForce"), "id", self)
{
if creator == argument[0]
{
other.or_maxspeed = or_maxspeed;
if(argument_count > 7){
script_ref_call(argument[7], other, self);
}
instance_delete(self);
}
}
return self;
}
#define superforce_step
//apply "super force" to enemies
if timer > 0 {timer -= current_time_scale; exit}
if !instance_exists(creator) ||instance_is(creator, Nothing) ||instance_is(creator, TechnoMancer) ||instance_is(creator, Turret) ||instance_is(creator, MaggotSpawn) ||instance_is(creator, Nothing) ||instance_is(creator, LilHunterFly) || instance_is(creator, RavenFly){instance_delete(self); exit}
var pass_step = false
if("hook_step" in self){
pass_step = script_ref_call(hook_step);
}
if(!pass_step){
with creator
{
if(!other.disableeffects) repeat(2) with instance_create(x, y, Dust){motion_add(other.direction + random_range(-8, 8), choose(1, 2, 2, 3)); sprite_index = sprExtraFeet}
other.x = x;
other.y = y;
if "maxspeed" in self maxspeed = other.superforce
motion_set(other.direction, other.superforce);
var _s = "size" in self ? size : 0;
other.superforce -= other.superfriction * max(1, _s);
if other.superforce <= 0 {with other {
if or_maxspeed > -1 {
other.maxspeed = or_maxspeed
}
instance_delete(self)
exit}
}
}
if(!disableeffects) if superforce >= 3 with instance_create(creator.x + random_range(-3, 3), creator.y + random_range(-3, 3), ImpactWrists){
var _fac = .6
image_xscale = _fac
image_yscale = _fac
image_speed = .75
motion_add(other.creator.direction, random_range(1, 3) + 1)
image_angle = direction
}
if place_meeting(x + hspeed, y + vspeed, Wall) && canwallhit = true
{
var pass_bounce = false
if("hook_bounce" in self){
pass_bounce = script_ref_call(hook_bounce);
}
if(!pass_bounce){
if(!disableeffects) with instance_create(x, y, MeleeHitWall){image_angle = other.direction}
move_bounce_solid(false);
if(!disableeffects) {
sound_play_pitchvol(sndImpWristKill, 1.2, .8)
sound_play_pitchvol(sndWallBreak, .7, .8)
sound_play_pitchvol(sndHitRock, .8, .8)
sleep(32)
if("size" in creator){
view_shake_at(x, y, 8 * clamp(creator.size, 1, 3))
repeat(creator.size) instance_create(x, y, Debris)
}
}
}
if superforce > 4 with creator
{
var pass_wallhit = false
if("hook_wallhit" in other){
pass_wallhit = script_ref_call(other.hook_wallhit);
}
if(!pass_wallhit){
//trace("wall hit")
projectile_hit(self,round(ceil(other.superforce * 1.5)),1 ,direction)
if my_health <= 0
{
var pass_wallkill = false
if("hook_wallkill" in other){
pass_wallkill = script_ref_call(other.hook_wallkill);
}
if(!pass_wallkill){
if(!other.disableeffects) {
sleep(30)
view_shake_at(x, y, 16)
repeat(3) instance_create(x, y, Dust){sprite_index = sprExtraFeet}
}
}
}
}
}
if(!pass_bounce){
superforce *= .7
/*with instance_create(x+lengthdir_x(12,direction),y+lengthdir_y(12,direction),AcidStreak){
sprite_index = spr.SonicStreak
image_angle = other.direction + random_range(-32, 32) - 90
motion_add(image_angle+90,12)
friction = 2.1
}*/
if(!disableeffects) {
with instance_create(x, y, ChickenB) image_speed = .65
repeat(max(1, creator.size)) with instance_create(x, y, ImpactWrists){
var _fac = random_range(.2, .5)
image_xscale = _fac
image_yscale = _fac * 1.5
image_speed = 1 - _fac
motion_add(random(360), random_range(1, 3) + 1)
image_angle = direction
}
}
}
}
if place_meeting(x + hspeed, y + vspeed, hitme)
{
var _h = instance_nearest(x + hspeed, y + vspeed, hitme);
if !instance_is(_h, Player) && _h != creator && projectile_canhit_melee(_h)
{
var pass_hit = false
if("hook_hit" in self){
pass_hit = script_ref_call(hook_hit, _h, self);
}
if(!pass_hit){
var _d = "meleedamage" in creator ? creator.meleedamage * 2 : 5;
var _s = (ceil(superforce) + _h.size) + _d;
if(!disableeffects) {
sleep(_s / 3 * max(1, _h.size))
view_shake_at(x, y, _s / 3 * max(1, _h.size))
}
projectile_hit(_h,_s, superforce, direction);
projectile_hit(creator, round(superforce / 2), 0, direction);
//trace("enemy hit")
superforce *= .85 + .15 * min(skill_get(mut_impact_wrists), 1);
}
}
}
}
#define bullet_recycle(_baseChance,_return,_patron)
//Thanks Class!
//_baseChance is the chance for the bullet to be returned, the vanilla chance is 60 So it should be that.
//_return is the amount of bullets to return to the player.
//_patron is who to return the bullets to. by default this isn't creator if you use that for other things.
var _odds = _baseChance * skill_get(mut_recycle_gland)
if random(100) < _odds{
with _patron if instance_is(self, Player){
ammo[1] = min(ammo[1] + _return, typ_amax[1]) //return the ammo
}
sound_play(sndRecGlandProc)
if _return == 1{ //Use the default effect if theres only 1 bullet being returned
instance_create(x, y, RecycleGland)
}else{
repeat(_return){
name = "RecycleGlandCasing"
with instance_create(x,y,CustomObject){
direction = 90 - random_range(135,-135)
speed = random(0.8) + 0.8
sprite_index = sprBulletShell
spin = choose(5,-5,8,-8,3,-3)
lifetime = 15 + irandom_range(2,-2);
image_alpha = -1
z = 10 / 4; //This thing fucks with the z axis
z_velocity = 12 /4;
z_gravity = 1.1 /3;
on_step = RecycleFXStep
on_draw = RecycleFXDraw
}
}
}
}
#define RecycleFXStep
z = max(0,z + z_velocity * current_time_scale) //z position is capped at zero
z_velocity -= z_gravity * current_time_scale //I don't think I need to clamp, these don't go too fast
image_angle += spin //SPEEEEEEEEEEEEEN
lifetime -= current_time_scale
if lifetime == 0{ //Delete the fucker from existance when prompted
with instance_create(x,y-z,CaveSparkle){
sprite_index = global.sprRecycleShine
}
instance_destroy()
}
#define RecycleFXDraw
depth = lerp(-3 ,-7, min(4,z)/2) //Set depth
image_angle = point_direction(x,y,x+hspeed,y-z_velocity)
y -= z
draw_sprite_ext(sprite_index, image_index, x, y, image_xscale, image_yscale, image_angle, image_blend, 1); //actually draw the fucking sprite poggers
y += z
#define wep_raw(_wep)
/*
For use with LWO weapons
Call a weapon's "weapon_raw" script in case of wrapper weapons
Ex:
wep_raw({ wep:{ wep:{ wep:123 }}}) == 123
*/
var _raw = _wep;
// Find Base Weapon:
while(is_object(_raw)){
_raw = (("wep" in _raw) ? _raw.wep : wep_none);
}
// Wrapper:
if(is_string(_raw) && mod_script_exists("weapon", _raw, "weapon_raw")){
_raw = mod_script_call("weapon", _raw, "weapon_raw", _wep);
}
return _raw;
#define weapon_get(_name, _wep)
/*
Calls the given script from a weapon mod and fetches its return value
*/
var _raw = _wep;
// Find Base Weapon:
while(is_object(_raw) && "wep" in _raw){
_raw = _raw.wep;
}
// Call Script:
if(is_string(_raw)){
var _scrt = "weapon_" + _name;
if(mod_script_exists("weapon", _raw, _scrt)){
return mod_script_call_self("weapon", _raw, _scrt, _wep);
}
}
// Default:
switch(_name){
case "avail":
case "burst":
return 1;
case "loadout":
switch(_raw){
case wep_revolver : return sprRevolverLoadout;
case wep_golden_revolver : return sprGoldRevolverLoadout;
case wep_chicken_sword : return sprChickenSwordLoadout;
case wep_rogue_rifle : return sprRogueRifleLoadout;
case wep_rusty_revolver : return sprRustyRevolverLoadout;
case wep_golden_wrench : return sprGoldWrenchLoadout;
case wep_golden_machinegun : return sprGoldMachinegunLoadout;
case wep_golden_shotgun : return sprGoldShotgunLoadout;
case wep_golden_crossbow : return sprGoldCrossbowLoadout;
case wep_golden_grenade_launcher : return sprGoldGrenadeLauncherLoadout;
case wep_golden_laser_pistol : return sprGoldLaserPistolLoadout;
case wep_golden_screwdriver : return sprGoldScrewdriverLoadout;
case wep_golden_assault_rifle : return sprGoldAssaultRifleLoadout;
case wep_golden_slugger : return sprGoldSluggerLoadout;
case wep_golden_splinter_gun : return sprGoldSplintergunLoadout;
case wep_golden_bazooka : return sprGoldBazookaLoadout;
case wep_golden_plasma_gun : return sprGoldPlasmaGunLoadout;
case wep_golden_nuke_launcher : return sprGoldNukeLauncherLoadout;
case wep_golden_disc_gun : return sprGoldDiscgunLoadout;
case wep_golden_frog_pistol : return sprGoldToxicGunLoadout;
}
break;
case "raw":
return (is_object(_wep) ? wep_none : _wep);
}
return 0;
#define weapon_fire_init(_wep)
/*
Called from a 'weapon_fire' script to do some basic weapon firing setup
Returns a LWO with some useful variables
Vars:
wep - The weapon's value, may be modified from the given argument
creator - The actual instance firing, for 'player_fire_ext()' support
primary - The weapon is in the primary slot (true) or secondary slot (false)
wepheld - The weapon is physically stored in the creator's 'wep' variable
spec - The weapon is being shot by an active (YV, Steroids, Skeleton)
burst - The current burst shot (starts at 1)
*/
var _fire = {
"wep" : _wep,
"creator" : noone,
"primary" : true,
"wepheld" : false,
"spec" : false,
"burst" : 1
};
// Creator:
_fire.creator = self;
if(instance_is(self, FireCont) && "creator" in self){
_fire.creator = creator;
}
// Weapon Held by Creator:
_fire.wepheld = (variable_instance_get(_fire.creator, "wep") == _fire.wep);
// Active / Secondary Firing:
_fire.spec = variable_instance_get(self, "specfiring", false);
if(race == "steroids" && _fire.spec){
_fire.primary = false;
}
// LWO Setup:
var _lwo = mod_variable_get("weapon", wep_raw(_fire.wep), "lwoWep");
if(is_object(_lwo)){
if(!is_object(_fire.wep)){
_fire.wep = { "wep" : _fire.wep };
if(_fire.wepheld){
_fire.creator.wep = _fire.wep;
}
}
for(var i = lq_size(_lwo) - 1; i >= 0; i--){
var _key = lq_get_key(_lwo, i);
if(_key not in _fire.wep){
lq_set(_fire.wep, _key, lq_get_value(_lwo, i));
}
}
}
// Extra Systems:
var _other = other;
with(instance_exists(_fire.creator) ? _fire.creator : self){
// Normal Weapon:
{
// Melee:
if(weapon_is_melee(_fire.wep)){
other.wepangle *= -1;
}
}
}
return _fire;
#define weapon_ammo_fire(_wep)
/*
Called from a 'weapon_fire' script to process LWO weapons with internal ammo
Returns 'true' if the weapon had enough internal ammo to fire, 'false' otherwise
*/
// Gun Warrant:
if(infammo != 0){
return true;
}
// Ammo Cost:
var _cost = lq_defget(_wep, "cost", 1);
with(_wep) if(ammo >= _cost){
ammo -= _cost;
// Can Fire:
return true;
}
// Not Enough Ammo:
reload = variable_instance_get(self, "reloadspeed", 1) * current_time_scale;
if("anam" in _wep){
if(button_pressed(index, (specfiring ? "spec" : "fire"))){
wkick = -2;
sound_play(sndEmpty);
with(instance_create(x, y, PopupText)){
target = other.index;
text = ((_wep.ammo > 0) ? "NOT ENOUGH " + _wep.anam : "EMPTY");
}
}
}
return false;
#define weapon_ammo_hud(_wep)
/*
Called from a 'weapon_sprt_hud' script to draw HUD for LWO weapons with internal ammo
Returns the weapon's normal sprite for easy returning
Ex:
#define weapon_sprt_hud(w)
return weapon_ammo_hud(w);
*/
// Draw Ammo:
if(
instance_is(self, Player)
&& (instance_is(other, TopCont) || instance_is(other, UberCont))
&& is_object(_wep)
){
var _ammo = lq_defget(_wep, "ammo", 0),
_ammoMax = lq_defget(_wep, "amax", _ammo),
_ammoMin = lq_defget(_wep, "amin", round(_ammoMax * 0.2));
draw_ammo(index, (bwep != _wep), (race == "steroids"), _ammo, _ammoMin);
}
// Default Sprite:
return weapon_get_sprt(_wep);
#define draw_ammo(_index, _primary, _steroids, _ammo, _ammoMin)
/*
Draws ammo HUD text
Args:
index - The player to draw HUD for
primary - Is a primary weapon, true/false
steroids - Player can dual wield, true/false
ammo - Ammo, can be a string or number
ammoMin - Low ammo threshold
*/
var _local = player_find_local_nonsync();
if(player_is_active(_local) && player_get_show_hud(_index, _local)){
if(!instance_exists(menubutton) || _index == _local){
var _x = view_xview_nonsync + (_primary ? 42 : 86),
_y = view_yview_nonsync + 21;
// Co-op Offset:
var _active = 0;
for(var i = 0; i < maxp; i++){
_active += player_is_active(i);
}
if(_active > 1){
_x -= 19;
}
// Color:
var _text = "";
if(is_real(_ammo)){
_text += "@";
if(_ammo > 0){
if(_primary || _steroids){
if(_ammo > _ammoMin){
_text += "w";
}
else _text += "r";
}
else _text += "s";
}
else _text += "d";
}
_text += string(_ammo);
// !!!
draw_set_halign(fa_left);
draw_set_valign(fa_top);
draw_set_projection(2, _index);
draw_text_nt(_x, _y, _text);
draw_reset_projection();
}
}
#define spawn_shell(_angle, _spread, _speed, _sprite)
with instance_create(x, y, Shell){
motion_add(other.gunangle + (other.right * _angle) + random_range(-_spread, _spread), _speed);
sprite_index = _sprite;
}
#define draw_weapon_huge(sprt)
if instance_is(self,Player){
with(script_bind_draw(drawLargeWeapon, depth + 1)){
gunangle = other.gunangle;
wepangle = other.wepangle;
wkick = other.wkick;
wepflip = other.wepflip;
index = other.index;
right = other.right;
sprite_index = sprt;
creator = other;
if other.gunangle > 180{
depth = other.depth - 2;
}else depth = other.depth + 1;
}
return mskNone;
}
//look, fallback cases are important.
return sprt;
#define drawLargeWeapon
if !instance_exists(creator){
instance_destroy();
exit;
}
x = creator.x + creator.hspeed_raw;
y = creator.y + creator.vspeed_raw;
draw_set_visible_all(false);
draw_set_visible(index, true);
if player_get_outlines(index){
d3d_set_fog(true,player_get_color(index),1,1);
draw_sprite_ext(sprite_index,image_index, 1 + x + lengthdir_x(wkick,gunangle), y + lengthdir_y(wkick,gunangle), 1, wepflip, gunangle + wepangle, image_blend, image_alpha);
draw_sprite_ext(sprite_index,image_index, -1 + x + lengthdir_x(wkick,gunangle), y + lengthdir_y(wkick,gunangle), 1, wepflip, gunangle + wepangle, image_blend, image_alpha);
draw_sprite_ext(sprite_index,image_index, x + lengthdir_x(wkick,gunangle), 1 + y + lengthdir_y(wkick,gunangle), 1, wepflip, gunangle + wepangle, image_blend, image_alpha);
draw_sprite_ext(sprite_index,image_index, x + lengthdir_x(wkick,gunangle), -1 + y + lengthdir_y(wkick,gunangle), 1, wepflip, gunangle + wepangle, image_blend, image_alpha);
d3d_set_fog(false,player_get_color(index),1,1);
}
draw_sprite_ext(sprite_index,image_index, x + lengthdir_x(wkick,gunangle), y + lengthdir_y(wkick,gunangle), 1, wepflip, gunangle + wepangle, image_blend, image_alpha);
draw_set_visible_all(true);
instance_destroy();