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);
22 spawnfunc(item_vaporizer_cells)
24 if (!g_instagib) { delete(this); return; }
25 StartItem(this, ITEM_VaporizerCells);
28 void instagib_invisibility(entity this)
30 this.strength_finished = autocvar_g_balance_powerup_strength_time;
31 StartItem(this, ITEM_Invisibility);
34 void instagib_extralife(entity this)
36 StartItem(this, ITEM_ExtraLife);
39 void instagib_speed(entity this)
41 this.invincible_finished = autocvar_g_balance_powerup_invincible_time;
42 StartItem(this, ITEM_Speed);
45 .float instagib_nextthink;
46 .float instagib_needammo;
47 void instagib_stop_countdown(entity e)
49 if (!e.instagib_needammo)
51 Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER, CPID_INSTAGIB_FINDAMMO);
52 e.instagib_needammo = false;
54 void instagib_ammocheck(entity this)
56 if(time < this.instagib_nextthink)
59 return; // not a player
61 if(IS_DEAD(this) || game_stopped)
62 instagib_stop_countdown(this);
63 else if (GetResourceAmount(this, RESOURCE_CELLS) > 0 || (this.items & IT_UNLIMITED_WEAPON_AMMO) || (this.flags & FL_GODMODE))
64 instagib_stop_countdown(this);
65 else if(autocvar_g_rm && autocvar_g_rm_laser)
67 if(!this.instagib_needammo)
69 Send_Notification(NOTIF_ONE, this, MSG_CENTER, CENTER_INSTAGIB_DOWNGRADE);
70 this.instagib_needammo = true;
75 float hp = GetResourceAmount(this, RESOURCE_HEALTH);
76 this.instagib_needammo = true;
79 Damage(this, this, this, 5, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
80 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_INSTAGIB_TERMINATED);
84 Damage(this, this, this, 5, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
85 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_1);
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_2);
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_3);
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_4);
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_5);
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_6);
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_7);
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_8);
124 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_INSTAGIB_FINDAMMO);
125 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
126 Send_Notification(NOTIF_ONE, this, MSG_ANNCE, ANNCE_NUM_9);
130 Send_Notification(NOTIF_ONE_ONLY, this, MSG_MULTI, MULTI_INSTAGIB_FINDAMMO);
131 Damage(this, this, this, 10, DEATH_NOAMMO.m_id, this.origin, '0 0 0');
134 this.instagib_nextthink = time + 1;
137 MUTATOR_HOOKFUNCTION(mutator_instagib, MatchEnd)
139 FOREACH_CLIENT(IS_PLAYER(it), { instagib_stop_countdown(it); });
142 MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterDropItem)
144 entity item = M_ARGV(1, entity);
146 item.monster_loot = ITEM_VaporizerCells;
149 MUTATOR_HOOKFUNCTION(mutator_instagib, MonsterSpawn)
151 entity mon = M_ARGV(0, entity);
153 // always refill ammo
154 if(mon.monsterid == MON_MAGE.monsterid)
158 MUTATOR_HOOKFUNCTION(mutator_instagib, BotShouldAttack)
160 entity targ = M_ARGV(1, entity);
162 if (targ.items & ITEM_Invisibility.m_itemid)
166 MUTATOR_HOOKFUNCTION(mutator_instagib, MakePlayerObserver)
168 entity player = M_ARGV(0, entity);
170 instagib_stop_countdown(player);
173 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerSpawn)
175 entity player = M_ARGV(0, entity);
177 player.effects |= EF_FULLBRIGHT;
180 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPreThink)
182 entity player = M_ARGV(0, entity);
184 instagib_ammocheck(player);
187 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerRegen)
189 // no regeneration in instagib
193 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPowerups)
195 entity player = M_ARGV(0, entity);
197 if (!(player.effects & EF_FULLBRIGHT))
198 player.effects |= EF_FULLBRIGHT;
200 if (player.items & ITEM_Invisibility.m_itemid)
202 play_countdown(player, player.strength_finished, SND_POWEROFF);
203 if (time > player.strength_finished)
205 player.alpha = default_player_alpha;
206 player.exteriorweaponentity.alpha = default_weapon_alpha;
207 player.items &= ~ITEM_Invisibility.m_itemid;
208 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERDOWN_INVISIBILITY);
213 if (time < player.strength_finished)
215 player.alpha = autocvar_g_instagib_invis_alpha;
216 player.exteriorweaponentity.alpha = autocvar_g_instagib_invis_alpha;
217 player.items |= ITEM_Invisibility.m_itemid;
218 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_POWERUP_INVISIBILITY, player.netname);
219 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERUP_INVISIBILITY);
223 if (player.items & ITEM_Speed.m_itemid)
225 play_countdown(player, player.invincible_finished, SND_POWEROFF);
226 if (time > player.invincible_finished)
228 player.items &= ~ITEM_Speed.m_itemid;
229 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERDOWN_SPEED);
234 if (time < player.invincible_finished)
236 player.items |= ITEM_Speed.m_itemid;
237 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_POWERUP_SPEED, player.netname);
238 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_POWERUP_SPEED);
243 .float stat_sv_maxspeed;
245 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerPhysics)
247 entity player = M_ARGV(0, entity);
249 if(player.items & ITEM_Speed.m_itemid)
250 player.stat_sv_maxspeed = player.stat_sv_maxspeed * autocvar_g_instagib_speed_highspeed;
253 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDamage_SplitHealthArmor)
255 M_ARGV(4, float) = M_ARGV(7, float); // take = damage
256 M_ARGV(5, float) = 0; // save
259 MUTATOR_HOOKFUNCTION(mutator_instagib, ForbidThrowCurrentWeapon)
261 // weapon dropping on death handled by FilterItem
265 MUTATOR_HOOKFUNCTION(mutator_instagib, Damage_Calculate)
267 entity frag_attacker = M_ARGV(1, entity);
268 entity frag_target = M_ARGV(2, entity);
269 float frag_deathtype = M_ARGV(3, float);
270 float frag_damage = M_ARGV(4, float);
271 float frag_mirrordamage = M_ARGV(5, float);
272 vector frag_force = M_ARGV(6, vector);
274 if(autocvar_g_friendlyfire == 0 && SAME_TEAM(frag_target, frag_attacker) && IS_PLAYER(frag_target) && IS_PLAYER(frag_attacker))
277 if(IS_PLAYER(frag_target))
279 if(frag_deathtype == DEATH_FALL.m_id)
280 frag_damage = 0; // never count fall damage
282 if(!autocvar_g_instagib_damagedbycontents)
283 switch(DEATH_ENT(frag_deathtype))
292 if(IS_PLAYER(frag_attacker))
293 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
295 if(!autocvar_g_instagib_friendlypush && SAME_TEAM(frag_target, frag_attacker))
296 frag_force = '0 0 0';
298 float armor = GetResourceAmount(frag_target, RESOURCE_ARMOR);
302 SetResourceAmount(frag_target, RESOURCE_ARMOR, armor);
304 frag_target.damage_dealt += 1;
305 frag_attacker.damage_dealt += 1;
306 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, armor);
310 if(IS_PLAYER(frag_attacker) && DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
312 if(frag_deathtype & HITTYPE_SECONDARY)
314 if(!autocvar_g_instagib_blaster_keepdamage || frag_attacker == frag_target)
317 if(!autocvar_g_instagib_mirrordamage)
318 frag_mirrordamage = 0; // never do mirror damage on enemies
321 if(frag_target != frag_attacker)
323 if(frag_damage <= 0 && GetResourceAmount(frag_target, RESOURCE_HEALTH) > 0) { Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE); }
324 if(!autocvar_g_instagib_blaster_keepforce)
325 frag_force = '0 0 0';
331 if(!autocvar_g_instagib_mirrordamage) // only apply the taking lives hack if we don't want to support real damage mirroring
332 if(IS_PLAYER(frag_attacker))
333 if(frag_mirrordamage > 0)
335 // just lose extra LIVES, don't kill the player for mirror damage
336 float armor = GetResourceAmount(frag_attacker, RESOURCE_ARMOR);
340 SetResourceAmount(frag_attacker, RESOURCE_ARMOR, armor);
341 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_INSTAGIB_LIVES_REMAINING, armor);
342 frag_attacker.damage_dealt += frag_mirrordamage;
344 frag_mirrordamage = 0;
347 if(frag_target.alpha && frag_target.alpha < 1)
348 if(IS_PLAYER(frag_target))
351 M_ARGV(4, float) = frag_damage;
352 M_ARGV(5, float) = frag_mirrordamage;
353 M_ARGV(6, vector) = frag_force;
356 MUTATOR_HOOKFUNCTION(mutator_instagib, SetStartItems)
358 start_health = warmup_start_health = 100;
359 start_armorvalue = warmup_start_armorvalue = 0;
361 start_ammo_shells = warmup_start_ammo_shells = 0;
362 start_ammo_nails = warmup_start_ammo_nails = 0;
363 start_ammo_cells = warmup_start_ammo_cells = cvar("g_instagib_ammo_start");
364 start_ammo_plasma = warmup_start_ammo_plasma = 0;
365 start_ammo_rockets = warmup_start_ammo_rockets = 0;
366 //start_ammo_fuel = warmup_start_ammo_fuel = 0;
368 start_weapons = warmup_start_weapons = WEPSET(VAPORIZER);
369 start_items |= IT_UNLIMITED_SUPERWEAPONS;
372 MUTATOR_HOOKFUNCTION(mutator_instagib, SetWeaponArena)
374 // turn weapon arena off
375 M_ARGV(0, string) = "off";
378 void replace_with_insta_cells(entity item)
380 entity e = new(item_vaporizer_cells);
381 setorigin(e, item.origin);
382 e.noalign = item.noalign;
385 e.spawnfunc_checked = true;
386 spawnfunc_item_vaporizer_cells(e);
389 MUTATOR_HOOKFUNCTION(mutator_instagib, FilterItem)
391 entity item = M_ARGV(0, entity);
393 if(item.classname == "item_cells")
395 if(autocvar_g_instagib_ammo_convert_cells)
397 replace_with_insta_cells(item);
401 else if(item.classname == "item_rockets")
403 if(autocvar_g_instagib_ammo_convert_rockets)
405 replace_with_insta_cells(item);
409 else if(item.classname == "item_shells")
411 if(autocvar_g_instagib_ammo_convert_shells)
413 replace_with_insta_cells(item);
417 else if(item.classname == "item_bullets")
419 if(autocvar_g_instagib_ammo_convert_bullets)
421 replace_with_insta_cells(item);
426 if(item.weapon == WEP_VAPORIZER.m_id && item.classname == "droppedweapon")
428 SetResourceAmount(item, RESOURCE_CELLS, autocvar_g_instagib_ammo_drop);
432 if(item.weapon == WEP_DEVASTATOR.m_id || item.weapon == WEP_VORTEX.m_id)
434 replace_with_insta_cells(item);
438 if(item.flags & FL_POWERUP)
441 float cells = GetResourceAmount(item, RESOURCE_CELLS);
442 if(cells > autocvar_g_instagib_ammo_drop && item.classname != "item_vaporizer_cells")
443 SetResourceAmount(item, RESOURCE_CELLS, autocvar_g_instagib_ammo_drop);
445 if(cells && !item.weapon)
451 MUTATOR_HOOKFUNCTION(mutator_instagib, CustomizeWaypoint)
453 entity wp = M_ARGV(0, entity);
454 entity player = M_ARGV(1, entity);
456 entity e = WaypointSprite_getviewentity(player);
458 // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
459 // but only apply this to real players, not to spectators
460 if((wp.owner.flags & FL_CLIENT) && (wp.owner.items & ITEM_Invisibility.m_itemid) && (e == player))
461 if(DIFF_TEAM(wp.owner, e))
465 MUTATOR_HOOKFUNCTION(mutator_instagib, PlayerDies)
467 float frag_deathtype = M_ARGV(3, float);
469 if(DEATH_ISWEAPON(frag_deathtype, WEP_VAPORIZER))
470 M_ARGV(4, float) = 1000; // always gib if it was a vaporizer death
473 MUTATOR_HOOKFUNCTION(mutator_instagib, ItemTouch)
475 entity item = M_ARGV(0, entity);
476 entity toucher = M_ARGV(1, entity);
478 if(GetResourceAmount(item, RESOURCE_CELLS))
480 // play some cool sounds ;)
481 float hp = GetResourceAmount(toucher, RESOURCE_HEALTH);
482 if (IS_CLIENT(toucher))
485 Send_Notification(NOTIF_ONE, toucher, MSG_ANNCE, ANNCE_INSTAGIB_LASTSECOND);
487 Send_Notification(NOTIF_ONE, toucher, MSG_ANNCE, ANNCE_INSTAGIB_NARROWLY);
491 SetResourceAmount(toucher, RESOURCE_HEALTH, 100);
493 return MUT_ITEMTOUCH_CONTINUE;
496 if(item.itemdef == ITEM_ExtraLife)
498 GiveResource(toucher, RESOURCE_ARMOR, autocvar_g_instagib_extralives);
499 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_EXTRALIVES);
500 return MUT_ITEMTOUCH_PICKUP;
503 return MUT_ITEMTOUCH_CONTINUE;
506 MUTATOR_HOOKFUNCTION(mutator_instagib, OnEntityPreSpawn)
508 if (!autocvar_g_powerups) { return; }
509 entity ent = M_ARGV(0, entity);
510 // Can't use .itemdef here
511 if (!(ent.classname == "item_strength" || ent.classname == "item_invincible" || ent.classname == "item_health_mega"))
519 e.classname = "item_invisibility";
520 setthink(e, instagib_invisibility);
524 e.classname = "item_extralife";
525 setthink(e, instagib_extralife);
529 e.classname = "item_speed";
530 setthink(e, instagib_speed);
533 e.nextthink = time + 0.1;
534 e.spawnflags = ent.spawnflags;
535 e.noalign = ent.noalign;
536 setorigin(e, ent.origin);
541 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsString)
543 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":instagib");
546 MUTATOR_HOOKFUNCTION(mutator_instagib, BuildMutatorsPrettyString)
548 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", instagib");
551 MUTATOR_HOOKFUNCTION(mutator_instagib, SetModname)
553 M_ARGV(0, string) = "InstaGib";