]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
LMS: fix megahealths from other games not getting replaced by extralife
authorterencehill <piuntn@gmail.com>
Sat, 6 May 2023 15:06:20 +0000 (17:06 +0200)
committerterencehill <piuntn@gmail.com>
Sat, 6 May 2023 15:06:20 +0000 (17:06 +0200)
qcsrc/common/gamemodes/gamemode/lms/sv_lms.qc

index 51df1bb2ae7a1aad68432909a87da9bd4a002044..692d987aa2d5a45427f0aefe3d963678f75b082f 100644 (file)
@@ -646,39 +646,33 @@ MUTATOR_HOOKFUNCTION(lms, FilterItemDefinition)
        if (autocvar_g_lms_items)
                return false;
 
-       entity definition = M_ARGV(0, entity);
+       entity def = M_ARGV(0, entity);
 
-       if (autocvar_g_lms_extra_lives && definition == ITEM_ExtraLife)
-       {
+       if (autocvar_g_powerups && autocvar_g_lms_extra_lives && (def == ITEM_ExtraLife || def == ITEM_HealthMega))
                return false;
-       }
        return (autocvar_g_pickup_items <= 0); // only allow items if explicitly enabled
 }
 
-void lms_extralife(entity this)
+void lms_replace_with_extralife(entity this)
 {
-       StartItem(this, ITEM_ExtraLife);
+       entity e = new(item_extralife);
+       Item_CopyFields(this, e);
+
+       StartItem(e, ITEM_ExtraLife);
 }
 
-MUTATOR_HOOKFUNCTION(lms, OnEntityPreSpawn)
+MUTATOR_HOOKFUNCTION(lms, FilterItem)
 {
-       if (MUTATOR_RETURNVALUE) return false;
-       if (!autocvar_g_powerups) return false;
-       if (!autocvar_g_lms_extra_lives) return false;
-
-       entity ent = M_ARGV(0, entity);
-
-       // Can't use .itemdef here
-       if (ent.classname != "item_health_mega") return false;
-
-       entity e = spawn();
-       setthink(e, lms_extralife);
-
-       Item_CopyFields(ent, e);
-
-       e.nextthink = time + 0.1;
+       entity item = M_ARGV(0, entity);
+       entity def = item.itemdef;
+       if(def == ITEM_HealthMega)
+       {
+               if(autocvar_g_powerups && autocvar_g_lms_extra_lives)
+                       lms_replace_with_extralife(item);
+               return true;
+       }
 
-       return true;
+       return false;
 }
 
 MUTATOR_HOOKFUNCTION(lms, ItemTouch)