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 StartItem(this, ITEM_VaporizerCells);
23 void instagib_invisibility(entity this)
25 this.strength_finished = autocvar_g_balance_powerup_strength_time;
26 StartItem(this, ITEM_Invisibility);
29 void instagib_extralife(entity this)
31 StartItem(this, ITEM_ExtraLife);
34 void instagib_speed(entity this)
36 this.invincible_finished = autocvar_g_balance_powerup_invincible_time;
37 StartItem(this, ITEM_Speed);
40 .float instagib_nextthink;
41 .float instagib_needammo;
42 void instagib_stop_countdown(entity e)
44 if (!e.instagib_needammo)
46 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER, CPID_INSTAGIB_FINDAMMO);
47 e.instagib_needammo = false;
49 void instagib_ammocheck(entity this)
51 if(time < this.instagib_nextthink)
54 return; // not a player
56 if(IS_DEAD(this) || game_stopped)
57 instagib_stop_countdown(this);
58 else if (this.ammo_cells > 0 || (this.items & IT_UNLIMITED_WEAPON_AMMO) || (this.flags & FL_GODMODE))
59 instagib_stop_countdown(this);
60 else if(autocvar_g_rm && autocvar_g_rm_laser)
62 if(!this.instagib_needammo)
64 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_INSTAGIB_DOWNGRADE);
65 this.instagib_needammo = true;
70 this.instagib_needammo = true;
73 Damage(this, this, this, 5, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
74 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_INSTAGIB_TERMINATED);
76 else if (this.health <= 10)
78 Damage(this, this, this, 5, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
79 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_1);
81 else if (this.health <= 20)
83 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
84 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_2);
86 else if (this.health <= 30)
88 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
89 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_3);
91 else if (this.health <= 40)
93 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
94 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_4);
96 else if (this.health <= 50)
98 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
99 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_5);
101 else if (this.health <= 60)
103 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
104 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_6);
106 else if (this.health <= 70)
108 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
109 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_7);
111 else if (this.health <= 80)
113 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
114 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_8);
116 else if (this.health <= 90)
118 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_INSTAGIB_FINDAMMO);
119 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
120 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_9);
124 Send_Notification(NOTIF_ONE_ONLY, this, MSG_MULTI, MULTI_INSTAGIB_FINDAMMO);
125 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
128 this.instagib_nextthink = time + 1;
131 MUTATOR_HOOKFUNCTION(mutator_instagib, MatchEnd)
133 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(instagib_stop_countdown(it)));
136 MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterDropItem)
138 entity item = M_ARGV(1, entity);
140 item.monster_loot = ITEM_VaporizerCells;
143 MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterSpawn)
145 entity mon = M_ARGV(0, entity);
147 // always refill ammo
148 if(mon.monsterid == MON_MAGE.monsterid)
152 MUTATOR_HOOKFUNCTION(mutator_instagib, BotShouldAttack)
154 entity targ = M_ARGV(1, entity);
156 if (targ.items & ITEM_Invisibility.m_itemid)
160 MUTATOR_HOOKFUNCTION(mutator_instagib, MakePlayerObserver)
162 entity player = M_ARGV(0, entity);
164 instagib_stop_countdown(player);
167 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerSpawn)
169 entity player = M_ARGV(0, entity);
171 player.effects |= EF_FULLBRIGHT;
174 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPreThink)
176 entity player = M_ARGV(0, entity);
178 instagib_ammocheck(player);
181 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerRegen)
183 // no regeneration in instagib
187 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPowerups)
189 entity player = M_ARGV(0, entity);
191 if (!(player.effects & EF_FULLBRIGHT))
192 player.effects |= EF_FULLBRIGHT;
194 if (player.items & ITEM_Invisibility.m_itemid)
196 play_countdown(player, player.strength_finished, SND_POWEROFF);
197 if (time > player.strength_finished)
199 player.alpha = default_player_alpha;
200 player.exteriorweaponentity.alpha = default_weapon_alpha;
201 player.items &= ~ITEM_Invisibility.m_itemid;
202 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERDOWN_INVISIBILITY);
207 if (time < player.strength_finished)
209 player.alpha = autocvar_g_instagib_invis_alpha;
210 player.exteriorweaponentity.alpha = autocvar_g_instagib_invis_alpha;
211 player.items |= ITEM_Invisibility.m_itemid;
212 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_POWERUP_INVISIBILITY, player.netname);
213 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERUP_INVISIBILITY);
217 if (player.items & ITEM_Speed.m_itemid)
219 play_countdown(player, player.invincible_finished, SND_POWEROFF);
220 if (time > player.invincible_finished)
222 player.items &= ~ITEM_Speed.m_itemid;
223 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERDOWN_SPEED);
228 if (time < player.invincible_finished)
230 player.items |= ITEM_Speed.m_itemid;
231 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_POWERUP_SPEED, player.netname);
232 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERUP_SPEED);
237 .float stat_sv_maxspeed;
239 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPhysics)
241 entity player = M_ARGV(0, entity);
243 if(player.items & ITEM_Speed.m_itemid)
244 player.stat_sv_maxspeed = player.stat_sv_maxspeed * autocvar_g_instagib_speed_highspeed;
247 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDamage_SplitHealthArmor)
249 M_ARGV(4, float) = M_ARGV(7, float); // take = damage
250 M_ARGV(5, float) = 0; // save
253 MUTATOR_HOOKFUNCTION(mutator_instagib, ForbidThrowCurrentWeapon)
255 // weapon dropping on death handled by FilterItem
259 MUTATOR_HOOKFUNCTION(mutator_instagib, Damage_Calculate)
261 entity frag_attacker = M_ARGV(1, entity);
262 entity frag_target = M_ARGV(2, entity);
263 float frag_deathtype = M_ARGV(3, float);
264 float frag_damage = M_ARGV(4, float);
265 float frag_mirrordamage = M_ARGV(5, float);
266 vector frag_force = M_ARGV(6, vector);
268 if(autocvar_g_friendlyfire == 0 && SAME_TEAM(frag_target, frag_attacker) && IS_PLAYER(frag_target) && IS_PLAYER(frag_attacker))
271 if(IS_PLAYER(frag_target))
273 if(frag_deathtype == DEATH_FALL.m_id)
274 frag_damage = 0; // never count fall damage
276 if(!autocvar_g_instagib_damagedbycontents)
277 switch(DEATH_ENT(frag_deathtype))
286 if(IS_PLAYER(frag_attacker))
287 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
289 if(!autocvar_g_instagib_friendlypush && SAME_TEAM(frag_target, frag_attacker))
290 frag_force = '0 0 0';
292 if(frag_target.armorvalue)
294 frag_target.armorvalue -= 1;
296 frag_target.damage_dealt += 1;
297 frag_attacker.damage_dealt += 1;
298 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, frag_target.armorvalue);
302 if(IS_PLAYER(frag_attacker) && DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
304 if(frag_deathtype & HITTYPE_SECONDARY)
306 if(!autocvar_g_instagib_blaster_keepdamage || frag_attacker == frag_target)
309 if(!autocvar_g_instagib_mirrordamage)
310 frag_mirrordamage = 0; // never do mirror damage on enemies
313 if(frag_target != frag_attacker)
315 if(frag_damage <= 0 && frag_target.health > 0) { Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE); }
316 if(!autocvar_g_instagib_blaster_keepforce)
317 frag_force = '0 0 0';
323 if(!autocvar_g_instagib_mirrordamage) // only apply the taking lives hack if we don't want to support real damage mirroring
324 if(IS_PLAYER(frag_attacker))
325 if(frag_mirrordamage > 0)
327 // just lose extra LIVES, don't kill the player for mirror damage
328 if(frag_attacker.armorvalue > 0)
330 frag_attacker.armorvalue -= 1;
331 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, frag_attacker.armorvalue);
332 frag_attacker.damage_dealt += frag_mirrordamage;
334 frag_mirrordamage = 0;
337 if(frag_target.alpha && frag_target.alpha < 1)
338 if(IS_PLAYER(frag_target))
341 M_ARGV(4, float) = frag_damage;
342 M_ARGV(5, float) = frag_mirrordamage;
343 M_ARGV(6, vector) = frag_force;
346 MUTATOR_HOOKFUNCTION(mutator_instagib, SetStartItems)
348 start_health = warmup_start_health = 100;
349 start_armorvalue = warmup_start_armorvalue = 0;
351 start_ammo_shells = warmup_start_ammo_shells = 0;
352 start_ammo_nails = warmup_start_ammo_nails = 0;
353 start_ammo_cells = warmup_start_ammo_cells = cvar("g_instagib_ammo_start");
354 start_ammo_plasma = warmup_start_ammo_plasma = 0;
355 start_ammo_rockets = warmup_start_ammo_rockets = 0;
356 //start_ammo_fuel = warmup_start_ammo_fuel = 0;
358 start_weapons = warmup_start_weapons = WEPSET(VAPORIZER);
359 start_items |= IT_UNLIMITED_SUPERWEAPONS;
362 MUTATOR_HOOKFUNCTION(mutator_instagib, SetWeaponArena)
364 // turn weapon arena off
365 M_ARGV(0, string) = "off";
368 void replace_with_insta_cells(entity item)
371 setorigin(e, item.origin);
372 e.noalign = item.noalign;
375 e.spawnfunc_checked = true;
376 spawnfunc_item_minst_cells(e);
379 MUTATOR_HOOKFUNCTION(mutator_instagib, FilterItem)
381 entity item = M_ARGV(0, entity);
383 if(item.classname == "item_cells")
385 if(autocvar_g_instagib_ammo_convert_cells)
387 replace_with_insta_cells(item);
391 else if(item.classname == "item_rockets")
393 if(autocvar_g_instagib_ammo_convert_rockets)
395 replace_with_insta_cells(item);
399 else if(item.classname == "item_shells")
401 if(autocvar_g_instagib_ammo_convert_shells)
403 replace_with_insta_cells(item);
407 else if(item.classname == "item_bullets")
409 if(autocvar_g_instagib_ammo_convert_bullets)
411 replace_with_insta_cells(item);
416 if(item.weapon == WEP_VAPORIZER.m_id && item.classname == "droppedweapon")
418 item.ammo_cells = autocvar_g_instagib_ammo_drop;
422 if(item.weapon == WEP_DEVASTATOR.m_id || item.weapon == WEP_VORTEX.m_id)
424 replace_with_insta_cells(item);
428 if(item.flags & FL_POWERUP)
431 if(item.ammo_cells > autocvar_g_instagib_ammo_drop && item.classname != "item_minst_cells")
432 item.ammo_cells = autocvar_g_instagib_ammo_drop;
434 if(item.ammo_cells && !item.weapon)
440 MUTATOR_HOOKFUNCTION(mutator_instagib, CustomizeWaypoint)
442 entity wp = M_ARGV(0, entity);
443 entity player = M_ARGV(1, entity);
445 entity e = WaypointSprite_getviewentity(player);
447 // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
448 // but only apply this to real players, not to spectators
449 if((wp.owner.flags & FL_CLIENT) && (wp.owner.items & ITEM_Invisibility.m_itemid) && (e == player))
450 if(DIFF_TEAM(wp.owner, e))
454 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDies)
456 float frag_deathtype = M_ARGV(3, float);
458 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
459 M_ARGV(4, float) = 1000; // always gib if it was a vaporizer death
462 MUTATOR_HOOKFUNCTION(mutator_instagib, ItemTouch)
464 entity item = M_ARGV(0, entity);
465 entity toucher = M_ARGV(1, entity);
469 // play some cool sounds ;)
470 if (IS_CLIENT(toucher))
472 if(toucher.health <= 5)
473 Send_Notification(NOTIF_ONE, toucher, MSG_ANNCE, ANNCE_INSTAGIB_LASTSECOND);
474 else if(toucher.health < 50)
475 Send_Notification(NOTIF_ONE, toucher, MSG_ANNCE, ANNCE_INSTAGIB_NARROWLY);
478 if(toucher.health < 100)
479 toucher.health = 100;
481 return MUT_ITEMTOUCH_CONTINUE;
484 if(item.itemdef == ITEM_ExtraLife)
486 toucher.armorvalue = bound(toucher.armorvalue, 999, toucher.armorvalue + autocvar_g_instagib_extralives);
487 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_EXTRALIVES);
488 return MUT_ITEMTOUCH_PICKUP;
491 return MUT_ITEMTOUCH_CONTINUE;
494 MUTATOR_HOOKFUNCTION(mutator_instagib, OnEntityPreSpawn)
496 if (!autocvar_g_powerups) { return; }
497 entity ent = M_ARGV(0, entity);
498 // Can't use .itemdef here
499 if (!(ent.classname == "item_strength" || ent.classname == "item_invincible" || ent.classname == "item_health_mega"))
506 setthink(e, instagib_invisibility);
508 setthink(e, instagib_extralife);
510 setthink(e, instagib_speed);
512 e.nextthink = time + 0.1;
513 e.spawnflags = ent.spawnflags;
514 e.noalign = ent.noalign;
515 setorigin(e, ent.origin);
520 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsString)
522 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":instagib");
525 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsPrettyString)
527 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", instagib");
530 MUTATOR_HOOKFUNCTION(mutator_instagib, SetModname)
532 M_ARGV(0, string) = "InstaGib";