Getting/restoring player's armor

Discuss all aspects of editing for ZDoom.
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.

Getting/restoring player's armor

Postby DBThanatos » Thu Apr 12, 2012 12:55 pm

Im morphing the player, but Im trying to keep the armor the same whether is morphed or not.

I searched and found what seems to be the right functions. However, I have been trying this:
Code: Select allExpand view
armoramount=GetArmorType("GreenArmor",0);

...

GiveInventory("GreenArmor",armoramount);


But turns out I'll get disproportionate amounts of armor, presumably because if I have 100 points of armor, at the moment of the morph, value 100 is stored, then I get 100 green armors, which gives me in total 10,000. By the time I try again, I reach some really big number.

I was reading in the "GiveInventory" that "health and armor it will give the total number". But this isnt happening.

What am I doing wrong here?
User avatar
DBThanatos
Guns, explosions, gore.
 
Joined: 14 Apr 2006
Location: in "the darkness that lurks in our mind"

Re: Getting/restoring player's armor

Postby Xaser » Thu Apr 12, 2012 2:38 pm

What's happening is that you're not actually giving armor, but a BasicArmorPickup (which is what GreenArmor inherits from). The amount of armor to actually give from each pickup is defined not by Inventory.Amount but by Armor.SaveAmount, so the standard 'amount' parameter literally translates to "give the player 100 items of this type." Armor itself is represented by the internal class BasicArmor, but you're not supposed to use that directly.

The simplest way is to define a new BasicArmorPickup with the correct SavePercent and an Armor.SaveAmount of 1 -- you can probably just inherit from GreenArmor and save a step. Not the most desirable way of having to do things, but it's more or less the best solution at this point.
User avatar
Xaser
secretly a supercomputer being a government
 
Joined: 20 Jul 2003
Location: .plɹoʍɹǝʌǝu.

Re: Getting/restoring player's armor

Postby NeuralStunner » Thu Apr 12, 2012 3:36 pm

Xaser wrote:The simplest way is to define a new BasicArmorPickup with the correct SavePercent and an Armor.SaveAmount of 1 -- you can probably just inherit from GreenArmor and save a step. Not the most desirable way of having to do things, but it's more or less the best solution at this point.
You'd have to use a modified BasicArmorBonus in that case, since a standard armor will never normally stack beyond its SaveAmount.
User avatar
NeuralStunner
O'Neill with it.
 
Joined: 21 Jul 2009
Location: The Colonies

Re: Getting/restoring player's armor

Postby Xaser » Thu Apr 12, 2012 7:13 pm

If that was the case, he wouldn't be ending up with 10,000 armor in the first place. It'd just be 100 each time.

The trouble with BasicArmorBonus, too, is that bonuses are only applied as a stack to the player's current armor. SavePercent only applies if the player has no armor when picking one up (hence why Doom's Armor bonuses award the player additional blue armor if he's wearing blue armor despite having a SavePercent of 0.33). Though I suppose it'd be safe to use in this case under the assumption that the player has no armor at all immediately after unmorph.
User avatar
Xaser
secretly a supercomputer being a government
 
Joined: 20 Jul 2003
Location: .plɹoʍɹǝʌǝu.

Re: Getting/restoring player's armor

Postby Kate » Thu Apr 12, 2012 7:22 pm

Xaser wrote:Though I suppose it'd be safe to use in this case under the assumption that the player has no armor at all immediately after unmorph.

Unfortunately, that can't really be guaranteed unless one does a "TakeInventory ("BasicArmor", [biggest amount the player can have])", because with the way the morphing system works, it only strips the armor that you previously had at the beginning of a morph, so when a morph ends, you will remain with whatever armor you had when you were morphed, which can happen if the class the player is changed into can +PICKUP items.

I'm not sure why it strips your armor when you change but DOESN'T strip it when you change back, but there you go.
User avatar
Kate
Will love and tolerate THE SHIT out of you
 
Joined: 15 Jul 2003
Location: New Jersey, US

Re: Getting/restoring player's armor

Postby Xaser » Thu Apr 12, 2012 9:01 pm

Huh, there you go. The fact that you keep armor when unmorphing totally slipped past my radar. Might actually make things easier on DBT's side though. ;)

Hmm, what's funny is that I actually set up a lot of this stuff myself for Necrodoom and seem to have completely forgotten how it all works. Oy vey. :P
User avatar
Xaser
secretly a supercomputer being a government
 
Joined: 20 Jul 2003
Location: .plɹoʍɹǝʌǝu.

Re: Getting/restoring player's armor

Postby NeuralStunner » Thu Apr 12, 2012 9:18 pm

Xaser wrote:If that was the case, he wouldn't be ending up with 10,000 armor in the first place. It'd just be 100 each time.
I seem to have missed half the issue here. If you're getting more than MaxSaveAmount of the armor in any case, that smells very bugtastic.
User avatar
NeuralStunner
O'Neill with it.
 
Joined: 21 Jul 2009
Location: The Colonies

Re: Getting/restoring player's armor

Postby DBThanatos » Fri Apr 13, 2012 12:55 am

Allright. I think I get it, yet this sounds a little counterintuitive. I tried this earlier:

Code: Select allExpand view
Actor GreenArmorHack : CustomInventory
{
+INVENTORY.AUTOACTIVATE
Inventory.MaxAmount 1
States
{
   Spawn:
      ARM1 A 6
      ARM1 B 7 bright
      loop
   Use:
      TNT1 A 0 A_GiveInventory("GreenArmorUnit",100)
      Stop
   }
}

Actor GreenArmorUnit : GreenArmor
{Armor.Saveamount 1}


The "armorhack" is basically to completely replace "GreenArmor". But found out that I get only one armor point (vs giving it via ACS which gives me 100). Im not totally getting how this works, but for how it looks, I will have to go something like this

-Store "GreenArmor" amount under "armoramount"
-Morph player
-Give "GreenArmorUnit" times "armoramount"

...and let it be (that's assuming it does keep the armor when it unmorphs as kate mentioned).

Then, when morphing again, instead of storing "GreenArmor" I'll have to store "GreenArmorUnit"... Ok, Im getting confused indeed :P
User avatar
DBThanatos
Guns, explosions, gore.
 
Joined: 14 Apr 2006
Location: in "the darkness that lurks in our mind"

Re: Getting/restoring player's armor

Postby DBThanatos » Fri Apr 13, 2012 2:22 am

Confirmed. There seems to be something not really consistent, or DECORATE and ACS follow rules completely different.

Code: Select allExpand view
Actor GreenArmorHack : CustomInventory
{
+INVENTORY.AUTOACTIVATE
Inventory.MaxAmount 1
States
{
   Spawn:
      ARM1 A 6
      ARM1 B 7 bright
      loop
   Use:
      TNT1 A 0 A_GiveInventory("GreenArmorUnit",100)
      Stop
   }
}

Actor GreenArmorUnit : GreenArmor
{Armor.Saveamount 1}


Upon picking "GreenArmorHack" I get 1 armor point.

But using
Code: Select allExpand view
Actor GreenArmorHack : CustomInventory
{
+INVENTORY.AUTOACTIVATE
Inventory.MaxAmount 1
States
{
   Spawn:
      ARM1 A 6
      ARM1 B 7 bright
      loop
   Use:
      TNT1 A 0 ACS_NamedExecute("GiveGreenArmor",0,0,0,0)
      Stop
   }
}

Actor GreenArmorUnit : GreenArmor
{Armor.Saveamount 1}

// ACS Script
Script "GiveGreenArmor" (void)
{
   GiveInventory("GreenArmorUnit",100);
}


I get 100 points of armor. This is sounding more like a bug to me than ever before.
User avatar
DBThanatos
Guns, explosions, gore.
 
Joined: 14 Apr 2006
Location: in "the darkness that lurks in our mind"

Re: Getting/restoring player's armor

Postby DBThanatos » Fri Apr 13, 2012 12:59 pm

So, to make it work, I had to apply all sorts of hacks.

For anyone interested:

Spoiler:
User avatar
DBThanatos
Guns, explosions, gore.
 
Joined: 14 Apr 2006
Location: in "the darkness that lurks in our mind"

Re: Getting/restoring player's armor

Postby NeuralStunner » Fri Apr 13, 2012 2:58 pm

To correct my earlier remarks: MaxSaveAmount is native to BasicArmorBonus, where it is enforced as expected. For a BasicArmorPickup, SaveAmount fills this role in most cases (picking it up or giving through console). In the errant case where that fails, I think it should be reported as a bug. I don't think a hack should be necessary.

Assmuing it's not desirable to lose items collected while morphed*, maximums should at least be enforced instead of tacking on the new stuff without checking. Does Ammo have the same problem, by the way?


* I'm not sure how common a practice it is to allow pickups for morphed classes. Regardless, reverting post-morph inventory might be a good candidate for a new morph flag.
User avatar
NeuralStunner
O'Neill with it.
 
Joined: 21 Jul 2009
Location: The Colonies

Re: Getting/restoring player's armor

Postby Xaser » Fri Apr 13, 2012 3:55 pm

Oh dear. Why did you go about replacing GreenArmor entirely? I was trying to suggest inheriting from it, changing the SavePercent to 1, then giving that item instead.
User avatar
Xaser
secretly a supercomputer being a government
 
Joined: 20 Jul 2003
Location: .plɹoʍɹǝʌǝu.

Re: Getting/restoring player's armor

Postby DBThanatos » Sat Apr 14, 2012 1:38 pm

SavePercent to 1? as in it will absorb 1% of the damage? I thought you meant SaveAmount. I did try with save amount, but I ended having two different armor types (say, the actual green armor, and then it's "pieces") to check with GetArmorType. All in all this has gotten overly messy, not because of that, but because of extra checks now required to ensure the values stored are the same that will be applied when the player unmorphs after it failed.

I might as well forget about this whole thing, hoping this gets added one day, and in the meantime, move in a different direction. Each subsequent issue that I find about this, is giving me headaches. :blergh:
User avatar
DBThanatos
Guns, explosions, gore.
 
Joined: 14 Apr 2006
Location: in "the darkness that lurks in our mind"


Return to Editing

Who is online

Users browsing this forum: Baidu [Spider] and 2 guests