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 (GetResourceAmount(this, RESOURCE_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 float hp = GetResourceAmount(this, RESOURCE_HEALTH);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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), { instagib_stop_countdown(it); });
137 MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterDropItem)
139 entity item = M_ARGV(1, entity);
141 item.monster_loot = ITEM_VaporizerCells;
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, Damage_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 float armor = GetResourceAmount(frag_target, RESOURCE_ARMOR);
297 SetResourceAmount(frag_target, RESOURCE_ARMOR, armor);
299 frag_target.damage_dealt += 1;
300 frag_attacker.damage_dealt += 1;
301 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, armor);
305 if(IS_PLAYER(frag_attacker) && DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
307 if(frag_deathtype & HITTYPE_SECONDARY)
309 if(!autocvar_g_instagib_blaster_keepdamage || frag_attacker == frag_target)
312 if(!autocvar_g_instagib_mirrordamage)
313 frag_mirrordamage = 0; // never do mirror damage on enemies
316 if(frag_target != frag_attacker)
318 if(frag_damage <= 0 && GetResourceAmount(frag_target, RESOURCE_HEALTH) > 0) { Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE); }
319 if(!autocvar_g_instagib_blaster_keepforce)
320 frag_force = '0 0 0';
326 if(!autocvar_g_instagib_mirrordamage) // only apply the taking lives hack if we don't want to support real damage mirroring
327 if(IS_PLAYER(frag_attacker))
328 if(frag_mirrordamage > 0)
330 // just lose extra LIVES, don't kill the player for mirror damage
331 float armor = GetResourceAmount(frag_attacker, RESOURCE_ARMOR);
335 SetResourceAmount(frag_attacker, RESOURCE_ARMOR, armor);
336 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, armor);
337 frag_attacker.damage_dealt += frag_mirrordamage;
339 frag_mirrordamage = 0;
342 if(frag_target.alpha && frag_target.alpha < 1)
343 if(IS_PLAYER(frag_target))
346 M_ARGV(4, float) = frag_damage;
347 M_ARGV(5, float) = frag_mirrordamage;
348 M_ARGV(6, vector) = frag_force;
351 MUTATOR_HOOKFUNCTION(mutator_instagib, SetStartItems)
353 start_health = warmup_start_health = 100;
354 start_armorvalue = warmup_start_armorvalue = 0;
356 start_ammo_shells = warmup_start_ammo_shells = 0;
357 start_ammo_nails = warmup_start_ammo_nails = 0;
358 start_ammo_cells = warmup_start_ammo_cells = cvar("g_instagib_ammo_start");
359 start_ammo_plasma = warmup_start_ammo_plasma = 0;
360 start_ammo_rockets = warmup_start_ammo_rockets = 0;
361 //start_ammo_fuel = warmup_start_ammo_fuel = 0;
363 start_weapons = warmup_start_weapons = WEPSET(VAPORIZER);
364 start_items |= IT_UNLIMITED_SUPERWEAPONS;
367 MUTATOR_HOOKFUNCTION(mutator_instagib, SetWeaponArena)
369 // turn weapon arena off
370 M_ARGV(0, string) = "off";
373 void replace_with_insta_cells(entity item)
376 setorigin(e, item.origin);
377 e.noalign = item.noalign;
380 e.spawnfunc_checked = true;
381 spawnfunc_item_minst_cells(e);
384 MUTATOR_HOOKFUNCTION(mutator_instagib, FilterItem)
386 entity item = M_ARGV(0, entity);
388 if(item.classname == "item_cells")
390 if(autocvar_g_instagib_ammo_convert_cells)
392 replace_with_insta_cells(item);
396 else if(item.classname == "item_rockets")
398 if(autocvar_g_instagib_ammo_convert_rockets)
400 replace_with_insta_cells(item);
404 else if(item.classname == "item_shells")
406 if(autocvar_g_instagib_ammo_convert_shells)
408 replace_with_insta_cells(item);
412 else if(item.classname == "item_bullets")
414 if(autocvar_g_instagib_ammo_convert_bullets)
416 replace_with_insta_cells(item);
421 if(item.weapon == WEP_VAPORIZER.m_id && item.classname == "droppedweapon")
423 SetResourceAmount(item, RESOURCE_CELLS, autocvar_g_instagib_ammo_drop);
427 if(item.weapon == WEP_DEVASTATOR.m_id || item.weapon == WEP_VORTEX.m_id)
429 replace_with_insta_cells(item);
433 if(item.flags & FL_POWERUP)
436 float cells = GetResourceAmount(item, RESOURCE_CELLS);
437 if(cells > autocvar_g_instagib_ammo_drop && item.classname != "item_minst_cells")
438 SetResourceAmount(item, RESOURCE_CELLS, autocvar_g_instagib_ammo_drop);
440 if(cells && !item.weapon)
446 MUTATOR_HOOKFUNCTION(mutator_instagib, CustomizeWaypoint)
448 entity wp = M_ARGV(0, entity);
449 entity player = M_ARGV(1, entity);
451 entity e = WaypointSprite_getviewentity(player);
453 // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
454 // but only apply this to real players, not to spectators
455 if((wp.owner.flags & FL_CLIENT) && (wp.owner.items & ITEM_Invisibility.m_itemid) && (e == player))
456 if(DIFF_TEAM(wp.owner, e))
460 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDies)
462 float frag_deathtype = M_ARGV(3, float);
464 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
465 M_ARGV(4, float) = 1000; // always gib if it was a vaporizer death
468 MUTATOR_HOOKFUNCTION(mutator_instagib, ItemTouch)
470 entity item = M_ARGV(0, entity);
471 entity toucher = M_ARGV(1, entity);
473 if(GetResourceAmount(item, RESOURCE_CELLS))
475 // play some cool sounds ;)
476 float hp = GetResourceAmount(toucher, RESOURCE_HEALTH);
477 if (IS_CLIENT(toucher))
480 Send_Notification(NOTIF_ONE, toucher, MSG_ANNCE, ANNCE_INSTAGIB_LASTSECOND);
482 Send_Notification(NOTIF_ONE, toucher, MSG_ANNCE, ANNCE_INSTAGIB_NARROWLY);
486 SetResourceAmount(toucher, RESOURCE_HEALTH, 100);
488 return MUT_ITEMTOUCH_CONTINUE;
491 if(item.itemdef == ITEM_ExtraLife)
493 GiveResource(toucher, RESOURCE_ARMOR, autocvar_g_instagib_extralives);
494 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_EXTRALIVES);
495 return MUT_ITEMTOUCH_PICKUP;
498 return MUT_ITEMTOUCH_CONTINUE;
501 MUTATOR_HOOKFUNCTION(mutator_instagib, OnEntityPreSpawn)
503 if (!autocvar_g_powerups) { return; }
504 entity ent = M_ARGV(0, entity);
505 // Can't use .itemdef here
506 if (!(ent.classname == "item_strength" || ent.classname == "item_invincible" || ent.classname == "item_health_mega"))
513 setthink(e, instagib_invisibility);
515 setthink(e, instagib_extralife);
517 setthink(e, instagib_speed);
519 e.nextthink = time + 0.1;
520 e.spawnflags = ent.spawnflags;
521 e.noalign = ent.noalign;
522 setorigin(e, ent.origin);
527 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsString)
529 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":instagib");
532 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsPrettyString)
534 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", instagib");
537 MUTATOR_HOOKFUNCTION(mutator_instagib, SetModname)
539 M_ARGV(0, string) = "InstaGib";