From: Mario Date: Fri, 12 Oct 2018 19:44:54 +0000 (+1000) Subject: When using specific weapon binds, if the player doesn't have the weapon, attempt... X-Git-Tag: xonotic-v0.8.5~1759^2~1 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=293777db9bd54478f88c29339f39756307a6929a;p=xonotic%2Fxonotic-data.pk3dir.git When using specific weapon binds, if the player doesn't have the weapon, attempt to switch to another weapon within the same group --- diff --git a/qcsrc/server/impulse.qc b/qcsrc/server/impulse.qc index cce596399..8a17ef6a1 100644 --- a/qcsrc/server/impulse.qc +++ b/qcsrc/server/impulse.qc @@ -149,7 +149,7 @@ X(9, next) for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) \ { \ .entity weaponentity = weaponentities[slot]; \ - W_SwitchWeapon(this, Weapons_from(WEP_FIRST + i), weaponentity); \ + W_SwitchWeapon_TryOthers(this, Weapons_from(WEP_FIRST + i), weaponentity); \ if(slot == 0 && autocvar_g_weaponswitch_debug != 1) \ break; \ } \ diff --git a/qcsrc/server/weapons/selection.qc b/qcsrc/server/weapons/selection.qc index 4af13e102..baee4ac53 100644 --- a/qcsrc/server/weapons/selection.qc +++ b/qcsrc/server/weapons/selection.qc @@ -282,6 +282,25 @@ void W_SwitchWeapon(entity this, Weapon w, .entity weaponentity) } } +void W_SwitchWeapon_TryOthers(entity this, Weapon w, .entity weaponentity) +{ + if(this.(weaponentity).m_switchweapon != w) + { + if(client_hasweapon(this, w, weaponentity, true, true)) // NOTE: still complains + W_SwitchWeapon_Force(this, w, weaponentity); + else + { + this.(weaponentity).selectweapon = w.m_id; // update selectweapon anyway + W_NextWeaponOnImpulse(this, w.impulse, weaponentity); + } + } + else if(!forbidWeaponUse(this)) + { + entity actor = this; + w.wr_reload(w, actor, weaponentity); + } +} + void W_CycleWeapon(entity this, string weaponorder, float dir, .entity weaponentity) { float w; diff --git a/qcsrc/server/weapons/selection.qh b/qcsrc/server/weapons/selection.qh index eea33ddb7..156c37f26 100644 --- a/qcsrc/server/weapons/selection.qh +++ b/qcsrc/server/weapons/selection.qh @@ -19,6 +19,7 @@ void W_SwitchWeapon_Force(Player this, Weapon w, .entity weaponentity); // perform weapon to attack (weaponstate and attack_finished check is here) void W_SwitchToOtherWeapon(entity this, .entity weaponentity); void W_SwitchWeapon(entity this, Weapon imp, .entity weaponentity); +void W_SwitchWeapon_TryOthers(entity this, Weapon imp, .entity weaponentity); void W_CycleWeapon(entity this, string weaponorder, float dir, .entity weaponentity);