(Resolved) Increasing Monster Spawn HP based on CVAR?

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
eharper256
Posts: 1038
Joined: Sun Feb 25, 2018 2:30 am
Location: UK
Contact:

(Resolved) Increasing Monster Spawn HP based on CVAR?

Post by eharper256 »

Hi there, I'm trying to add in a function to allow players to tweak their own difficulty by using CVAR sliders in my monsters menu.

I did originally think about just giving monsters endless powerups with a hacky DECORATE solution, but thought it might be more efficient to try a ZScript solution first.

Alas, I can't seem to alter monster spawning HP at all. I currently have this:

Code: Select all

Class HPModifierHandler : EventHandler
{
   override void WorldThingSpawned(Worldevent event)
   {
      CVar hpSetWalp = CVar.FindCVar('walp_hpmod');
	  if(event.Thing.bIsMonster == true)
      {
		 event.thing.Health *= (1*(hpSetWalp.GetFloat()));
		 //event.thing.SpawnHealth() *= (1*(hpSetWalp.GetFloat()));
       //Console.Printf("Health is %F",event.thing.Health);
      }
   }
}
As you can see, Health does allow the script to run, but appears to do nothing (as is the current state), even if the CVAR is set to less than 1.0 (it currently has a slider from 0.5 to 5.0). SpawnHealth appears to be unmodifiable and causes a crash.

As I'm still a relative noob when ZScripting, I'm clearly missing something.

Thanks for your help!
Last edited by eharper256 on Sun Aug 07, 2022 9:36 am, edited 1 time in total.
User avatar
m8f
 
 
Posts: 1445
Joined: Fri Dec 29, 2017 4:15 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Manjaro Linux
Location: Siberia (UTC+7)
Contact:

Re: Increasing Monster Spawn HP based on CVAR?

Post by m8f »

User avatar
eharper256
Posts: 1038
Joined: Sun Feb 25, 2018 2:30 am
Location: UK
Contact:

Re: Increasing Monster Spawn HP based on CVAR?

Post by eharper256 »

Hm... so I take it there is not an easier route for customising HP than this? Ouch. That's alot of extra faff-math to have to do. :x

Using

Code: Select all

event.thing.StartHealth *= (1*(hpSetWalp.GetFloat()));
appears to have no effect either and StartHealth doesn't show up on the wiki so I'm guessing that's something you define for UCD along with cd_MonsterSettings.

Is there a method to simply throw custom HealthBonus at monsters at all? I did try a bunch of attempts like that but apparently these are all restricted to playerclasses. Or directly multiply the current difficulty settings MonsterHealth?
User avatar
m8f
 
 
Posts: 1445
Joined: Fri Dec 29, 2017 4:15 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Manjaro Linux
Location: Siberia (UTC+7)
Contact:

Re: Increasing Monster Spawn HP based on CVAR?

Post by m8f »

It's not difficult at all. The most difficult part is to figure out the desired health. In your case, it would look something like this (not tested):

Code: Select all

Class HPModifierHandler : EventHandler
{
   override void WorldThingSpawned(Worldevent event)
   {
      CVar hpSetWalp = CVar.FindCVar('walp_hpmod');
      if(event.Thing.bIsMonster == true)
      {
        double newHealth = event.thing.Health * hpSetWalp.GetFloat();
        event.thing.StartHealth = newHealth; // "base" health, so the monster doesn't appear overhealed/damaged.
        event.thing.A_SetHealth(newHealth); // actual health.
      }
   }
}
User avatar
eharper256
Posts: 1038
Joined: Sun Feb 25, 2018 2:30 am
Location: UK
Contact:

Re: Increasing Monster Spawn HP based on CVAR?

Post by eharper256 »

m8f wrote:It's not difficult at all. The most difficult part is to figure out the desired health. In your case, it would look something like this (not tested):
Thanks, although there is still no effect from that.

I did wonder if it was to do with WorldThingSpawned not affecting monsters summoned by A_SpawnItemEx by my spawners, but then using console summon also has no effect. I guess it will need more supporting code than just a simple override like this, alas.

I have absolutely no mind for programming at all, so I'm sure it seems super-easy for yourself, but my ZScripting is usually trying to bash various square pegs into round holes until I happen to find a round peg. :lol:
User avatar
m8f
 
 
Posts: 1445
Joined: Fri Dec 29, 2017 4:15 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Manjaro Linux
Location: Siberia (UTC+7)
Contact:

Re: Increasing Monster Spawn HP based on CVAR?

Post by m8f »

I checked this

Code: Select all

  override void WorldThingSpawned(Worldevent event)
  {
    //CVar hpSetWalp = CVar.FindCVar('walp_hpmod');
    if(event.Thing.bIsMonster == true)
    {
      double newHealth = event.thing.Health * 3;
      event.thing.StartHealth = newHealth; // "base" health, so the monster doesn't appear overhealed/damaged.
      event.thing.A_SetHealth(newHealth); // actual health.
    }
  }
And it does work (checked with Target Spy).

So, it's either the CVar is not what you expect, or AddEventHandlers definition is missing.
User avatar
eharper256
Posts: 1038
Joined: Sun Feb 25, 2018 2:30 am
Location: UK
Contact:

Re: Increasing Monster Spawn HP based on CVAR?

Post by eharper256 »

m8f wrote:And it does work (checked with Target Spy).

So, it's either the CVar is not what you expect, or AddEventHandlers definition is missing.
That's it, missing the AddEventHandlers. It's usually something dumb like that which I forget. :)

Thanks for all the assistance.
Post Reply

Return to “Scripting”