1 #include "sv_instagib.qh"
3 int autocvar_g_instagib_ammo_drop;
4 bool autocvar_g_instagib_ammo_convert_cells;
5 bool autocvar_g_instagib_ammo_convert_rockets;
6 bool autocvar_g_instagib_ammo_convert_shells;
7 bool autocvar_g_instagib_ammo_convert_bullets;
8 int autocvar_g_instagib_extralives;
9 float autocvar_g_instagib_speed_highspeed;
11 #include <server/client.qh>
13 #include <common/items/_mod.qh>
15 REGISTER_MUTATOR(mutator_instagib, cvar("g_instagib") && !g_nexball);
17 spawnfunc(item_minst_cells)
19 if (!g_instagib) { delete(this); return; }
20 if (!this.ammo_cells) this.ammo_cells = autocvar_g_instagib_ammo_drop;
21 StartItem(this, ITEM_VaporizerCells);
24 void instagib_invisibility(entity this)
26 this.strength_finished = autocvar_g_balance_powerup_strength_time;
27 StartItem(this, ITEM_Invisibility);
30 void instagib_extralife(entity this)
32 StartItem(this, ITEM_ExtraLife);
35 void instagib_speed(entity this)
37 this.invincible_finished = autocvar_g_balance_powerup_invincible_time;
38 StartItem(this, ITEM_Speed);
41 .float instagib_nextthink;
42 .float instagib_needammo;
43 void instagib_stop_countdown(entity e)
45 if (!e.instagib_needammo)
47 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER, CPID_INSTAGIB_FINDAMMO);
48 e.instagib_needammo = false;
50 void instagib_ammocheck(entity this)
52 if(time < this.instagib_nextthink)
55 return; // not a player
57 if(IS_DEAD(this) || gameover)
58 instagib_stop_countdown(this);
59 else if (this.ammo_cells > 0 || (this.items & IT_UNLIMITED_WEAPON_AMMO) || (this.flags & FL_GODMODE))
60 instagib_stop_countdown(this);
61 else if(autocvar_g_rm && autocvar_g_rm_laser)
63 if(!this.instagib_needammo)
65 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_INSTAGIB_DOWNGRADE);
66 this.instagib_needammo = true;
71 this.instagib_needammo = true;
74 Damage(this, this, this, 5, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
75 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_INSTAGIB_TERMINATED);
77 else if (this.health <= 10)
79 Damage(this, this, this, 5, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
80 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_1);
82 else if (this.health <= 20)
84 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
85 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_2);
87 else if (this.health <= 30)
89 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
90 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_3);
92 else if (this.health <= 40)
94 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
95 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_4);
97 else if (this.health <= 50)
99 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
100 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_5);
102 else if (this.health <= 60)
104 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
105 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_6);
107 else if (this.health <= 70)
109 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
110 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_7);
112 else if (this.health <= 80)
114 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
115 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_8);
117 else if (this.health <= 90)
119 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_INSTAGIB_FINDAMMO);
120 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
121 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_9);
125 Send_Notification(NOTIF_ONE_ONLY, this, MSG_MULTI, MULTI_INSTAGIB_FINDAMMO);
126 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
129 this.instagib_nextthink = time + 1;
132 MUTATOR_HOOKFUNCTION(mutator_instagib, MatchEnd)
134 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(instagib_stop_countdown(it)));
137 MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterDropItem)
139 entity item = M_ARGV(1, entity);
141 item.monster_loot = spawnfunc_item_minst_cells;
144 MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterSpawn)
146 entity mon = M_ARGV(0, entity);
148 // always refill ammo
149 if(mon.monsterid == MON_MAGE.monsterid)
153 MUTATOR_HOOKFUNCTION(mutator_instagib, BotShouldAttack)
155 entity targ = M_ARGV(1, entity);
157 if (targ.items & ITEM_Invisibility.m_itemid)
161 MUTATOR_HOOKFUNCTION(mutator_instagib, MakePlayerObserver)
163 entity player = M_ARGV(0, entity);
165 instagib_stop_countdown(player);
168 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerSpawn)
170 entity player = M_ARGV(0, entity);
172 player.effects |= EF_FULLBRIGHT;
175 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPreThink)
177 entity player = M_ARGV(0, entity);
179 instagib_ammocheck(player);
182 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerRegen)
184 // no regeneration in instagib
188 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPowerups)
190 entity player = M_ARGV(0, entity);
192 if (!(player.effects & EF_FULLBRIGHT))
193 player.effects |= EF_FULLBRIGHT;
195 if (player.items & ITEM_Invisibility.m_itemid)
197 play_countdown(player, player.strength_finished, SND_POWEROFF);
198 if (time > player.strength_finished)
200 player.alpha = default_player_alpha;
201 player.exteriorweaponentity.alpha = default_weapon_alpha;
202 player.items &= ~ITEM_Invisibility.m_itemid;
203 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERDOWN_INVISIBILITY);
208 if (time < player.strength_finished)
210 player.alpha = autocvar_g_instagib_invis_alpha;
211 player.exteriorweaponentity.alpha = autocvar_g_instagib_invis_alpha;
212 player.items |= ITEM_Invisibility.m_itemid;
213 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_POWERUP_INVISIBILITY, player.netname);
214 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERUP_INVISIBILITY);
218 if (player.items & ITEM_Speed.m_itemid)
220 play_countdown(player, player.invincible_finished, SND_POWEROFF);
221 if (time > player.invincible_finished)
223 player.items &= ~ITEM_Speed.m_itemid;
224 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERDOWN_SPEED);
229 if (time < player.invincible_finished)
231 player.items |= ITEM_Speed.m_itemid;
232 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_POWERUP_SPEED, player.netname);
233 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERUP_SPEED);
238 .float stat_sv_maxspeed;
240 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPhysics)
242 entity player = M_ARGV(0, entity);
244 if(player.items & ITEM_Speed.m_itemid)
245 player.stat_sv_maxspeed = player.stat_sv_maxspeed * autocvar_g_instagib_speed_highspeed;
248 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDamage_SplitHealthArmor)
250 M_ARGV(4, float) = M_ARGV(7, float); // take = damage
251 M_ARGV(5, float) = 0; // save
254 MUTATOR_HOOKFUNCTION(mutator_instagib, ForbidThrowCurrentWeapon)
256 // weapon dropping on death handled by FilterItem
260 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDamage_Calculate)
262 entity frag_attacker = M_ARGV(1, entity);
263 entity frag_target = M_ARGV(2, entity);
264 float frag_deathtype = M_ARGV(3, float);
265 float frag_damage = M_ARGV(4, float);
266 float frag_mirrordamage = M_ARGV(5, float);
267 vector frag_force = M_ARGV(6, vector);
269 if(autocvar_g_friendlyfire == 0 && SAME_TEAM(frag_target, frag_attacker) && IS_PLAYER(frag_target) && IS_PLAYER(frag_attacker))
272 if(IS_PLAYER(frag_target))
274 if(frag_deathtype == DEATH_FALL.m_id)
275 frag_damage = 0; // never count fall damage
277 if(!autocvar_g_instagib_damagedbycontents)
278 switch(DEATH_ENT(frag_deathtype))
287 if(IS_PLAYER(frag_attacker))
288 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
290 if(!autocvar_g_instagib_friendlypush && SAME_TEAM(frag_target, frag_attacker))
291 frag_force = '0 0 0';
293 if(frag_target.armorvalue)
295 frag_target.armorvalue -= 1;
297 frag_target.damage_dealt += 1;
298 frag_attacker.damage_dealt += 1;
299 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, frag_target.armorvalue);
303 if(IS_PLAYER(frag_attacker) && DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
305 if(frag_deathtype & HITTYPE_SECONDARY)
307 if(!autocvar_g_instagib_blaster_keepdamage || frag_attacker == frag_target)
310 if(!autocvar_g_instagib_mirrordamage)
311 frag_mirrordamage = 0; // never do mirror damage on enemies
314 if(frag_target != frag_attacker)
316 if(frag_damage <= 0 && frag_target.health > 0) { Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE); }
317 if(!autocvar_g_instagib_blaster_keepforce)
318 frag_force = '0 0 0';
324 if(!autocvar_g_instagib_mirrordamage) // only apply the taking lives hack if we don't want to support real damage mirroring
325 if(IS_PLAYER(frag_attacker))
326 if(frag_mirrordamage > 0)
328 // just lose extra LIVES, don't kill the player for mirror damage
329 if(frag_attacker.armorvalue > 0)
331 frag_attacker.armorvalue -= 1;
332 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, frag_attacker.armorvalue);
333 frag_attacker.damage_dealt += frag_mirrordamage;
335 frag_mirrordamage = 0;
338 if(frag_target.alpha && frag_target.alpha < 1)
339 if(IS_PLAYER(frag_target))
342 M_ARGV(4, float) = frag_damage;
343 M_ARGV(5, float) = frag_mirrordamage;
344 M_ARGV(6, vector) = frag_force;
347 MUTATOR_HOOKFUNCTION(mutator_instagib, SetStartItems)
349 start_health = warmup_start_health = 100;
350 start_armorvalue = warmup_start_armorvalue = 0;
352 start_ammo_shells = warmup_start_ammo_shells = 0;
353 start_ammo_nails = warmup_start_ammo_nails = 0;
354 start_ammo_cells = warmup_start_ammo_cells = cvar("g_instagib_ammo_start");
355 start_ammo_plasma = warmup_start_ammo_plasma = 0;
356 start_ammo_rockets = warmup_start_ammo_rockets = 0;
357 start_ammo_fuel = warmup_start_ammo_fuel = 0;
359 start_weapons = warmup_start_weapons = WEPSET(VAPORIZER);
360 start_items |= IT_UNLIMITED_SUPERWEAPONS;
363 MUTATOR_HOOKFUNCTION(mutator_instagib, SetWeaponArena)
365 // turn weapon arena off
366 M_ARGV(0, string) = "off";
369 void replace_with_insta_cells(entity item)
372 setorigin(e, item.origin);
373 e.noalign = item.noalign;
376 e.spawnfunc_checked = true;
377 spawnfunc_item_minst_cells(e);
380 MUTATOR_HOOKFUNCTION(mutator_instagib, FilterItem)
382 entity item = M_ARGV(0, entity);
384 if(item.classname == "item_cells")
386 if(autocvar_g_instagib_ammo_convert_cells)
388 replace_with_insta_cells(item);
392 else if(item.classname == "item_rockets")
394 if(autocvar_g_instagib_ammo_convert_rockets)
396 replace_with_insta_cells(item);
400 else if(item.classname == "item_shells")
402 if(autocvar_g_instagib_ammo_convert_shells)
404 replace_with_insta_cells(item);
408 else if(item.classname == "item_bullets")
410 if(autocvar_g_instagib_ammo_convert_bullets)
412 replace_with_insta_cells(item);
417 if(item.weapon == WEP_VAPORIZER.m_id && item.classname == "droppedweapon")
419 item.ammo_cells = autocvar_g_instagib_ammo_drop;
423 if(item.weapon == WEP_DEVASTATOR.m_id || item.weapon == WEP_VORTEX.m_id)
425 replace_with_insta_cells(item);
429 if(item.flags & FL_POWERUP)
432 if(item.ammo_cells > autocvar_g_instagib_ammo_drop && item.classname != "item_minst_cells")
433 item.ammo_cells = autocvar_g_instagib_ammo_drop;
435 if(item.ammo_cells && !item.weapon)
441 MUTATOR_HOOKFUNCTION(mutator_instagib, CustomizeWaypoint)
443 entity wp = M_ARGV(0, entity);
444 entity player = M_ARGV(1, entity);
446 entity e = WaypointSprite_getviewentity(player);
448 // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
449 // but only apply this to real players, not to spectators
450 if((wp.owner.flags & FL_CLIENT) && (wp.owner.items & ITEM_Invisibility.m_itemid) && (e == player))
451 if(DIFF_TEAM(wp.owner, e))
455 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDies)
457 float frag_deathtype = M_ARGV(3, float);
459 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
460 M_ARGV(4, float) = 1000; // always gib if it was a vaporizer death
463 MUTATOR_HOOKFUNCTION(mutator_instagib, ItemTouch)
465 entity item = M_ARGV(0, entity);
466 entity toucher = M_ARGV(1, entity);
470 // play some cool sounds ;)
471 if (IS_CLIENT(toucher))
473 if(toucher.health <= 5)
474 Send_Notification(NOTIF_ONE, toucher, MSG_ANNCE, ANNCE_INSTAGIB_LASTSECOND);
475 else if(toucher.health < 50)
476 Send_Notification(NOTIF_ONE, toucher, MSG_ANNCE, ANNCE_INSTAGIB_NARROWLY);
479 if(toucher.health < 100)
480 toucher.health = 100;
482 return MUT_ITEMTOUCH_CONTINUE;
485 if(item.itemdef == ITEM_ExtraLife)
487 toucher.armorvalue = bound(toucher.armorvalue, 999, toucher.armorvalue + autocvar_g_instagib_extralives);
488 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_EXTRALIVES);
489 return MUT_ITEMTOUCH_PICKUP;
492 return MUT_ITEMTOUCH_CONTINUE;
495 MUTATOR_HOOKFUNCTION(mutator_instagib, OnEntityPreSpawn)
497 if (!autocvar_g_powerups) { return; }
498 entity ent = M_ARGV(0, entity);
499 // Can't use .itemdef here
500 if (!(ent.classname == "item_strength" || ent.classname == "item_invincible" || ent.classname == "item_health_mega"))
507 setthink(e, instagib_invisibility);
509 setthink(e, instagib_extralife);
511 setthink(e, instagib_speed);
513 e.nextthink = time + 0.1;
514 e.spawnflags = ent.spawnflags;
515 e.noalign = ent.noalign;
516 setorigin(e, ent.origin);
521 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsString)
523 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":instagib");
526 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsPrettyString)
528 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", instagib");
531 MUTATOR_HOOKFUNCTION(mutator_instagib, SetModname)
533 M_ARGV(0, string) = "InstaGib";