header general

Converting the Medical Backpack from ACS to ZScript

  • Salahmander
  • Salahmander's Avatar Topic Author
  • BFG Commando
  • BFG Commando
More
1 week 13 minutes ago #1 by Salahmander
Hiya, so looking to do the above in the title, but not sure how, anyone know how to go about it? Would be terrific for it to be all ZScript.

Please Log in or Create an account to join the conversation.

  • DeVloek
  • DeVloek's Avatar
  • Arachnotron
  • Arachnotron
More
6 days 10 hours ago - 6 days 10 hours ago #2 by DeVloek
Here's a zscript version of the item that uses GetMaxHealth() instead of the ACS script.

Code:
class HealthBackpack : Inventory {     Default     {         +INVENTORY.INVBAR;         +INVENTORY.ISHEALTH;         +INVENTORY.TRANSFER;         Inventory.Amount 100;         Inventory.MaxAmount 100;         Inventory.InterHubAmount 100;         Inventory.PickupMessage "You got a Health Backpack.";         Tag "Health Pack";         Inventory.Icon "I_MBPK";     }     States     {         Spawn:         MBPK A -1;         Stop;     }     override bool Use(bool pickup)     {         if (owner && owner.player)         {             int maxhp = owner.GetMaxHealth();             int curhp = owner.health;             int diff = maxhp - curhp;             if (diff > 0)             {                 S_StartSound("FKITUSE",CHAN_ITEM);                 owner.GiveBody(min(diff,owner.countinv("HealthBackpack")),maxhp);                 owner.TakeInventory("HealthBackpack",diff);             }         }         return false;     }          override void OnDrop(Actor dropper)     {         if (dropper && dropper.player)         {             int amount = dropper.countinv("HealthBackpack");             dropper.TakeInventory("HealthBackpack",amount);             SetInventory("HealthBackpack",amount);         }     } }


The original item had a bug, dropping the item dropped a backpack with 1 use in it, so you could drop 100 backpacks with 1 hp each. 
To fix this I added the TRANSFER flag and the OnDrop override, this retains the amount of uses when dropping the item and picking it back up.
The ISHEALTH flag is just to signal the game that the item shouldn't spawn when health items are turned off on a server.
I also noticed another mildly irritating thing. When the item has only 1 use left, the amount number is not displayed anymore. No idea how to fix this.

btw isn't it a bit irritating that the item is called Medical Backpack in the repo, but Health Backpack in the code and in the game? I think Medical Backpack sounds better, maybe we should rename it to that everywhere.
Last edit: 6 days 10 hours ago by DeVloek.

Please Log in or Create an account to join the conversation.

  • Salahmander
  • Salahmander's Avatar Topic Author
  • BFG Commando
  • BFG Commando
More
6 days 3 minutes ago #3 by Salahmander
Replied by Salahmander on topic Converting the Medical Backpack from ACS to ZScript
Ahhh you're a gem! Cheers matey, the medical backpack has been given it's repo name throughout now.

Please Log in or Create an account to join the conversation.

  • DeVloek
  • DeVloek's Avatar
  • Arachnotron
  • Arachnotron
More
5 days 5 hours ago #4 by DeVloek
No worries, happy to help :-)

Regarding the "bug" I described, I just looked the holodoomguy item and it has the same issue, only 1 unit out of 60 is dropped. But 60 is the seconds remaining so I need to fix this as well.

Are you aware of other items in the repo that have a large quantity of units, that should drop only 1 item with all units in it?

Please Log in or Create an account to join the conversation.