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 void instagib_invisibility(entity this)
22 this.strength_finished = autocvar_g_instagib_invisibility_time;
23 StartItem(this, ITEM_Invisibility);
26 void instagib_extralife(entity this)
28 StartItem(this, ITEM_ExtraLife);
31 void instagib_speed(entity this)
33 this.invincible_finished = autocvar_g_instagib_speed_time;
34 StartItem(this, ITEM_Speed);
37 .float instagib_nextthink;
38 .float instagib_needammo;
39 void instagib_stop_countdown(entity e)
41 if (!e.instagib_needammo)
43 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER, CPID_INSTAGIB_FINDAMMO);
44 e.instagib_needammo = false;
46 void instagib_ammocheck(entity this)
48 if(time < this.instagib_nextthink)
51 return; // not a player
53 if(IS_DEAD(this) || game_stopped)
54 instagib_stop_countdown(this);
55 else if (GetResourceAmount(this, RESOURCE_CELLS) > 0 || (this.items & IT_UNLIMITED_WEAPON_AMMO) || (this.flags & FL_GODMODE))
56 instagib_stop_countdown(this);
57 else if(autocvar_g_rm && autocvar_g_rm_laser)
59 if(!this.instagib_needammo)
61 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_INSTAGIB_DOWNGRADE);
62 this.instagib_needammo = true;
67 float hp = GetResourceAmount(this, RESOURCE_HEALTH);
68 this.instagib_needammo = true;
71 Damage(this, this, this, 5, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
72 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_INSTAGIB_TERMINATED);
76 Damage(this, this, this, 5, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
77 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_1);
81 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
82 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_2);
86 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
87 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_3);
91 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
92 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_4);
96 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
97 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_5);
101 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
102 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_6);
106 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
107 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_7);
111 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
112 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_8);
116 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_INSTAGIB_FINDAMMO);
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_9);
122 Send_Notification(NOTIF_ONE_ONLY, this, MSG_MULTI, MULTI_INSTAGIB_FINDAMMO);
123 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, DMG_NOWEP, this.origin, '0 0 0');
126 this.instagib_nextthink = time + 1;
129 MUTATOR_HOOKFUNCTION(mutator_instagib, MatchEnd)
131 FOREACH_CLIENT(IS_PLAYER(it), { instagib_stop_countdown(it); });
134 MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterDropItem)
136 entity item = M_ARGV(1, entity);
138 item.monster_loot = ITEM_VaporizerCells;
141 MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterSpawn)
143 entity mon = M_ARGV(0, entity);
145 // always refill ammo
146 if(mon.monsterid == MON_MAGE.monsterid)
150 MUTATOR_HOOKFUNCTION(mutator_instagib, BotShouldAttack)
152 entity targ = M_ARGV(1, entity);
154 if (targ.items & ITEM_Invisibility.m_itemid)
158 MUTATOR_HOOKFUNCTION(mutator_instagib, MakePlayerObserver)
160 entity player = M_ARGV(0, entity);
162 instagib_stop_countdown(player);
165 MUTATOR_HOOKFUNCTION(mutator_instagib, ForbidRandomStartWeapons)
170 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerSpawn)
172 entity player = M_ARGV(0, entity);
174 player.effects |= EF_FULLBRIGHT;
177 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPreThink)
179 entity player = M_ARGV(0, entity);
181 instagib_ammocheck(player);
184 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerRegen)
186 // no regeneration in instagib
190 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPowerups)
192 entity player = M_ARGV(0, entity);
194 if (!(player.effects & EF_FULLBRIGHT))
195 player.effects |= EF_FULLBRIGHT;
197 if (player.items & ITEM_Invisibility.m_itemid)
199 play_countdown(player, player.strength_finished, SND_POWEROFF);
200 if (time > player.strength_finished)
202 player.alpha = default_player_alpha;
203 player.exteriorweaponentity.alpha = default_weapon_alpha;
204 player.items &= ~ITEM_Invisibility.m_itemid;
205 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERDOWN_INVISIBILITY);
210 if (time < player.strength_finished)
212 player.alpha = autocvar_g_instagib_invis_alpha;
213 player.exteriorweaponentity.alpha = autocvar_g_instagib_invis_alpha;
214 player.items |= ITEM_Invisibility.m_itemid;
215 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_POWERUP_INVISIBILITY, player.netname);
216 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERUP_INVISIBILITY);
220 if (player.items & ITEM_Speed.m_itemid)
222 play_countdown(player, player.invincible_finished, SND_POWEROFF);
223 if (time > player.invincible_finished)
225 player.items &= ~ITEM_Speed.m_itemid;
226 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERDOWN_SPEED);
231 if (time < player.invincible_finished)
233 player.items |= ITEM_Speed.m_itemid;
234 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_POWERUP_SPEED, player.netname);
235 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERUP_SPEED);
240 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPhysics_UpdateStats)
242 entity player = M_ARGV(0, entity);
243 // these automatically reset, no need to worry
245 if(player.items & ITEM_Speed.m_itemid)
246 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_instagib_speed_highspeed;
249 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDamage_SplitHealthArmor)
251 M_ARGV(4, float) = M_ARGV(7, float); // take = damage
252 M_ARGV(5, float) = 0; // save
255 MUTATOR_HOOKFUNCTION(mutator_instagib, ForbidThrowCurrentWeapon)
257 // weapon dropping on death handled by FilterItem
261 MUTATOR_HOOKFUNCTION(mutator_instagib, Damage_Calculate)
263 entity frag_attacker = M_ARGV(1, entity);
264 entity frag_target = M_ARGV(2, entity);
265 float frag_deathtype = M_ARGV(3, float);
266 float frag_damage = M_ARGV(4, float);
267 float frag_mirrordamage = M_ARGV(5, float);
268 vector frag_force = M_ARGV(6, vector);
270 if(autocvar_g_friendlyfire == 0 && SAME_TEAM(frag_target, frag_attacker) && IS_PLAYER(frag_target) && IS_PLAYER(frag_attacker))
273 if(IS_PLAYER(frag_target))
275 if(frag_deathtype == DEATH_FALL.m_id)
276 frag_damage = 0; // never count fall damage
278 if(!autocvar_g_instagib_damagedbycontents)
279 switch(DEATH_ENT(frag_deathtype))
288 if(IS_PLAYER(frag_attacker))
289 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
291 if(!autocvar_g_instagib_friendlypush && SAME_TEAM(frag_target, frag_attacker))
292 frag_force = '0 0 0';
294 float armor = GetResourceAmount(frag_target, RESOURCE_ARMOR);
298 SetResourceAmount(frag_target, RESOURCE_ARMOR, armor);
300 frag_target.damage_dealt += 1;
301 frag_attacker.damage_dealt += 1;
302 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, armor);
306 if(IS_PLAYER(frag_attacker) && DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
308 if(frag_deathtype & HITTYPE_SECONDARY)
310 if(!autocvar_g_instagib_blaster_keepdamage || frag_attacker == frag_target)
313 if(!autocvar_g_instagib_mirrordamage)
314 frag_mirrordamage = 0; // never do mirror damage on enemies
317 if(frag_target != frag_attacker)
319 if(frag_damage <= 0 && GetResourceAmount(frag_target, RESOURCE_HEALTH) > 0) { Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE); }
320 if(!autocvar_g_instagib_blaster_keepforce)
321 frag_force = '0 0 0';
327 if(!autocvar_g_instagib_mirrordamage) // only apply the taking lives hack if we don't want to support real damage mirroring
328 if(IS_PLAYER(frag_attacker))
329 if(frag_mirrordamage > 0)
331 // just lose extra LIVES, don't kill the player for mirror damage
332 float armor = GetResourceAmount(frag_attacker, RESOURCE_ARMOR);
336 SetResourceAmount(frag_attacker, RESOURCE_ARMOR, armor);
337 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, armor);
338 frag_attacker.damage_dealt += frag_mirrordamage;
340 frag_mirrordamage = 0;
343 if(frag_target.alpha && frag_target.alpha < 1)
344 if(IS_PLAYER(frag_target))
347 M_ARGV(4, float) = frag_damage;
348 M_ARGV(5, float) = frag_mirrordamage;
349 M_ARGV(6, vector) = frag_force;
352 MUTATOR_HOOKFUNCTION(mutator_instagib, SetStartItems)
354 start_health = warmup_start_health = 100;
355 start_armorvalue = warmup_start_armorvalue = 0;
357 start_ammo_shells = warmup_start_ammo_shells = 0;
358 start_ammo_nails = warmup_start_ammo_nails = 0;
359 start_ammo_cells = warmup_start_ammo_cells = cvar("g_instagib_ammo_start");
360 start_ammo_plasma = warmup_start_ammo_plasma = 0;
361 start_ammo_rockets = warmup_start_ammo_rockets = 0;
362 //start_ammo_fuel = warmup_start_ammo_fuel = 0;
364 start_weapons = warmup_start_weapons = WEPSET(VAPORIZER);
365 start_items |= IT_UNLIMITED_SUPERWEAPONS;
368 MUTATOR_HOOKFUNCTION(mutator_instagib, SetWeaponArena)
370 // turn weapon arena off
371 M_ARGV(0, string) = "off";
374 void replace_with_insta_cells(entity item)
376 entity e = new(item_vaporizer_cells);
377 setorigin(e, item.origin);
378 e.noalign = Item_ShouldKeepPosition(item);
381 e.spawnfunc_checked = true;
382 spawnfunc_item_vaporizer_cells(e);
385 MUTATOR_HOOKFUNCTION(mutator_instagib, FilterItem)
387 entity item = M_ARGV(0, entity);
389 if(item.classname == "item_cells")
391 if(autocvar_g_instagib_ammo_convert_cells)
393 replace_with_insta_cells(item);
397 else if(item.classname == "item_rockets")
399 if(autocvar_g_instagib_ammo_convert_rockets)
401 replace_with_insta_cells(item);
405 else if(item.classname == "item_shells")
407 if(autocvar_g_instagib_ammo_convert_shells)
409 replace_with_insta_cells(item);
413 else if(item.classname == "item_bullets")
415 if(autocvar_g_instagib_ammo_convert_bullets)
417 replace_with_insta_cells(item);
422 if(item.weapon == WEP_VAPORIZER.m_id && Item_IsLoot(item))
424 SetResourceAmount(item, RESOURCE_CELLS, autocvar_g_instagib_ammo_drop);
428 if(item.weapon == WEP_DEVASTATOR.m_id || item.weapon == WEP_VORTEX.m_id)
430 replace_with_insta_cells(item);
434 if(item.flags & FL_POWERUP)
437 float cells = GetResourceAmount(item, RESOURCE_CELLS);
438 if(cells > autocvar_g_instagib_ammo_drop && item.classname != "item_vaporizer_cells")
439 SetResourceAmount(item, RESOURCE_CELLS, autocvar_g_instagib_ammo_drop);
441 if(cells && !item.weapon)
447 MUTATOR_HOOKFUNCTION(mutator_instagib, CustomizeWaypoint)
449 entity wp = M_ARGV(0, entity);
450 entity player = M_ARGV(1, entity);
452 entity e = WaypointSprite_getviewentity(player);
454 // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
455 // but only apply this to real players, not to spectators
456 if((wp.owner.flags & FL_CLIENT) && (wp.owner.items & ITEM_Invisibility.m_itemid) && (e == player))
457 if(DIFF_TEAM(wp.owner, e))
461 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDies)
463 float frag_deathtype = M_ARGV(3, float);
465 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
466 M_ARGV(4, float) = 1000; // always gib if it was a vaporizer death
469 MUTATOR_HOOKFUNCTION(mutator_instagib, ItemTouch)
471 entity item = M_ARGV(0, entity);
472 entity toucher = M_ARGV(1, entity);
474 if(GetResourceAmount(item, RESOURCE_CELLS))
476 // play some cool sounds ;)
477 float hp = GetResourceAmount(toucher, RESOURCE_HEALTH);
478 if (IS_CLIENT(toucher))
481 Send_Notification(NOTIF_ONE, toucher, MSG_ANNCE, ANNCE_INSTAGIB_LASTSECOND);
483 Send_Notification(NOTIF_ONE, toucher, MSG_ANNCE, ANNCE_INSTAGIB_NARROWLY);
487 SetResourceAmount(toucher, RESOURCE_HEALTH, 100);
489 return MUT_ITEMTOUCH_CONTINUE;
492 if(item.itemdef == ITEM_ExtraLife)
494 GiveResource(toucher, RESOURCE_ARMOR, autocvar_g_instagib_extralives);
495 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_EXTRALIVES);
496 return MUT_ITEMTOUCH_PICKUP;
499 return MUT_ITEMTOUCH_CONTINUE;
502 MUTATOR_HOOKFUNCTION(mutator_instagib, OnEntityPreSpawn)
504 if (!autocvar_g_powerups) { return; }
505 entity ent = M_ARGV(0, entity);
506 // Can't use .itemdef here
507 if (!(ent.classname == "item_strength" || ent.classname == "item_shield" || ent.classname == "item_health_mega"))
515 e.classname = "item_invisibility";
516 setthink(e, instagib_invisibility);
520 e.classname = "item_extralife";
521 setthink(e, instagib_extralife);
525 e.classname = "item_speed";
526 setthink(e, instagib_speed);
529 e.nextthink = time + 0.1;
530 e.spawnflags = ent.spawnflags;
531 e.noalign = ent.noalign;
532 setorigin(e, ent.origin);
537 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsString)
539 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":instagib");
542 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsPrettyString)
544 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", instagib");
547 MUTATOR_HOOKFUNCTION(mutator_instagib, SetModname)
549 M_ARGV(0, string) = "InstaGib";