Armor Regeneration Script [SOLVED]
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Armor Regeneration Script [SOLVED]
For my mod, instead of having armor pickups scattered around the map for the player to collect, I'd like to implement a script that does the following:
1. Player starts automatically with 100% armor at the beginning of the map.
2. When the armor drops below 100%, wait 5 seconds. If not taking damage, start regenerating armor at a rate of 1% per second.
3. Armor regeneration stops at 100%.
How do I make it happen? Does it require ACS scripting? While I can do the most basic stuff in DECORATE, I have no experience with ACS and quite frankly couldn't wrap my head around it. Any help would be appreciated.
1. Player starts automatically with 100% armor at the beginning of the map.
2. When the armor drops below 100%, wait 5 seconds. If not taking damage, start regenerating armor at a rate of 1% per second.
3. Armor regeneration stops at 100%.
How do I make it happen? Does it require ACS scripting? While I can do the most basic stuff in DECORATE, I have no experience with ACS and quite frankly couldn't wrap my head around it. Any help would be appreciated.
Last edited by P.Rex on Fri Aug 26, 2016 1:40 pm, edited 1 time in total.
Re: Armor Regeneration Script?
Spoiler: DECORATE
Spoiler: ACS
Re: Armor Regeneration Script?
Thank you very much, Lud.
I'd hate to bother you again, but when I try to compile this script in SLADE it comes up with an error message saying there's something missing in this line of the code:
int OldHealth = GetActorProperty(0, APROP_Health);
It says, "Identifier has not been declared".
Could you look into it? If I tried fixing that I'd probably end up making a bigger mess...
I'd hate to bother you again, but when I try to compile this script in SLADE it comes up with an error message saying there's something missing in this line of the code:
int OldHealth = GetActorProperty(0, APROP_Health);
It says, "Identifier has not been declared".
Could you look into it? If I tried fixing that I'd probably end up making a bigger mess...
Re: Armor Regeneration Script?
Oh, yea, forgot to add #library and #include. Here's how it should look like:
And you're most welcome, mate. 
Code: Select all
#library "SomeLibraryName"
#include "zcommon.acs"
<rest of the code here>

Re: Armor Regeneration Script?
Alright, now the script compiles smoothly, but it still isn't executed in the game. I have named the library "ARMORREGEN", placed the compiled script in ACS/ARMORREGEN in the .pk3, and created a LOADACS lump with the line "ARMORREGEN" in it, but the script still doesn't run. What am I doing wrong?
Re: Armor Regeneration Script?
Works fine here. Can you post the full ACS code you're using? Also, try typing "developer 1" in the console and start a game. Watch if the script starts. (Log should be in the console.)
Re: Armor Regeneration Script?
Here's the full script:
Spoiler:In developer 1 mode, the console says all scripts of type 4 (enter) and type 1 (open) are being run at level start, but it doesn't mention this specific script.
Re: Armor Regeneration Script?
Weird. One last request, then. Can I check the pk3 myself? You can PM me if you don't wanna post it here. Basically, what I did was create a new wad (not pk3), copied the DECORATE code, copied the ACS, compiled, added to LOADACS and launched the game. It worked and the console said that the script is running. Even gave me the name of the script.
Re: Armor Regeneration Script?
Apologies, but I'm not comfortable with sending the entire pk3, as it is a very dear project to me, which I've been working on for several months and which contains a lot of original material, and I'm far from ready to release it yet.
Instead, could you please send the WAD you made to test that? If I put that WAD in my pk3, it should run, right?
Instead, could you please send the WAD you made to test that? If I put that WAD in my pk3, it should run, right?
Re: Armor Regeneration Script?
Actually, I figured it out. ARMORREGEN is too long. The lump name should be max 8 characters long. Make it ARMREGEN and try again. If you use more than 8 characters, you have to specify the full path. Doom modding's complicated, lol.
Re: Armor Regeneration Script?
Alright, now we're making progress! The script works, although it doesn't quite work as planned.
*Instead of starting armor at 100%, it starts at 0%.
*Every 5 seconds regeneration stops and only starts again after 5 seconds. What I wanted to achieve is rather that the script waits 5 seconds only after taking damage.
*Armor can still regenerate above 100% instead of stopping there.
*The armor level doesn't drop at all when taking damage.
Any ideas?
*Instead of starting armor at 100%, it starts at 0%.
*Every 5 seconds regeneration stops and only starts again after 5 seconds. What I wanted to achieve is rather that the script waits 5 seconds only after taking damage.
*Armor can still regenerate above 100% instead of stopping there.
*The armor level doesn't drop at all when taking damage.
Any ideas?
Re: Armor Regeneration Script?
I forgot to mention that the armor doesn't start at 100 because it's easier to code that into the Player actor, if you have one. Use Player.StartItem "GreenArmor" or whatever armor actor you're using that gives 100 armor.
As for the capping, I think it'd be easier if you just change the MaxSaveAmount in the RegenArmor actor to 100. For the 5 seconds thing, I will investigate and post in 5-10 mins.
As for the capping, I think it'd be easier if you just change the MaxSaveAmount in the RegenArmor actor to 100. For the 5 seconds thing, I will investigate and post in 5-10 mins.
Re: Armor Regeneration Script?
Thanks! That solves 3 out of 4 problems. Only the 5 seconds thing remains.
Re: Armor Regeneration Script?
New code:
A bug, though: Sometimes it may take a bit more than 5 seconds for the script to realise that you're not taking damage. That happens while if in the process of waiting, you take damage which causes the script to restart. The longest you could possibly wait is 10 seconds in some very bad cases. Average is ~6s. I hope that's not a big problem.
Spoiler: Fixing it with WD-40Fixed the regeneration issue where it stops. I've also found a way to cap the armor from within the script. Since it gives only 1 armor bonus, it is a lot easier to control overbuffing. You can revert to Armor.MaxSaveAmount 0x7FFFFFFF in DECORATE, though the bad side of ACS is that your save games with the mod are forfeit if you change the script and recompile. You can choose either the DECORATE method of capping or the ACS one. Either way, it works. If you choose the DECORATE method, I suggest you omit the #define ARMORCAP and change ARMORCAP later in the script to whatever number you want.
A bug, though: Sometimes it may take a bit more than 5 seconds for the script to realise that you're not taking damage. That happens while if in the process of waiting, you take damage which causes the script to restart. The longest you could possibly wait is 10 seconds in some very bad cases. Average is ~6s. I hope that's not a big problem.
No such problem here.DHP1990 wrote:*The armor level doesn't drop at all when taking damage.
Re: Armor Regeneration Script?
Excellent. Now it works exactly the way I wanted. Thank you once again for your time and patience.