]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
If the player has no weapon, return "none" in the chat, also report health 2342 as...
authorMario <mario.mario@y7mail.com>
Mon, 30 Dec 2019 14:53:05 +0000 (00:53 +1000)
committerMario <mario.mario@y7mail.com>
Mon, 30 Dec 2019 14:53:05 +0000 (00:53 +1000)
qcsrc/server/miscfunctions.qc

index 38ce9f3e5fe79434c6d4f0a37742ac3367556449..6082dbc9baf376b02ad6028a3b29036ba6096ac4 100644 (file)
@@ -7,6 +7,7 @@
 #include "ipban.qh"
 #include <server/mutators/_mod.qh>
 #include "../common/t_items.qh"
+#include "mapvoting.qh"
 #include "resources.qh"
 #include "items.qh"
 #include "player.qh"
@@ -233,13 +234,25 @@ string PlayerHealth(entity this)
        float myhealth = floor(GetResource(this, RES_HEALTH));
        if(myhealth == -666)
                return "spectating";
-       else if(myhealth == -2342)
+       else if(myhealth == -2342 || (myhealth == 2342 && mapvote_initialized))
                return "observing";
        else if(myhealth <= 0 || IS_DEAD(this))
                return "dead";
        return ftos(myhealth);
 }
 
+string WeaponNameFromWeaponentity(entity this, .entity weaponentity)
+{
+       entity wepent = this.(weaponentity);
+       if(!wepent)
+               return "none";
+       else if(wepent.m_weapon != WEP_Null)
+               return wepent.m_weapon.m_name;
+       else if(wepent.m_switchweapon != WEP_Null)
+               return wepent.m_switchweapon.m_name;
+       return "none"; //Weapons_from(wepent.cnt).m_name;
+}
+
 string formatmessage(entity this, string msg)
 {
        float p, p1, p2;
@@ -297,7 +310,7 @@ string formatmessage(entity this, string msg)
                        case "l": replacement = NearestLocation(this.origin); break;
                        case "y": replacement = NearestLocation(cursor); break;
                        case "d": replacement = NearestLocation(this.death_origin); break;
-                       case "w": replacement = ((this.(weaponentity).m_weapon == WEP_Null) ? ((this.(weaponentity).m_switchweapon == WEP_Null) ? Weapons_from(this.(weaponentity).cnt) : this.(weaponentity).m_switchweapon) : this.(weaponentity).m_weapon).m_name; break;
+                       case "w": replacement = WeaponNameFromWeaponentity(this, weaponentity); break;
                        case "W": replacement = AmmoNameFromWeaponentity(this.(weaponentity).m_weapon); break;
                        case "x": replacement = ((cursor_ent.netname == "" || !cursor_ent) ? "nothing" : cursor_ent.netname); break;
                        case "s": replacement = ftos(vlen(this.velocity - this.velocity_z * '0 0 1')); break;