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;
26 MUTATOR_ONROLLBACK_OR_REMOVE
28 ITEM_VaporizerCells.spawnflags |= ITEM_FLAG_MUTATORBLOCKED;
32 void instagib_invisibility(entity this)
34 this.strength_finished = autocvar_g_balance_powerup_strength_time;
35 StartItem(this, ITEM_Invisibility);
38 void instagib_extralife(entity this)
40 StartItem(this, ITEM_ExtraLife);
43 void instagib_speed(entity this)
45 this.invincible_finished = autocvar_g_balance_powerup_invincible_time;
46 StartItem(this, ITEM_Speed);
49 .float instagib_nextthink;
50 .float instagib_needammo;
51 void instagib_stop_countdown(entity e)
53 if (!e.instagib_needammo)
55 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER, CPID_INSTAGIB_FINDAMMO);
56 e.instagib_needammo = false;
58 void instagib_ammocheck(entity this)
60 if(time < this.instagib_nextthink)
63 return; // not a player
65 if(IS_DEAD(this) || game_stopped)
66 instagib_stop_countdown(this);
67 else if (GetResourceAmount(this, RESOURCE_CELLS) > 0 || (this.items & IT_UNLIMITED_WEAPON_AMMO) || (this.flags & FL_GODMODE))
68 instagib_stop_countdown(this);
69 else if(autocvar_g_rm && autocvar_g_rm_laser)
71 if(!this.instagib_needammo)
73 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_INSTAGIB_DOWNGRADE);
74 this.instagib_needammo = true;
79 float hp = GetResourceAmount(this, RESOURCE_HEALTH);
80 this.instagib_needammo = true;
83 Damage(this, this, this, 5, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
84 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_INSTAGIB_TERMINATED);
88 Damage(this, this, this, 5, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
89 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_1);
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_2);
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_3);
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_4);
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_5);
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_6);
118 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
119 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_7);
123 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
124 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_8);
128 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_INSTAGIB_FINDAMMO);
129 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
130 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_9);
134 Send_Notification(NOTIF_ONE_ONLY, this, MSG_MULTI, MULTI_INSTAGIB_FINDAMMO);
135 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
138 this.instagib_nextthink = time + 1;
141 MUTATOR_HOOKFUNCTION(mutator_instagib, MatchEnd)
143 FOREACH_CLIENT(IS_PLAYER(it), { instagib_stop_countdown(it); });
146 MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterDropItem)
148 entity item = M_ARGV(1, entity);
150 item.monster_loot = ITEM_VaporizerCells;
153 MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterSpawn)
155 entity mon = M_ARGV(0, entity);
157 // always refill ammo
158 if(mon.monsterid == MON_MAGE.monsterid)
162 MUTATOR_HOOKFUNCTION(mutator_instagib, BotShouldAttack)
164 entity targ = M_ARGV(1, entity);
166 if (targ.items & ITEM_Invisibility.m_itemid)
170 MUTATOR_HOOKFUNCTION(mutator_instagib, MakePlayerObserver)
172 entity player = M_ARGV(0, entity);
174 instagib_stop_countdown(player);
177 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerSpawn)
179 entity player = M_ARGV(0, entity);
181 player.effects |= EF_FULLBRIGHT;
184 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPreThink)
186 entity player = M_ARGV(0, entity);
188 instagib_ammocheck(player);
191 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerRegen)
193 // no regeneration in instagib
197 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPowerups)
199 entity player = M_ARGV(0, entity);
201 if (!(player.effects & EF_FULLBRIGHT))
202 player.effects |= EF_FULLBRIGHT;
204 if (player.items & ITEM_Invisibility.m_itemid)
206 play_countdown(player, player.strength_finished, SND_POWEROFF);
207 if (time > player.strength_finished)
209 player.alpha = default_player_alpha;
210 player.exteriorweaponentity.alpha = default_weapon_alpha;
211 player.items &= ~ITEM_Invisibility.m_itemid;
212 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERDOWN_INVISIBILITY);
217 if (time < player.strength_finished)
219 player.alpha = autocvar_g_instagib_invis_alpha;
220 player.exteriorweaponentity.alpha = autocvar_g_instagib_invis_alpha;
221 player.items |= ITEM_Invisibility.m_itemid;
222 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_POWERUP_INVISIBILITY, player.netname);
223 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERUP_INVISIBILITY);
227 if (player.items & ITEM_Speed.m_itemid)
229 play_countdown(player, player.invincible_finished, SND_POWEROFF);
230 if (time > player.invincible_finished)
232 player.items &= ~ITEM_Speed.m_itemid;
233 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERDOWN_SPEED);
238 if (time < player.invincible_finished)
240 player.items |= ITEM_Speed.m_itemid;
241 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_POWERUP_SPEED, player.netname);
242 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERUP_SPEED);
247 .float stat_sv_maxspeed;
249 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPhysics)
251 entity player = M_ARGV(0, entity);
253 if(player.items & ITEM_Speed.m_itemid)
254 player.stat_sv_maxspeed = player.stat_sv_maxspeed * autocvar_g_instagib_speed_highspeed;
257 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDamage_SplitHealthArmor)
259 M_ARGV(4, float) = M_ARGV(7, float); // take = damage
260 M_ARGV(5, float) = 0; // save
263 MUTATOR_HOOKFUNCTION(mutator_instagib, ForbidThrowCurrentWeapon)
265 // weapon dropping on death handled by FilterItem
269 MUTATOR_HOOKFUNCTION(mutator_instagib, Damage_Calculate)
271 entity frag_attacker = M_ARGV(1, entity);
272 entity frag_target = M_ARGV(2, entity);
273 float frag_deathtype = M_ARGV(3, float);
274 float frag_damage = M_ARGV(4, float);
275 float frag_mirrordamage = M_ARGV(5, float);
276 vector frag_force = M_ARGV(6, vector);
278 if(autocvar_g_friendlyfire == 0 && SAME_TEAM(frag_target, frag_attacker) && IS_PLAYER(frag_target) && IS_PLAYER(frag_attacker))
281 if(IS_PLAYER(frag_target))
283 if(frag_deathtype == DEATH_FALL.m_id)
284 frag_damage = 0; // never count fall damage
286 if(!autocvar_g_instagib_damagedbycontents)
287 switch(DEATH_ENT(frag_deathtype))
296 if(IS_PLAYER(frag_attacker))
297 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
299 if(!autocvar_g_instagib_friendlypush && SAME_TEAM(frag_target, frag_attacker))
300 frag_force = '0 0 0';
302 float armor = GetResourceAmount(frag_target, RESOURCE_ARMOR);
306 SetResourceAmount(frag_target, RESOURCE_ARMOR, armor);
308 frag_target.damage_dealt += 1;
309 frag_attacker.damage_dealt += 1;
310 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, armor);
314 if(IS_PLAYER(frag_attacker) && DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
316 if(frag_deathtype & HITTYPE_SECONDARY)
318 if(!autocvar_g_instagib_blaster_keepdamage || frag_attacker == frag_target)
321 if(!autocvar_g_instagib_mirrordamage)
322 frag_mirrordamage = 0; // never do mirror damage on enemies
325 if(frag_target != frag_attacker)
327 if(frag_damage <= 0 && GetResourceAmount(frag_target, RESOURCE_HEALTH) > 0) { Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE); }
328 if(!autocvar_g_instagib_blaster_keepforce)
329 frag_force = '0 0 0';
335 if(!autocvar_g_instagib_mirrordamage) // only apply the taking lives hack if we don't want to support real damage mirroring
336 if(IS_PLAYER(frag_attacker))
337 if(frag_mirrordamage > 0)
339 // just lose extra LIVES, don't kill the player for mirror damage
340 float armor = GetResourceAmount(frag_attacker, RESOURCE_ARMOR);
344 SetResourceAmount(frag_attacker, RESOURCE_ARMOR, armor);
345 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, armor);
346 frag_attacker.damage_dealt += frag_mirrordamage;
348 frag_mirrordamage = 0;
351 if(frag_target.alpha && frag_target.alpha < 1)
352 if(IS_PLAYER(frag_target))
355 M_ARGV(4, float) = frag_damage;
356 M_ARGV(5, float) = frag_mirrordamage;
357 M_ARGV(6, vector) = frag_force;
360 MUTATOR_HOOKFUNCTION(mutator_instagib, SetStartItems)
362 start_health = warmup_start_health = 100;
363 start_armorvalue = warmup_start_armorvalue = 0;
365 start_ammo_shells = warmup_start_ammo_shells = 0;
366 start_ammo_nails = warmup_start_ammo_nails = 0;
367 start_ammo_cells = warmup_start_ammo_cells = cvar("g_instagib_ammo_start");
368 start_ammo_plasma = warmup_start_ammo_plasma = 0;
369 start_ammo_rockets = warmup_start_ammo_rockets = 0;
370 //start_ammo_fuel = warmup_start_ammo_fuel = 0;
372 start_weapons = warmup_start_weapons = WEPSET(VAPORIZER);
373 start_items |= IT_UNLIMITED_SUPERWEAPONS;
376 MUTATOR_HOOKFUNCTION(mutator_instagib, SetWeaponArena)
378 // turn weapon arena off
379 M_ARGV(0, string) = "off";
382 void replace_with_insta_cells(entity item)
384 entity e = new(item_vaporizer_cells);
385 setorigin(e, item.origin);
386 e.noalign = item.noalign;
389 e.spawnfunc_checked = true;
390 spawnfunc_item_vaporizer_cells(e);
393 MUTATOR_HOOKFUNCTION(mutator_instagib, FilterItem)
395 entity item = M_ARGV(0, entity);
397 if(item.classname == "item_cells")
399 if(autocvar_g_instagib_ammo_convert_cells)
401 replace_with_insta_cells(item);
405 else if(item.classname == "item_rockets")
407 if(autocvar_g_instagib_ammo_convert_rockets)
409 replace_with_insta_cells(item);
413 else if(item.classname == "item_shells")
415 if(autocvar_g_instagib_ammo_convert_shells)
417 replace_with_insta_cells(item);
421 else if(item.classname == "item_bullets")
423 if(autocvar_g_instagib_ammo_convert_bullets)
425 replace_with_insta_cells(item);
430 if(item.weapon == WEP_VAPORIZER.m_id && Item_IsLoot(item))
432 SetResourceAmount(item, RESOURCE_CELLS, autocvar_g_instagib_ammo_drop);
436 if(item.weapon == WEP_DEVASTATOR.m_id || item.weapon == WEP_VORTEX.m_id)
438 replace_with_insta_cells(item);
442 if(item.flags & FL_POWERUP)
445 float cells = GetResourceAmount(item, RESOURCE_CELLS);
446 if(cells > autocvar_g_instagib_ammo_drop && item.classname != "item_vaporizer_cells")
447 SetResourceAmount(item, RESOURCE_CELLS, autocvar_g_instagib_ammo_drop);
449 if(cells && !item.weapon)
455 MUTATOR_HOOKFUNCTION(mutator_instagib, CustomizeWaypoint)
457 entity wp = M_ARGV(0, entity);
458 entity player = M_ARGV(1, entity);
460 entity e = WaypointSprite_getviewentity(player);
462 // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
463 // but only apply this to real players, not to spectators
464 if((wp.owner.flags & FL_CLIENT) && (wp.owner.items & ITEM_Invisibility.m_itemid) && (e == player))
465 if(DIFF_TEAM(wp.owner, e))
469 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDies)
471 float frag_deathtype = M_ARGV(3, float);
473 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
474 M_ARGV(4, float) = 1000; // always gib if it was a vaporizer death
477 MUTATOR_HOOKFUNCTION(mutator_instagib, ItemTouch)
479 entity item = M_ARGV(0, entity);
480 entity toucher = M_ARGV(1, entity);
482 if(GetResourceAmount(item, RESOURCE_CELLS))
484 // play some cool sounds ;)
485 float hp = GetResourceAmount(toucher, RESOURCE_HEALTH);
486 if (IS_CLIENT(toucher))
489 Send_Notification(NOTIF_ONE, toucher, MSG_ANNCE, ANNCE_INSTAGIB_LASTSECOND);
491 Send_Notification(NOTIF_ONE, toucher, MSG_ANNCE, ANNCE_INSTAGIB_NARROWLY);
495 SetResourceAmount(toucher, RESOURCE_HEALTH, 100);
497 return MUT_ITEMTOUCH_CONTINUE;
500 if(item.itemdef == ITEM_ExtraLife)
502 GiveResource(toucher, RESOURCE_ARMOR, autocvar_g_instagib_extralives);
503 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_EXTRALIVES);
504 return MUT_ITEMTOUCH_PICKUP;
507 return MUT_ITEMTOUCH_CONTINUE;
510 MUTATOR_HOOKFUNCTION(mutator_instagib, OnEntityPreSpawn)
512 if (!autocvar_g_powerups) { return; }
513 entity ent = M_ARGV(0, entity);
514 // Can't use .itemdef here
515 if (!(ent.classname == "item_strength" || ent.classname == "item_shield" || ent.classname == "item_health_mega"))
523 e.classname = "item_invisibility";
524 setthink(e, instagib_invisibility);
528 e.classname = "item_extralife";
529 setthink(e, instagib_extralife);
533 e.classname = "item_speed";
534 setthink(e, instagib_speed);
537 e.nextthink = time + 0.1;
538 e.spawnflags = ent.spawnflags;
539 e.noalign = ent.noalign;
540 setorigin(e, ent.origin);
545 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsString)
547 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":instagib");
550 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsPrettyString)
552 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", instagib");
555 MUTATOR_HOOKFUNCTION(mutator_instagib, SetModname)
557 M_ARGV(0, string) = "InstaGib";