Merge branch 'martin-t/ok_weap' into 'master'
authorMario <zacjardine@y7mail.com>
Mon, 2 Jan 2017 08:05:02 +0000 (08:05 +0000)
committerMario <zacjardine@y7mail.com>
Mon, 2 Jan 2017 08:05:02 +0000 (08:05 +0000)
overkill: take into account last weapon held when switching while dead

Closes #1728

See merge request !400

qcsrc/common/mutators/mutator/overkill/sv_overkill.qc
qcsrc/server/client.qc
qcsrc/server/mutators/events.qh

index 501b3af..5897653 100644 (file)
@@ -171,17 +171,6 @@ MUTATOR_HOOKFUNCTION(ok, PlayerPreThink)
        if(IS_DEAD(player) || !IS_PLAYER(player) || STAT(FROZEN, player))
                return;
 
-       if(player.ok_lastwep)
-       {
-               Weapon newwep = Weapons_from(player.ok_lastwep);
-               if(player.ok_lastwep == WEP_HMG.m_id)
-                       newwep = WEP_MACHINEGUN;
-               if(player.ok_lastwep == WEP_RPC.m_id)
-                       newwep = WEP_VORTEX;
-               PS(player).m_switchweapon = newwep;
-               player.ok_lastwep = 0;
-       }
-
        ok_IncreaseCharge(player, PS(player).m_weapon.m_id);
 
        if(PHYS_INPUT_BUTTON_ATCK2(player))
@@ -248,10 +237,22 @@ MUTATOR_HOOKFUNCTION(ok, PlayerSpawn)
        }
        else
                player.ok_use_ammocharge = 0;
+}
 
-       // if player changed their weapon while dead, don't switch to their death weapon
-       if(player.impulse)
+MUTATOR_HOOKFUNCTION(ok, PlayerWeaponSelect)
+{
+       entity player = M_ARGV(0, entity);
+
+       if(player.ok_lastwep)
+       {
+               Weapon newwep = Weapons_from(player.ok_lastwep);
+               if(player.ok_lastwep == WEP_HMG.m_id)
+                       newwep = WEP_MACHINEGUN;
+               if(player.ok_lastwep == WEP_RPC.m_id)
+                       newwep = WEP_VORTEX;
+               PS(player).m_switchweapon = newwep;
                player.ok_lastwep = 0;
+       }
 }
 
 void self_spawnfunc_weapon_hmg(entity this) { spawnfunc_weapon_hmg(this); }
index d4a3e9f..c1cce0c 100644 (file)
@@ -706,6 +706,8 @@ void PutClientInServer(entity this)
                this.weaponname = "";
                PS(this).m_switchingweapon = WEP_Null;
 
+               MUTATOR_CALLHOOK(PlayerWeaponSelect, this);
+
                if (!warmup_stage && !this.alivetime)
                        this.alivetime = time;
 
index 499110e..2bea200 100644 (file)
@@ -31,6 +31,12 @@ MUTATOR_HOOKABLE(ForbidSpawn, EV_ForbidSpawn);
     /**/
 MUTATOR_HOOKABLE(PlayerSpawn, EV_PlayerSpawn);
 
+/** called after a player's weapon is chosen so it can be overriden here */
+#define EV_PlayerWeaponSelect(i, o) \
+       /** player spawning */ i(entity, MUTATOR_ARGV_0_entity) \
+    /**/
+MUTATOR_HOOKABLE(PlayerWeaponSelect, EV_PlayerWeaponSelect);
+
 /** called in reset_map */
 #define EV_reset_map_global(i, o) \
     /**/