[Zscript] Monster Armor regeneration

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
User avatar
JUSSOMONE
Posts: 29
Joined: Fri Oct 07, 2022 8:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia (Modern GZDoom)

[Zscript] Monster Armor regeneration

Post by JUSSOMONE »

As the title implies, I've been trying with no avail to create an Armor that have regenerative purposes, think of it like a force field...I think it have something to do with the BasicArmorPickup that it will only accept another one of the same type and it dosen't work adding a BasicArmorbonus to increment it...

Here is the armor code:

Code: Select all

class EnergyShield : BasicArmorPickup
{
    Default
	{
	      // PROPERTY
	      DamageFactor "LCaliber",      0.0;  //Immune
              DamageFactor "MCaliber",      0.0;  //Immune
	      DamageFactor "HCaliber",      0.0;  //Immune
              DamageFactor "Explosive",     0.0;  //Immune
	      DamageFactor "KExplosive",    0.0;  //Immune
	      DamageFactor "Fire",          0.0;  //Immune
	      DamageFactor "Laser",         1.0;  //Vulnerable
              Armor.SaveAmount              300; //300
              Armor.SavePercent             100;   
    }
    States                   
    {                      
    Spawn:                   
       TNT1 A 1;
       Loop;
    }

    override bool Use(bool pickup)
    {
        bool result = Super.Use(pickup);

        // If pickup has succeeded, give the FX item too.
        if (result)
        {
            Owner.GiveInventory('EnergyShieldFX', 1);
        }

        return result;
    }
}

class EnergyShieldFX : Inventory
{
    Default
    {
        // Prevent sudden removal of the item.
        +INVENTORY.UNCLEARABLE;
    }

    override void AbsorbDamage(int damage, Name damageType, out int newdamage, Actor inflictor, Actor source, int flags)
    {
        // If the enemy is wearing the armor, play the special sound.
        if (OwnerHasEnergyShield())
        {
            Owner.A_StartSound("Armor/Energy_Shield", CHAN_BODY);
        }
    }
    
    override void Tick()
    {
        Super.Tick();
		
	// If the enemy doesn't have the armor anymore, destroy the FX item.
        If (!OwnerHasEnergyShield())
        {
			Destroy();
        }
    }

    private bool OwnerHasEnergyShield()
    {
        // Check that the player still has the corresponding armor type
        // and the amount is non-zero.
        if (Owner != null)
        {
            let ba = BasicArmor(Owner.FindInventory('BasicArmor'));
           
            if (ba != null)
            {
                return ba.Amount > 0 && ba.ArmorType == 'EnergyShield';
            }
        }

        return false;
    }
}
And finally the enemy that have it:

Code: Select all

        CODE CODE CODE CODE CODE
        CODE CODE CODE CODE CODE...
        
	override void PostBeginPlay()
	{
		super.PostBeginPlay();

		// Began already with armor whitout waiting for his first frame.
		GiveInventory("EnergyShield", 1);
       }
       Override void Tick()
       {
	      Super.Tick(); //Call original in case of another override
		  {
		        //Heal every fifteen tics
		        If (Level.Time%15 == 0 && FindInventory("EnergyShieldFX") && Health > 0)
				{
				      GiveInventory("BasicArmorBonus", 5);
				}
		  }
	}
	CODE CODE CODE CODE CODE
        CODE CODE CODE CODE CODE...
By giving the actor the EnergyShield he will automatically receive the EnergyShieldFX too since it's included in the override bool use (bool pickup) so, I don't understand what I am doing wrong here, since it seems fine to me...
Blue Shadow
Posts: 5019
Joined: Sun Nov 14, 2010 12:59 am

Re: [Zscript] Monster Armor regeneration

Post by Blue Shadow »

The problem with BasicArmorBonus is that its MaxSaveAmount is 0, which makes it useless. So create a new type of BasicArmorBonus, set its MaxSaveAmount to 300 (I'd imagine you wouldn't want it to go beyond the armor's own SaveAmount), and use that instead of BasicArmorBonus for regeneration.

Return to “Scripting”