Advertisement
Guest User

Untitled

a guest
Nov 8th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 KB | None | 0 0
  1. class GreenArmorPickup : GreenArmor {} //copied class so we can still use GreenArmor under another name
  2.  
  3. class ArmorWrapper : CustomInventory
  4. {
  5.     action bool DoPickup(int amount, double percent, string pickup)
  6.     {
  7.         //store some relevant references
  8.         let p = players[consoleplayer].mo;                      //playerpawn actor
  9.         let armor = BasicArmor(p.FindInventory("BasicArmor"));  //player's armor
  10.        
  11.         /*
  12.         If you want to add global cases where armor should always be picked up, here is the spot
  13.         for example, you could check to see if the player's HP is below a certain value, then
  14.         return true if it is.
  15.         */
  16.        
  17.         // Copied from ZS source, accounts for null case. Shouldn't ever be tripped but whatever
  18.         if (armor == null)
  19.         {
  20.             armor = BasicArmor(Spawn("BasicArmor"));
  21.             armor.BecomeItem();
  22.             armor.Amount = 0;
  23.             armor.MaxAmount = 0;
  24.             p.AddInventory(armor);
  25.         }
  26.        
  27.         /*
  28.         This measures the current amount of damage the player can absorb with his armor at a given health
  29.         it assumes no healing takes place, so there are cases where it may block a green->green or blue->blue
  30.         on the grounds that the current armor protects the player adequately at their current health
  31.         */
  32.         double currentSaveAmount = min(armor.Amount, p.player.health)*armor.SavePercent;
  33.         double newSaveAmount = min(amount, p.player.health) * percent;//0.333350;
  34.        
  35.         if(newSaveAmount > currentSaveAmount)
  36.         {
  37.             p.A_GiveInventory(pickup);
  38.             return true;
  39.         }
  40.         return false;
  41.     }
  42. }
  43.  
  44. class GreenArmorWrapper : ArmorWrapper Replaces GreenArmor
  45. {
  46.     default
  47.     {
  48.         /*
  49.         Make sure you fill in these variables so the size is right and the messages appear
  50.         */
  51.         Radius 20;
  52.         Height 16;
  53.         Inventory.PickupMessage "$GOTARMOR";
  54.     }
  55.     States
  56.     {
  57.         //Looping state for while we're on the ground
  58.         Spawn:
  59.             ARM1 A 6;
  60.             ARM1 B 7 Bright;
  61.             Loop;
  62.         //Pickup state, obviously
  63.         Pickup:
  64.             TNT1 A 0
  65.             {
  66.                 //Boolean check to see if we should pick up the armor based on its attributes
  67.                 if(DoPickup(100, 0.333350, "GreenArmorPickup"))
  68.                 {
  69.                     return ResolveState(null);
  70.                 }
  71.                 return ResolveState("Spawn");
  72.             }
  73.             //This frame needs to be here for some reason as listed on the wiki.
  74.             TNT1 A 0 A_RailWait(); //does nothing
  75.             Stop;
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement