Armor Regeneration Script [SOLVED]

Archive of the old editing forum
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.
User avatar
P.Rex
Posts: 54
Joined: Sun May 15, 2016 12:32 pm
Preferred Pronouns: She/Her
Contact:

Armor Regeneration Script [SOLVED]

Post by P.Rex »

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.
Last edited by P.Rex on Fri Aug 26, 2016 1:40 pm, edited 1 time in total.
User avatar
Accensus
Banned User
Posts: 2383
Joined: Thu Feb 11, 2016 9:59 am

Re: Armor Regeneration Script?

Post by Accensus »

Spoiler: DECORATE
Spoiler: ACS
User avatar
P.Rex
Posts: 54
Joined: Sun May 15, 2016 12:32 pm
Preferred Pronouns: She/Her
Contact:

Re: Armor Regeneration Script?

Post by P.Rex »

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...
User avatar
Accensus
Banned User
Posts: 2383
Joined: Thu Feb 11, 2016 9:59 am

Re: Armor Regeneration Script?

Post by Accensus »

Oh, yea, forgot to add #library and #include. Here's how it should look like:

Code: Select all

#library "SomeLibraryName"
#include "zcommon.acs"

<rest of the code here>
And you're most welcome, mate. ;)
User avatar
P.Rex
Posts: 54
Joined: Sun May 15, 2016 12:32 pm
Preferred Pronouns: She/Her
Contact:

Re: Armor Regeneration Script?

Post by P.Rex »

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?
User avatar
Accensus
Banned User
Posts: 2383
Joined: Thu Feb 11, 2016 9:59 am

Re: Armor Regeneration Script?

Post by Accensus »

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.)
User avatar
P.Rex
Posts: 54
Joined: Sun May 15, 2016 12:32 pm
Preferred Pronouns: She/Her
Contact:

Re: Armor Regeneration Script?

Post by P.Rex »

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.
User avatar
Accensus
Banned User
Posts: 2383
Joined: Thu Feb 11, 2016 9:59 am

Re: Armor Regeneration Script?

Post by Accensus »

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.
User avatar
P.Rex
Posts: 54
Joined: Sun May 15, 2016 12:32 pm
Preferred Pronouns: She/Her
Contact:

Re: Armor Regeneration Script?

Post by P.Rex »

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?
User avatar
Accensus
Banned User
Posts: 2383
Joined: Thu Feb 11, 2016 9:59 am

Re: Armor Regeneration Script?

Post by Accensus »

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.
User avatar
P.Rex
Posts: 54
Joined: Sun May 15, 2016 12:32 pm
Preferred Pronouns: She/Her
Contact:

Re: Armor Regeneration Script?

Post by P.Rex »

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?
User avatar
Accensus
Banned User
Posts: 2383
Joined: Thu Feb 11, 2016 9:59 am

Re: Armor Regeneration Script?

Post by Accensus »

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.
User avatar
P.Rex
Posts: 54
Joined: Sun May 15, 2016 12:32 pm
Preferred Pronouns: She/Her
Contact:

Re: Armor Regeneration Script?

Post by P.Rex »

Thanks! That solves 3 out of 4 problems. Only the 5 seconds thing remains.
User avatar
Accensus
Banned User
Posts: 2383
Joined: Thu Feb 11, 2016 9:59 am

Re: Armor Regeneration Script?

Post by Accensus »

New code:
Spoiler: Fixing it with WD-40
Fixed 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.
DHP1990 wrote:*The armor level doesn't drop at all when taking damage.
No such problem here.
User avatar
P.Rex
Posts: 54
Joined: Sun May 15, 2016 12:32 pm
Preferred Pronouns: She/Her
Contact:

Re: Armor Regeneration Script?

Post by P.Rex »

Excellent. Now it works exactly the way I wanted. Thank you once again for your time and patience.
Locked

Return to “Editing (Archive)”