Creating Armor with different elemental defenses <solved>

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!)
Post Reply
User avatar
deathzero021
Posts: 55
Joined: Wed Apr 24, 2019 7:36 am
Graphics Processor: nVidia with Vulkan support

Creating Armor with different elemental defenses <solved>

Post by deathzero021 »

So I'm working on an RPG mod for Hexen and I wanted to allow for different armors to have different defensive values for the various damage types.

For example:

Code: Select all

Iron_Chestplate:
Defense_Normal = 10;
Defense_Fire = 2;
Defense_Lightning = 1;
Defense_Magic = 4;
My problem isn't with the implementation of a custom inventory and such. The issue I have is in implementing the defense into damage calculation. I have thought of 2 approaches but neither seem to be completely possible and have major problems.

Approach 1:
Using the actor property "DamageFactor". This seems the most straight forward and logical approach as damage calculation would continue to be handled automatically. However as far as I can tell, there's NO way to change an actor's "DamageFactor" during gameplay. You can only seem to change the "generic" DamageFactor which applies to all (?) "DamageTypes". So this won't allow for different elemental "DamageFactors".

Approach 2:
Using user_vars (decorate) and calculating damage manually. In order to do this, AAPTR_TARGET and AAPTR_PLAYER_GETTARGET have to be used to get the victim's information (even this i'm not sure how feasible that is). This seems simple enough for melee attacks but doesn't seem possible for projectiles, since they won't have a target to point to and get information from. (And I can't find any functions for getting an actor in a collision)

Note: I am only familiar with DECORATE and ACS, so my thoughts here only reflect the possibilities of those two features. I do not know enough about Zscript to say if there's a different approach.

If anyone has any ideas, thoughts or input, I'd greatly appreciate it.

EDIT: Forgot to mention, the goal here was to implement a 4 piece armor system. So I wanted to adjust the player actor's defensive values.

EDIT2: Thread has been solved. A viable method can be found below.
Last edited by deathzero021 on Tue Oct 15, 2019 2:06 am, edited 2 times in total.
User avatar
Cherno
Posts: 1337
Joined: Tue Dec 06, 2016 11:25 am

Re: Creating Armor with different elemental defenses

Post by Cherno »

In Zscript, override DamageMobj and compare the damagetype with the armor that is equipped, and modify the return value accordingly.
User avatar
Void Weaver
Posts: 724
Joined: Thu Dec 18, 2014 7:15 am
Contact:

Re: Creating Armor with different elemental defenses

Post by Void Weaver »

What's problem here?

The basic BasicArmorPickup allows to define a custom DamageFactors:

Code: Select all

Actor Iron_Chestplate : BasicArmorPickup
{
Armor.SaveAmount 300
Armor.SavePercent 50
DamageFactor "Normal",0.1 //Defense_Normal = 10;
DamageFactor "Fire",0.5 //Defense_Fire = 2;
DamageFactor "Lightning",1.0 //Defense_Lightning = 1;
DamageFactor "Magic",0.25 //Defense_Magic = 4;
States
  {
  Spawn:
    ARM5 A 6
    ARM5 B 7 bright
    Loop
  }
}
WARNING! DamageFactor "None" != DamageFactor "Normal", since "Normal" ISN'T DamageType at all!
---
Also you can precisely recalculate specific DamageFactor from specific item with specific DamageType via ApplyDamageFactors.
---
Other way is to use CustomInventory wrapper with a some armor and PowerProtection (as long as you have this wrapper), but apparently it's redundant in your case.
User avatar
deathzero021
Posts: 55
Joined: Wed Apr 24, 2019 7:36 am
Graphics Processor: nVidia with Vulkan support

Re: Creating Armor with different elemental defenses

Post by deathzero021 »

Void Weaver wrote:What's problem here?
...
I suppose I forgot to mention, I wanted multiple armor pieces the player can equip. So the final resulting DamageFactor would need to be a sum of all the pieces. So BasicArmorPickup wouldn't exactly help. However, your suggestion is a nice thing to fall back on if I can't figure out a way to implement armor pieces. It certainly would be much easier to deal with if I just go with a one armor piece system.
User avatar
Void Weaver
Posts: 724
Joined: Thu Dec 18, 2014 7:15 am
Contact:

Re: Creating Armor with different elemental defenses

Post by Void Weaver »

Oh, it's very important thing, then define each piece as standalone CustomInventory with different PowerProtection, and don't forget that final DamageFactor of the same DamageType calculates multiplicative.
That means DamageFactor Fire, 0.5 (50% def) + DamageFactor Fire, 0.2 (80% def) = 0.5*0.2 = 0.1 (90% def).
Last edited by Void Weaver on Tue Oct 15, 2019 12:36 am, edited 1 time in total.
User avatar
deathzero021
Posts: 55
Joined: Wed Apr 24, 2019 7:36 am
Graphics Processor: nVidia with Vulkan support

Re: Creating Armor with different elemental defenses

Post by deathzero021 »

Void Weaver wrote:Oh, it's very important thing, but the BasicArmorPickup is still solution for your goal. :) Just define each piece as standalone armor (or CustomInventory), and don't forget that final DamageFactor of the same DamageType calculates multiplicative.
That means DamageFactor Fire, 0.5 (50% def) + DamageFactor Fire, 0.2 (80% def) = 0.5*0.2 = 0.1 (90% def).
Hmm didn't think that was possible. I'll do more reading on BasicArmorPickup than. Thanks for the help!
User avatar
Void Weaver
Posts: 724
Joined: Thu Dec 18, 2014 7:15 am
Contact:

Re: Creating Armor with different elemental defenses

Post by Void Weaver »

Sorry, I just forgot about that
BasicArmorPickups are armor items that replace any existing armor with themselves if the player's armor points are less than this item provides.
So in your case solution is CInventory w PProtection.
User avatar
deathzero021
Posts: 55
Joined: Wed Apr 24, 2019 7:36 am
Graphics Processor: nVidia with Vulkan support

Re: Creating Armor with different elemental defenses

Post by deathzero021 »

Void Weaver wrote:Sorry, I just forgot about that
BasicArmorPickups are armor items that replace any existing armor with themselves if the player's armor points are less than this item provides.
So in your case solution is CInventory w PProtection.
That's exactly why I didn't consider BasicArmorPickup in the first place. :roll:

I'll look more into PowerProtection. At first glance it didn't seem like a good fit, considering it's a bit unintuitive to use for armor pieces. Especially considering things might get tricky with powerup.duration and unequipping armor.
User avatar
Void Weaver
Posts: 724
Joined: Thu Dec 18, 2014 7:15 am
Contact:

Re: Creating Armor with different elemental defenses

Post by Void Weaver »

Well, I've mistaken a bit. You can just use BasicArmorBonus instead of BasicArmorPickup, without any PProtection.
Spoiler: It's 6 different parts of armor with different resistances which will give the Iron_Chestplate when full set is gathered
EDIT:
Fixed, now it works properly.
Last edited by Void Weaver on Tue Oct 15, 2019 10:53 am, edited 2 times in total.
User avatar
deathzero021
Posts: 55
Joined: Wed Apr 24, 2019 7:36 am
Graphics Processor: nVidia with Vulkan support

Re: Creating Armor with different elemental defenses

Post by deathzero021 »

Void Weaver wrote:Well, I've mistaken a bit. You can just use BasicArmorBonus instead of BasicArmorPickup, without any PProtection.
Spoiler: It's 6 different parts of armor with different resistances which will give the Iron_Chestplate when full set is gathered
That's a pretty strange approach and would get way too complicated to deal with in the long run when making many different armors in the game.

However, I got a working system in place now. Using PowerProtection and PowerupGiver:

Code: Select all

actor StatChestplateIron : PowerProtection
	{
	DamageFactor "Normal", 0.9
	DamageFactor "Fire", 0.5
	inventory.icon "AR_1A0"
	}

actor ArmorChestplateIron : PowerupGiver
	{
	inventory.pickupmessage "Equipped Chestplate (Iron)"
	powerup.duration 0x7FFFFF00
	powerup.type "StatChestplateIron"
	
	+INVENTORY.AUTOACTIVATE
	
	States
		{
		Spawn:
			AR_1 A -1
			Loop
		}
	}
So using PowerProtection to define the stats of the armor piece, and using PowerupGiver as the item you can pickup (and stores in your inventory). And removing the armor piece is as simple as removing it from the inventory using take ArmorChestplateIron, which also removes the Powerup it's associated with. I've tested it with multiple different armor pieces at once and the DamageFactors do stack properly.

This is a pretty easy, straight forward approach that's well organized. Of course using this method, there is no basic doom armor absorption, and no armor durability. Although that could be handled manually if desired. (I won't be bothering with durability)

Consider this thread solved. Thanks for the help Void Weaver.
User avatar
Void Weaver
Posts: 724
Joined: Thu Dec 18, 2014 7:15 am
Contact:

Re: Creating Armor with different elemental defenses <solved

Post by Void Weaver »

Well, I've use 6 part for my own choise, no more. You can reduce this kinds amount for your wish, also my method take in account both armor durability and dmg reduce, if any. Therefore it looks a bit massive.
---
Anyway grats for success. ^_^
User avatar
CBM
Posts: 373
Joined: Wed Oct 09, 2019 3:39 am
Graphics Processor: nVidia with Vulkan support
Location: The Shores of Hell

Re: Creating Armor with different elemental defenses <solved

Post by CBM »

congrats on getting it to work, I have had some trouble getting anything with a typed damage to work as intended
Post Reply

Return to “Scripting”