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, DMG_NOWEP, 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, DMG_NOWEP, 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, DMG_NOWEP, 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, DMG_NOWEP, 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, DMG_NOWEP, 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, DMG_NOWEP, 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, DMG_NOWEP, 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, DMG_NOWEP, 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, DMG_NOWEP, 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, DMG_NOWEP, 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, DMG_NOWEP, 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, ForbidRandomStartWeapons)
186 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerSpawn)
188 entity player = M_ARGV(0, entity);
190 player.effects |= EF_FULLBRIGHT;
193 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPreThink)
195 entity player = M_ARGV(0, entity);
197 instagib_ammocheck(player);
200 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerRegen)
202 // no regeneration in instagib
206 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPowerups)
208 entity player = M_ARGV(0, entity);
210 if (!(player.effects & EF_FULLBRIGHT))
211 player.effects |= EF_FULLBRIGHT;
213 if (player.items & ITEM_Invisibility.m_itemid)
215 play_countdown(player, player.strength_finished, SND_POWEROFF);
216 if (time > player.strength_finished)
218 player.alpha = default_player_alpha;
219 player.exteriorweaponentity.alpha = default_weapon_alpha;
220 player.items &= ~ITEM_Invisibility.m_itemid;
221 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERDOWN_INVISIBILITY);
226 if (time < player.strength_finished)
228 player.alpha = autocvar_g_instagib_invis_alpha;
229 player.exteriorweaponentity.alpha = autocvar_g_instagib_invis_alpha;
230 player.items |= ITEM_Invisibility.m_itemid;
231 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_POWERUP_INVISIBILITY, player.netname);
232 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERUP_INVISIBILITY);
236 if (player.items & ITEM_Speed.m_itemid)
238 play_countdown(player, player.invincible_finished, SND_POWEROFF);
239 if (time > player.invincible_finished)
241 player.items &= ~ITEM_Speed.m_itemid;
242 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERDOWN_SPEED);
247 if (time < player.invincible_finished)
249 player.items |= ITEM_Speed.m_itemid;
250 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_POWERUP_SPEED, player.netname);
251 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERUP_SPEED);
256 .float stat_sv_maxspeed;
258 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPhysics)
260 entity player = M_ARGV(0, entity);
262 if(player.items & ITEM_Speed.m_itemid)
263 player.stat_sv_maxspeed = player.stat_sv_maxspeed * autocvar_g_instagib_speed_highspeed;
266 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDamage_SplitHealthArmor)
268 M_ARGV(4, float) = M_ARGV(7, float); // take = damage
269 M_ARGV(5, float) = 0; // save
272 MUTATOR_HOOKFUNCTION(mutator_instagib, ForbidThrowCurrentWeapon)
274 // weapon dropping on death handled by FilterItem
278 MUTATOR_HOOKFUNCTION(mutator_instagib, Damage_Calculate)
280 entity frag_attacker = M_ARGV(1, entity);
281 entity frag_target = M_ARGV(2, entity);
282 float frag_deathtype = M_ARGV(3, float);
283 float frag_damage = M_ARGV(4, float);
284 float frag_mirrordamage = M_ARGV(5, float);
285 vector frag_force = M_ARGV(6, vector);
287 if(autocvar_g_friendlyfire == 0 && SAME_TEAM(frag_target, frag_attacker) && IS_PLAYER(frag_target) && IS_PLAYER(frag_attacker))
290 if(IS_PLAYER(frag_target))
292 if(frag_deathtype == DEATH_FALL.m_id)
293 frag_damage = 0; // never count fall damage
295 if(!autocvar_g_instagib_damagedbycontents)
296 switch(DEATH_ENT(frag_deathtype))
305 if(IS_PLAYER(frag_attacker))
306 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
308 if(!autocvar_g_instagib_friendlypush && SAME_TEAM(frag_target, frag_attacker))
309 frag_force = '0 0 0';
311 float armor = GetResourceAmount(frag_target, RESOURCE_ARMOR);
315 SetResourceAmount(frag_target, RESOURCE_ARMOR, armor);
317 frag_target.damage_dealt += 1;
318 frag_attacker.damage_dealt += 1;
319 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, armor);
323 if(IS_PLAYER(frag_attacker) && DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
325 if(frag_deathtype & HITTYPE_SECONDARY)
327 if(!autocvar_g_instagib_blaster_keepdamage || frag_attacker == frag_target)
330 if(!autocvar_g_instagib_mirrordamage)
331 frag_mirrordamage = 0; // never do mirror damage on enemies
334 if(frag_target != frag_attacker)
336 if(frag_damage <= 0 && GetResourceAmount(frag_target, RESOURCE_HEALTH) > 0) { Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE); }
337 if(!autocvar_g_instagib_blaster_keepforce)
338 frag_force = '0 0 0';
344 if(!autocvar_g_instagib_mirrordamage) // only apply the taking lives hack if we don't want to support real damage mirroring
345 if(IS_PLAYER(frag_attacker))
346 if(frag_mirrordamage > 0)
348 // just lose extra LIVES, don't kill the player for mirror damage
349 float armor = GetResourceAmount(frag_attacker, RESOURCE_ARMOR);
353 SetResourceAmount(frag_attacker, RESOURCE_ARMOR, armor);
354 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, armor);
355 frag_attacker.damage_dealt += frag_mirrordamage;
357 frag_mirrordamage = 0;
360 if(frag_target.alpha && frag_target.alpha < 1)
361 if(IS_PLAYER(frag_target))
364 M_ARGV(4, float) = frag_damage;
365 M_ARGV(5, float) = frag_mirrordamage;
366 M_ARGV(6, vector) = frag_force;
369 MUTATOR_HOOKFUNCTION(mutator_instagib, SetStartItems)
371 start_health = warmup_start_health = 100;
372 start_armorvalue = warmup_start_armorvalue = 0;
374 start_ammo_shells = warmup_start_ammo_shells = 0;
375 start_ammo_nails = warmup_start_ammo_nails = 0;
376 start_ammo_cells = warmup_start_ammo_cells = cvar("g_instagib_ammo_start");
377 start_ammo_plasma = warmup_start_ammo_plasma = 0;
378 start_ammo_rockets = warmup_start_ammo_rockets = 0;
379 //start_ammo_fuel = warmup_start_ammo_fuel = 0;
381 start_weapons = warmup_start_weapons = WEPSET(VAPORIZER);
382 start_items |= IT_UNLIMITED_SUPERWEAPONS;
385 MUTATOR_HOOKFUNCTION(mutator_instagib, SetWeaponArena)
387 // turn weapon arena off
388 M_ARGV(0, string) = "off";
391 void replace_with_insta_cells(entity item)
393 entity e = new(item_vaporizer_cells);
394 setorigin(e, item.origin);
395 e.noalign = Item_ShouldKeepPosition(item);
398 e.spawnfunc_checked = true;
399 spawnfunc_item_vaporizer_cells(e);
402 MUTATOR_HOOKFUNCTION(mutator_instagib, FilterItem)
404 entity item = M_ARGV(0, entity);
406 if(item.classname == "item_cells")
408 if(autocvar_g_instagib_ammo_convert_cells)
410 replace_with_insta_cells(item);
414 else if(item.classname == "item_rockets")
416 if(autocvar_g_instagib_ammo_convert_rockets)
418 replace_with_insta_cells(item);
422 else if(item.classname == "item_shells")
424 if(autocvar_g_instagib_ammo_convert_shells)
426 replace_with_insta_cells(item);
430 else if(item.classname == "item_bullets")
432 if(autocvar_g_instagib_ammo_convert_bullets)
434 replace_with_insta_cells(item);
439 if(item.weapon == WEP_VAPORIZER.m_id && Item_IsLoot(item))
441 SetResourceAmount(item, RESOURCE_CELLS, autocvar_g_instagib_ammo_drop);
445 if(item.weapon == WEP_DEVASTATOR.m_id || item.weapon == WEP_VORTEX.m_id)
447 replace_with_insta_cells(item);
451 if(item.flags & FL_POWERUP)
454 float cells = GetResourceAmount(item, RESOURCE_CELLS);
455 if(cells > autocvar_g_instagib_ammo_drop && item.classname != "item_vaporizer_cells")
456 SetResourceAmount(item, RESOURCE_CELLS, autocvar_g_instagib_ammo_drop);
458 if(cells && !item.weapon)
464 MUTATOR_HOOKFUNCTION(mutator_instagib, CustomizeWaypoint)
466 entity wp = M_ARGV(0, entity);
467 entity player = M_ARGV(1, entity);
469 entity e = WaypointSprite_getviewentity(player);
471 // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
472 // but only apply this to real players, not to spectators
473 if((wp.owner.flags & FL_CLIENT) && (wp.owner.items & ITEM_Invisibility.m_itemid) && (e == player))
474 if(DIFF_TEAM(wp.owner, e))
478 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDies)
480 float frag_deathtype = M_ARGV(3, float);
482 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
483 M_ARGV(4, float) = 1000; // always gib if it was a vaporizer death
486 MUTATOR_HOOKFUNCTION(mutator_instagib, ItemTouch)
488 entity item = M_ARGV(0, entity);
489 entity toucher = M_ARGV(1, entity);
491 if(GetResourceAmount(item, RESOURCE_CELLS))
493 // play some cool sounds ;)
494 float hp = GetResourceAmount(toucher, RESOURCE_HEALTH);
495 if (IS_CLIENT(toucher))
498 Send_Notification(NOTIF_ONE, toucher, MSG_ANNCE, ANNCE_INSTAGIB_LASTSECOND);
500 Send_Notification(NOTIF_ONE, toucher, MSG_ANNCE, ANNCE_INSTAGIB_NARROWLY);
504 SetResourceAmount(toucher, RESOURCE_HEALTH, 100);
506 return MUT_ITEMTOUCH_CONTINUE;
509 if(item.itemdef == ITEM_ExtraLife)
511 GiveResource(toucher, RESOURCE_ARMOR, autocvar_g_instagib_extralives);
512 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_EXTRALIVES);
513 return MUT_ITEMTOUCH_PICKUP;
516 return MUT_ITEMTOUCH_CONTINUE;
519 MUTATOR_HOOKFUNCTION(mutator_instagib, OnEntityPreSpawn)
521 if (!autocvar_g_powerups) { return; }
522 entity ent = M_ARGV(0, entity);
523 // Can't use .itemdef here
524 if (!(ent.classname == "item_strength" || ent.classname == "item_shield" || ent.classname == "item_health_mega"))
532 e.classname = "item_invisibility";
533 setthink(e, instagib_invisibility);
537 e.classname = "item_extralife";
538 setthink(e, instagib_extralife);
542 e.classname = "item_speed";
543 setthink(e, instagib_speed);
546 e.nextthink = time + 0.1;
547 e.spawnflags = ent.spawnflags;
548 e.noalign = ent.noalign;
549 setorigin(e, ent.origin);
554 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsString)
556 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":instagib");
559 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsPrettyString)
561 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", instagib");
564 MUTATOR_HOOKFUNCTION(mutator_instagib, SetModname)
566 M_ARGV(0, string) = "InstaGib";