]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/gamemodes/gamemode/lms/sv_lms.qc
Merge branch 'terencehill/lms_spec' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / gamemodes / gamemode / lms / sv_lms.qc
index 7139a7b2e134ccd45a47365dbad9d732b6f76f44..348262e76c231cd7d60d1ebe68bc3b8edd8e68ed 100644 (file)
@@ -647,42 +647,36 @@ MUTATOR_HOOKFUNCTION(lms, ForbidPlayerScore_Clear)
 
 MUTATOR_HOOKFUNCTION(lms, FilterItemDefinition)
 {
-       if (autocvar_g_lms_items)
+       if (autocvar_g_lms_items || autocvar_g_pickup_items > 0)
                return false;
 
-       entity definition = M_ARGV(0, entity);
-
-       if (autocvar_g_lms_extra_lives && definition == ITEM_ExtraLife)
-       {
+       entity def = M_ARGV(0, entity);
+       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)
-{
-       StartItem(this, ITEM_ExtraLife);
+       return true;
 }
 
-MUTATOR_HOOKFUNCTION(lms, OnEntityPreSpawn)
+void lms_replace_with_extralife(entity this)
 {
-       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 = new(item_extralife);
+       Item_CopyFields(this, e);
 
-       entity e = spawn();
-       setthink(e, lms_extralife);
-
-       Item_CopyFields(ent, e);
+       StartItem(e, ITEM_ExtraLife);
+}
 
-       e.nextthink = time + 0.1;
+MUTATOR_HOOKFUNCTION(lms, FilterItem)
+{
+       entity item = M_ARGV(0, entity);
+       entity def = item.itemdef;
+       if(def == ITEM_HealthMega && !(autocvar_g_lms_items || autocvar_g_pickup_items > 0))
+       {
+               if(autocvar_g_powerups && autocvar_g_lms_extra_lives)
+                       lms_replace_with_extralife(item);
+               return true;
+       }
 
-       return true;
+       return false;
 }
 
 MUTATOR_HOOKFUNCTION(lms, ItemTouch)
@@ -696,6 +690,7 @@ MUTATOR_HOOKFUNCTION(lms, ItemTouch)
        {
                Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_EXTRALIVES, autocvar_g_lms_extra_lives);
                GameRules_scoring_add(toucher, LMS_LIVES, autocvar_g_lms_extra_lives);
+               Inventory_pickupitem(item.itemdef, toucher);
                return MUT_ITEMTOUCH_PICKUP;
        }