1 #include "sv_instagib.qh"
3 bool autocvar_g_instagib_damagedbycontents = true;
4 bool autocvar_g_instagib_blaster_keepdamage = false;
5 bool autocvar_g_instagib_blaster_keepforce = false;
6 bool autocvar_g_instagib_mirrordamage;
7 bool autocvar_g_instagib_friendlypush = true;
8 //int autocvar_g_instagib_ammo_drop;
9 bool autocvar_g_instagib_ammo_convert_cells;
10 bool autocvar_g_instagib_ammo_convert_rockets;
11 bool autocvar_g_instagib_ammo_convert_shells;
12 bool autocvar_g_instagib_ammo_convert_bullets;
13 int autocvar_g_instagib_extralives;
14 float autocvar_g_instagib_speed_highspeed;
16 #include <server/client.qh>
18 #include <common/items/_mod.qh>
20 REGISTER_MUTATOR(mutator_instagib, autocvar_g_instagib && !g_nexball)
24 ITEM_VaporizerCells.spawnflags &= ~ITEM_FLAG_MUTATORBLOCKED;
25 ITEM_Invisibility.spawnflags &= ~ITEM_FLAG_MUTATORBLOCKED;
26 ITEM_Speed.spawnflags &= ~ITEM_FLAG_MUTATORBLOCKED;
28 MUTATOR_ONROLLBACK_OR_REMOVE
30 ITEM_VaporizerCells.spawnflags |= ITEM_FLAG_MUTATORBLOCKED;
31 ITEM_Invisibility.spawnflags |= ITEM_FLAG_MUTATORBLOCKED;
32 ITEM_Speed.spawnflags |= ITEM_FLAG_MUTATORBLOCKED;
36 void instagib_invisibility(entity this)
38 this.strength_finished = autocvar_g_instagib_invisibility_time;
39 StartItem(this, ITEM_Invisibility);
42 void instagib_extralife(entity this)
44 StartItem(this, ITEM_ExtraLife);
47 void instagib_speed(entity this)
49 this.invincible_finished = autocvar_g_instagib_speed_time;
50 StartItem(this, ITEM_Speed);
53 .float instagib_nextthink;
54 .float instagib_needammo;
55 void instagib_stop_countdown(entity e)
57 if (!e.instagib_needammo)
59 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER, CPID_INSTAGIB_FINDAMMO);
60 e.instagib_needammo = false;
62 void instagib_ammocheck(entity this)
64 if(time < this.instagib_nextthink)
67 return; // not a player
69 if(IS_DEAD(this) || game_stopped)
70 instagib_stop_countdown(this);
71 else if (GetResourceAmount(this, RESOURCE_CELLS) > 0 || (this.items & IT_UNLIMITED_WEAPON_AMMO) || (this.flags & FL_GODMODE))
72 instagib_stop_countdown(this);
73 else if(autocvar_g_rm && autocvar_g_rm_laser)
75 if(!this.instagib_needammo)
77 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_INSTAGIB_DOWNGRADE);
78 this.instagib_needammo = true;
83 float hp = GetResourceAmount(this, RESOURCE_HEALTH);
84 this.instagib_needammo = true;
87 Damage(this, this, this, 5, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
88 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_INSTAGIB_TERMINATED);
92 Damage(this, this, this, 5, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
93 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_1);
97 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
98 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_2);
102 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
103 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_3);
107 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
108 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_4);
112 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
113 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_5);
117 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
118 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_6);
122 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
123 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_7);
127 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
128 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_8);
132 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_INSTAGIB_FINDAMMO);
133 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
134 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_9);
138 Send_Notification(NOTIF_ONE_ONLY, this, MSG_MULTI, MULTI_INSTAGIB_FINDAMMO);
139 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
142 this.instagib_nextthink = time + 1;
145 MUTATOR_HOOKFUNCTION(mutator_instagib, MatchEnd)
147 FOREACH_CLIENT(IS_PLAYER(it), { instagib_stop_countdown(it); });
150 MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterDropItem)
152 entity item = M_ARGV(1, entity);
154 item.monster_loot = ITEM_VaporizerCells;
157 MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterSpawn)
159 entity mon = M_ARGV(0, entity);
161 // always refill ammo
162 if(mon.monsterid == MON_MAGE.monsterid)
166 MUTATOR_HOOKFUNCTION(mutator_instagib, BotShouldAttack)
168 entity targ = M_ARGV(1, entity);
170 if (targ.items & ITEM_Invisibility.m_itemid)
174 MUTATOR_HOOKFUNCTION(mutator_instagib, MakePlayerObserver)
176 entity player = M_ARGV(0, entity);
178 instagib_stop_countdown(player);
181 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerSpawn)
183 entity player = M_ARGV(0, entity);
185 player.effects |= EF_FULLBRIGHT;
188 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPreThink)
190 entity player = M_ARGV(0, entity);
192 instagib_ammocheck(player);
195 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerRegen)
197 // no regeneration in instagib
201 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPowerups)
203 entity player = M_ARGV(0, entity);
205 if (!(player.effects & EF_FULLBRIGHT))
206 player.effects |= EF_FULLBRIGHT;
208 if (player.items & ITEM_Invisibility.m_itemid)
210 play_countdown(player, player.strength_finished, SND_POWEROFF);
211 if (time > player.strength_finished)
213 player.alpha = default_player_alpha;
214 player.exteriorweaponentity.alpha = default_weapon_alpha;
215 player.items &= ~ITEM_Invisibility.m_itemid;
216 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERDOWN_INVISIBILITY);
221 if (time < player.strength_finished)
223 player.alpha = autocvar_g_instagib_invis_alpha;
224 player.exteriorweaponentity.alpha = autocvar_g_instagib_invis_alpha;
225 player.items |= ITEM_Invisibility.m_itemid;
226 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_POWERUP_INVISIBILITY, player.netname);
227 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERUP_INVISIBILITY);
231 if (player.items & ITEM_Speed.m_itemid)
233 play_countdown(player, player.invincible_finished, SND_POWEROFF);
234 if (time > player.invincible_finished)
236 player.items &= ~ITEM_Speed.m_itemid;
237 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERDOWN_SPEED);
242 if (time < player.invincible_finished)
244 player.items |= ITEM_Speed.m_itemid;
245 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_POWERUP_SPEED, player.netname);
246 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERUP_SPEED);
251 .float stat_sv_maxspeed;
253 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPhysics)
255 entity player = M_ARGV(0, entity);
257 if(player.items & ITEM_Speed.m_itemid)
258 player.stat_sv_maxspeed = player.stat_sv_maxspeed * autocvar_g_instagib_speed_highspeed;
261 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDamage_SplitHealthArmor)
263 M_ARGV(4, float) = M_ARGV(7, float); // take = damage
264 M_ARGV(5, float) = 0; // save
267 MUTATOR_HOOKFUNCTION(mutator_instagib, ForbidThrowCurrentWeapon)
269 // weapon dropping on death handled by FilterItem
273 MUTATOR_HOOKFUNCTION(mutator_instagib, Damage_Calculate)
275 entity frag_attacker = M_ARGV(1, entity);
276 entity frag_target = M_ARGV(2, entity);
277 float frag_deathtype = M_ARGV(3, float);
278 float frag_damage = M_ARGV(4, float);
279 float frag_mirrordamage = M_ARGV(5, float);
280 vector frag_force = M_ARGV(6, vector);
282 if(autocvar_g_friendlyfire == 0 && SAME_TEAM(frag_target, frag_attacker) && IS_PLAYER(frag_target) && IS_PLAYER(frag_attacker))
285 if(IS_PLAYER(frag_target))
287 if(frag_deathtype == DEATH_FALL.m_id)
288 frag_damage = 0; // never count fall damage
290 if(!autocvar_g_instagib_damagedbycontents)
291 switch(DEATH_ENT(frag_deathtype))
300 if(IS_PLAYER(frag_attacker))
301 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
303 if(!autocvar_g_instagib_friendlypush && SAME_TEAM(frag_target, frag_attacker))
304 frag_force = '0 0 0';
306 float armor = GetResourceAmount(frag_target, RESOURCE_ARMOR);
310 SetResourceAmount(frag_target, RESOURCE_ARMOR, armor);
312 frag_target.damage_dealt += 1;
313 frag_attacker.damage_dealt += 1;
314 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, armor);
318 if(IS_PLAYER(frag_attacker) && DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
320 if(frag_deathtype & HITTYPE_SECONDARY)
322 if(!autocvar_g_instagib_blaster_keepdamage || frag_attacker == frag_target)
325 if(!autocvar_g_instagib_mirrordamage)
326 frag_mirrordamage = 0; // never do mirror damage on enemies
329 if(frag_target != frag_attacker)
331 if(frag_damage <= 0 && GetResourceAmount(frag_target, RESOURCE_HEALTH) > 0) { Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE); }
332 if(!autocvar_g_instagib_blaster_keepforce)
333 frag_force = '0 0 0';
339 if(!autocvar_g_instagib_mirrordamage) // only apply the taking lives hack if we don't want to support real damage mirroring
340 if(IS_PLAYER(frag_attacker))
341 if(frag_mirrordamage > 0)
343 // just lose extra LIVES, don't kill the player for mirror damage
344 float armor = GetResourceAmount(frag_attacker, RESOURCE_ARMOR);
348 SetResourceAmount(frag_attacker, RESOURCE_ARMOR, armor);
349 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, armor);
350 frag_attacker.damage_dealt += frag_mirrordamage;
352 frag_mirrordamage = 0;
355 if(frag_target.alpha && frag_target.alpha < 1)
356 if(IS_PLAYER(frag_target))
359 M_ARGV(4, float) = frag_damage;
360 M_ARGV(5, float) = frag_mirrordamage;
361 M_ARGV(6, vector) = frag_force;
364 MUTATOR_HOOKFUNCTION(mutator_instagib, SetStartItems)
366 start_health = warmup_start_health = 100;
367 start_armorvalue = warmup_start_armorvalue = 0;
369 start_ammo_shells = warmup_start_ammo_shells = 0;
370 start_ammo_nails = warmup_start_ammo_nails = 0;
371 start_ammo_cells = warmup_start_ammo_cells = cvar("g_instagib_ammo_start");
372 start_ammo_plasma = warmup_start_ammo_plasma = 0;
373 start_ammo_rockets = warmup_start_ammo_rockets = 0;
374 //start_ammo_fuel = warmup_start_ammo_fuel = 0;
376 start_weapons = warmup_start_weapons = WEPSET(VAPORIZER);
377 start_items |= IT_UNLIMITED_SUPERWEAPONS;
380 MUTATOR_HOOKFUNCTION(mutator_instagib, SetWeaponArena)
382 // turn weapon arena off
383 M_ARGV(0, string) = "off";
386 void replace_with_insta_cells(entity item)
388 entity e = new(item_vaporizer_cells);
389 setorigin(e, item.origin);
390 e.noalign = item.noalign;
393 e.spawnfunc_checked = true;
394 spawnfunc_item_vaporizer_cells(e);
397 MUTATOR_HOOKFUNCTION(mutator_instagib, FilterItem)
399 entity item = M_ARGV(0, entity);
401 if(item.classname == "item_cells")
403 if(autocvar_g_instagib_ammo_convert_cells)
405 replace_with_insta_cells(item);
409 else if(item.classname == "item_rockets")
411 if(autocvar_g_instagib_ammo_convert_rockets)
413 replace_with_insta_cells(item);
417 else if(item.classname == "item_shells")
419 if(autocvar_g_instagib_ammo_convert_shells)
421 replace_with_insta_cells(item);
425 else if(item.classname == "item_bullets")
427 if(autocvar_g_instagib_ammo_convert_bullets)
429 replace_with_insta_cells(item);
434 if(item.weapon == WEP_VAPORIZER.m_id && Item_IsLoot(item))
436 SetResourceAmount(item, RESOURCE_CELLS, autocvar_g_instagib_ammo_drop);
440 if(item.weapon == WEP_DEVASTATOR.m_id || item.weapon == WEP_VORTEX.m_id)
442 replace_with_insta_cells(item);
446 if(item.flags & FL_POWERUP)
449 float cells = GetResourceAmount(item, RESOURCE_CELLS);
450 if(cells > autocvar_g_instagib_ammo_drop && item.classname != "item_vaporizer_cells")
451 SetResourceAmount(item, RESOURCE_CELLS, autocvar_g_instagib_ammo_drop);
453 if(cells && !item.weapon)
459 MUTATOR_HOOKFUNCTION(mutator_instagib, CustomizeWaypoint)
461 entity wp = M_ARGV(0, entity);
462 entity player = M_ARGV(1, entity);
464 entity e = WaypointSprite_getviewentity(player);
466 // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
467 // but only apply this to real players, not to spectators
468 if((wp.owner.flags & FL_CLIENT) && (wp.owner.items & ITEM_Invisibility.m_itemid) && (e == player))
469 if(DIFF_TEAM(wp.owner, e))
473 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDies)
475 float frag_deathtype = M_ARGV(3, float);
477 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
478 M_ARGV(4, float) = 1000; // always gib if it was a vaporizer death
481 MUTATOR_HOOKFUNCTION(mutator_instagib, ItemTouch)
483 entity item = M_ARGV(0, entity);
484 entity toucher = M_ARGV(1, entity);
486 if(GetResourceAmount(item, RESOURCE_CELLS))
488 // play some cool sounds ;)
489 float hp = GetResourceAmount(toucher, RESOURCE_HEALTH);
490 if (IS_CLIENT(toucher))
493 Send_Notification(NOTIF_ONE, toucher, MSG_ANNCE, ANNCE_INSTAGIB_LASTSECOND);
495 Send_Notification(NOTIF_ONE, toucher, MSG_ANNCE, ANNCE_INSTAGIB_NARROWLY);
499 SetResourceAmount(toucher, RESOURCE_HEALTH, 100);
501 return MUT_ITEMTOUCH_CONTINUE;
504 if(item.itemdef == ITEM_ExtraLife)
506 GiveResource(toucher, RESOURCE_ARMOR, autocvar_g_instagib_extralives);
507 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_EXTRALIVES);
508 return MUT_ITEMTOUCH_PICKUP;
511 return MUT_ITEMTOUCH_CONTINUE;
514 MUTATOR_HOOKFUNCTION(mutator_instagib, OnEntityPreSpawn)
516 if (!autocvar_g_powerups) { return; }
517 entity ent = M_ARGV(0, entity);
518 // Can't use .itemdef here
519 if (!(ent.classname == "item_strength" || ent.classname == "item_shield" || ent.classname == "item_health_mega"))
527 e.classname = "item_invisibility";
528 setthink(e, instagib_invisibility);
532 e.classname = "item_extralife";
533 setthink(e, instagib_extralife);
537 e.classname = "item_speed";
538 setthink(e, instagib_speed);
541 e.nextthink = time + 0.1;
542 e.spawnflags = ent.spawnflags;
543 e.noalign = ent.noalign;
544 setorigin(e, ent.origin);
549 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsString)
551 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":instagib");
554 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsPrettyString)
556 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", instagib");
559 MUTATOR_HOOKFUNCTION(mutator_instagib, SetModname)
561 M_ARGV(0, string) = "InstaGib";