Author Topic: UpdateHP System v4 (Put Health Percentages Into Any Module Easily and More)  (Read 538 times)

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
UpdateHP System v4 (Put Health Percentages Into Any Module Easily and More)
« Reply #15 on: March 15, 2013, 10:40:30 pm »


               

FunkySwerve wrote...

I agree, I would absolutely cut off the pseudo if there's no pcs in the area. Looping pcs and comparing their area to that of the caller is a very fast operation. After all, it's the players' perceptions your script is concerned with.


...that actually gives me an idea.  Perception.

Whenever the creature perceives an enemy and a local int called "updatehp" is not true, it sets a local int on itself called "updatehp" to 1 and starts the script running, but only one time.  On each of the subsequent psuedo-heartbeats, it checks the areas of all PCs and if it doesn't find one in the same area, it sets "updatehp" to 0 and returns.

So now the psuedo-heartbeat is not running.  But when it is approached by an enemy in the future, the perception fires again and the psuedo starts back up.

Would that work?  Or is a PC permanently considered "perceived" once a creature has seen it once?

This would eliminate the need for any OnEnter/OnExit scripts and would stop any pseudos from running when no PCs are around.

Also, how much more expensive would it be to loop through creatures within 35 yards compared to looping through all PCs?  Solely dependent on the number of creatures within 35 yards or inherently more expensive?  Because if a PC ran away from a creature, the psuedo wouldn't stop until all PCs left the area - as opposed to stopping as soon as no PCs can perceive it, which would theoretically be better.

Edit: Could also check the distance between each PC and the creature - if there is no PC between 0.1 and 35.0, stop running it (since GetDistanceBetween returns 0.0 as an error).

If that works well, still one major issue: naming (since the script is no longer in OnSpawn).  Would have a few options.

1. Tell people to put a single line of code in the OnSpawn that adds on the six characters.
2. Have it run the first first time the script is called (setting a local int called "named" or something so it only runs once)
3. Have it run if the far right character isn't "%" - under the assumption no one would ever end a default name with that

FunkySwerve wrote...

Anyway, I can understand why you did use ondamaged.


Was that meant to be "didn't use ondamaged?"

FunkySwerve wrote...

I don't really see many good alternatives if you're concerned with universalizibility. Otherwise, I would just use nwnx_funcs' SetMaxHitPoints, though frankly, we haven't had to, given regen, damage reduction/resist/immunity, etc, and acaos WROTE the darn function. '<img'>


Well, the MassiveHP part was a later addition, the health percentages were the initial goal.  But I was faced with a situation when building when I either had to add immunity to a creature or somehow increase its hit points massively - and I didn't want issues with Divine Might/Favor piercing through immunity or have the creature be the only one with damage immunity like that.  I had previously used the rough concept of MassiveHP in an OnDamaged script elsewhere, so I formally adapted it as a general script versus specific for one creature (since I was under the time pressure of the ABC, didn't have time to overhaul the combat system).

So if we can figure out a good way to minimize overhead but still update enough to make it relatively smooth, you'd be free to use the percentages part if you're interested in that while ignoring (and/or deleting/commenting out) the MassiveHP part.
               
               

               


                     Modifié par MagicalMaster, 15 mars 2013 - 11:22 .
                     
                  


            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
UpdateHP System v4 (Put Health Percentages Into Any Module Easily and More)
« Reply #16 on: March 15, 2013, 11:50:10 pm »


               

MagicalMaster wrote...

Would that work?  Or is a PC permanently considered "perceived" once a creature has seen it once?

No, players can move in and out of perception. I'm not sure it's a good alternative, though, since it requires perception - think sneaking, invisibility, sanctuary, etc.

Also, how much more expensive would it be to loop through creatures within 35 yards compared to looping through all PCs?  Solely dependent on the number of creatures within 35 yards or inherently more expensive?  Because if a PC ran away from a creature, the psuedo wouldn't stop until all PCs left the area - as opposed to stopping as soon as no PCs can perceive it, which would theoretically be better.

Edit: Could also check the distance between each PC and the creature - if there is no PC between 0.1 and 35.0, stop running it (since GetDistanceBetween returns 0.0 as an error).

Distance comparisons are more costly than looping through pcs. Can't say how much more, but I'm guessing a factor of 10 at least, on average.

If that works well, still one major issue: naming (since the script is no longer in OnSpawn).  Would have a few options.

1. Tell people to put a single line of code in the OnSpawn that adds on the six characters.
2. Have it run the first first time the script is called (setting a local int called "named" or something so it only runs once)
3. Have it run if the far right character isn't "%" - under the assumption no one would ever end a default name with that

Not sure what you're getting at here, since I haven't read the script. Is the percentile health being added to the end of the critter's name? Should've figured, I guess - health bar would mean engine hacks, and nonuniversalizable.

Was that meant to be "didn't use ondamaged?"

Yup, sorry.

Funky
               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
UpdateHP System v4 (Put Health Percentages Into Any Module Easily and More)
« Reply #17 on: March 16, 2013, 02:31:03 am »


               

FunkySwerve wrote...

I'm not sure it's a good alternative, though, since it requires perception - think sneaking, invisibility, sanctuary, etc.


Isn't that exactly WHY it would be a good alternative?  If a rogue is sneaking past a bunch of mobs, none of them will have this script start running because they never perceived him.

FunkySwerve wrote...

Distance comparisons are more costly than looping through pcs. Can't say how much more, but I'm guessing a factor of 10 at least, on average.


Does that include GetFirstObjectInShape loops?  I'm guessing it's probably more expensive than looping through PCs, but I'm wondering by how much - being able to stop the script from running if a PC leaves the visual range of a creature after it perceived him (while the PC is still in the area).

FunkySwerve wrote...

Not sure what you're getting at here, since I haven't read the script. Is the percentile health being added to the end of the critter's name? Should've figured, I guess - health bar would mean engine hacks, and nonuniversalizable.


Correct.  Adds on 6 characters and then adjusts those six as needed.  Looks like this:

'Posted

Can see it briefly in action here: http://www.youtube.c...f0caA-3Dw#t=75s
               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
UpdateHP System v4 (Put Health Percentages Into Any Module Easily and More)
« Reply #18 on: March 16, 2013, 05:41:49 am »


               Pulled the file for now - will repost with some major efficiency improvements tomorrow.

Goals:
- Won't execute until PCs engage enemy, so you can spawn enemies up ahead without eating up any resources
- Won't execute if PCs leave the area, meaning not cleaning up creatures shouldn't be a problem.

More info tomorrow.
               
               

               
            

Legacy_Nissa_Red

  • Full Member
  • ***
  • Posts: 121
  • Karma: +0/-0
UpdateHP System v4 (Put Health Percentages Into Any Module Easily and More)
« Reply #19 on: March 16, 2013, 01:50:04 pm »


               I watched your video yesterday, and I must say that I was intrigued.

Not that much by the "adding inordinate" (to me) amounts of HP to monsters" feature, but by uncoupling the HP as the game perceives it (the condition that the creature is in, "badly wounded" in your screenshot above) from the HP as the player would perceive it ("10 000 hp").

I would be very interested in your system if you also ported it over to the player character (I can't tell if that's already how it works, since it seems that you've pulled the files).

To motivate my request, please let me explain that my background is the one of a party/single-player module builder. If your system manages the player character's HP in the same way that it manages monster's HP, it would allow for some very high level stuff, like locational damage, or additional "HP/health" parameters, like "stamina" or why not "sanity" and "psy points". Would it possible to extend it ? or is that not your goal at all ?

On a side note (and this has perhaps already been adressed by you, or Funky), how does your system behave when fighting several creatures ? several PCs fighting several creatures in different areas (PW) ? I imagine there's a limit : what is the recommended one to avoid TMI's ?

Also, I see a potential for abuse if players ran across your server, attacking every creature they happen to find, just enough time to initiate the pseudo-HBs, and then leave your server crawling under the extra pressure of the scripts.

Thank you for sharing your discoveries and work with us.
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
UpdateHP System v4 (Put Health Percentages Into Any Module Easily and More)
« Reply #20 on: March 16, 2013, 02:37:09 pm »


               Yeah! I dl'd it before it got pulled. I was going to fool around with it this weekend.
I like the modular aspect. So for instance if you were concerned about lag from so many creatures having it you could use just the maximum hp part of Boss monsters. In that instance you would usually only have 1 creature running the script at any 1 time.
You could also have some of you lesser creatures that came in as single individuals or pairs running the other scripts. For instance I don't think you want this script to be on rats.
So I guess what I am getting at is that you would only have a limited number of creatures with the scripts on them.

As far as extending it to players as Nissa_Red suggests I imagine that would be possible. I currently have a stamina system, but it is probably more expensive than this as it is checking AC, PC condition(poisoned, diseased, wounded), shield/ weapon size. But in single player since it's only ever running of 1 PC you can get away with a lot more.  My fatigue method only fires in combat.  Out of combat you recover fatigue naturally just standing around revovers up to 50% of your max fatigue, while potions and campfires can boost it too.
Resting naturally recovers all fatigue. Finally nagging wounds reduce your maximum fatigue and how much fatigue you have is based on your class/con/str. 
               
               

               


                     Modifié par ffbj, 16 mars 2013 - 03:03 .
                     
                  


            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
UpdateHP System v4 (Put Health Percentages Into Any Module Easily and More)
« Reply #21 on: March 16, 2013, 03:20:37 pm »


               

MagicalMaster wrote...

FunkySwerve wrote...

I'm not sure it's a good alternative, though, since it requires perception - think sneaking, invisibility, sanctuary, etc.


Isn't that exactly WHY it would be a good alternative?  If a rogue is sneaking past a bunch of mobs, none of them will have this script start running because they never perceived him.

Not really - you're concerned with player perception, not monster perception. My point was that this would yeild inconsistent play experience. Of course, if a player isn't damaging a monster, it's entirely possible that you just don't care about having a 100% by its name.

As for closing it down when a player leaves perception, that's also problematic, since some monsters heal via regen.

I really haven't taken the time to work through all the permutations, but you're going to have to do some fine-tuning. I still think it'll work, though.

Funky
               
               

               
            

Legacy_Nissa_Red

  • Full Member
  • ***
  • Posts: 121
  • Karma: +0/-0
UpdateHP System v4 (Put Health Percentages Into Any Module Easily and More)
« Reply #22 on: March 16, 2013, 03:25:50 pm »


               

ffbj wrote...
As far as extending it to players as Nissa_Red suggests I imagine that would be possible. I currently have a stamina system, but it is probably more expensive than this as it is checking AC, PC condition(poisoned, diseased, wounded), shield/ weapon size. But in single player since it's only ever running of 1 PC you can get away with a lot more.  My fatigue method only fires in combat.  Out of combat you recover fatigue naturally just standing around revovers up to 50% of your max fatigue, while potions and campfires can boost it too.
Resting naturally recovers all fatigue. Finally nagging wounds reduce your maximum fatigue and how much fatigue you have is based on your class/con/str. 


That sounds very interesting to me.

Instead of reinventing the wheel, may I ask if you made your system publicly avalaible by chance, ffbj, so that I could perhaps have a look at it ?
               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
UpdateHP System v4 (Put Health Percentages Into Any Module Easily and More)
« Reply #23 on: March 17, 2013, 05:48:14 pm »


               Version 3 is up.  Chunk of code provided to cover a fringe scenario.  Extra work to install for little gain, but possible if you want to do it:

- Chunk of code provided to place in OnEnter script for areas to avoid having an incorrect health percentage for a few seconds if a player attacks a regenerating creature and retreats (leaving the area entirely) without killing it and returns before the monster despawns (player would see an incorrect health percent for a few seconds upon returning before the script started running again)

Version 2 is up. Takes one additional (simple) step to install with the following improvements:

- Called with OnPerception when an enemy or PC approaches to avoid using resources until needed
- Shuts down if all PCs leave the creature's area and starts back up when approached again
- Calls itself every second by default once triggered (compared to previous 0.5 seconds), speeding up to 0.5 seconds if the creature is using MassiveHP and below 3000 raw hit points

Nissa_Red wrote...

Not that much by the "adding inordinate" (to me) amounts of HP to monsters" feature, but by uncoupling the HP as the game perceives it (the condition that the creature is in, "badly wounded" in your screenshot above) from the HP as the player would perceive it ("10 000 hp").


You'd be surprised how fast a group of PCs and/or henchmen can chew through HP unless you give high immunity/resistance to damage.

Nissa_Red wrote...

I would be very interested in your system if you also ported it over to the player character (I can't tell if that's already how it works, since it seems that you've pulled the files).


The general principle of MassiveHP can be applied to players...but the health percentage cannot because SetName does not work on player characters.  Which means the player would have a hard time knowing how much HP (s)he is supposed to have.

Nissa_Red wrote...

To motivate my request, please let me explain that my background is the one of a party/single-player module builder. If your system manages the player character's HP in the same way that it manages monster's HP, it would allow for some very high level stuff, like locational damage, or additional "HP/health" parameters, like "stamina" or why not "sanity" and "psy points". Would it possible to extend it ? or is that not your goal at all ?


Yes, locational damage, stamina, and all of that sort of stuff is entirely possible, since in effect it's a puesdo heartbeat firing on the PC.  It would be easy to set it up so that taking more then X damage would have a chance of causing some severe injury or something, though that would be taking the method behind the system (pseudo heartbeat) and applying it to something else entirely.

My goal really isn't to extend this particular script - the goal was a modular script that is easy to install and not performance intensive that shows health percentages and allows for high hit point pools if needed.  I could probably set up a separate script for what you're talking about, though .

Nissa_Red wrote...

On a side note (and this has perhaps already been adressed by you, or Funky), how does your system behave when fighting several creatures ? several PCs fighting several creatures in different areas (PW) ? I imagine there's a limit : what is the recommended one to avoid TMI's ?


In my module (single player, level 40, high damage/lots of spells/abilities going off), I had probably 60ish creatures spawned with the script running with zero issues, and that was the older version of the script (where 40 of those 60 creatures were in another zone entirely).  It's never caused a TMI because that usually means an infinite loop or something that loops way too much - the "overhead" of this script is simply the fact it's called freqently.

I don't know how the older version would hold up to a  PW with 10+ players and potentially a few hundred monsters spawned, though, which is why I revamped it to only have it running where needed.  For example, if you were building a module and placed monsters manually instead of spawning them, having 1000 monsters alive and running this script probably would have caused an issue.

With the new version, it won't, because the script won't fire until the creature is approached and it'll shut down when the player leaves.

Nissa_Red wrote...

Also, I see a potential for abuse if players ran across your server, attacking every creature they happen to find, just enough time to initiate the pseudo-HBs, and then leave your server crawling under the extra pressure of the scripts.


Well, in the original version, they didn't even have to attack the creature, it just started running on the spawn.  Now they have to attack the creature, but if they leave the area it shuts down, which prevents that abuse.

ffbj wrote...

Yeah! I dl'd it before it got pulled. I was going to fool around with it this weekend.


Sorry!  New version is up now.  I just didn't think of the potential for someone to place 1000 monsters manually in the toolset or something because I try to make sure not too many creatures are spawned at once.  Didn't want someone to download the old version, try running it in a module like that, and have massive issues.

New version doesn't require the builder to worry about anything like that (or rather, my script won't make the situation any worse than it already would be in that situation).

ffbj wrote...

I like the modular aspect. So for instance if you were concerned about lag from so many creatures having it you could use just the maximum hp part of Boss monsters. In that instance you would usually only have 1 creature running the script at any 1 time.

You could also have some of you lesser creatures that came in as single individuals or pairs running the other scripts. For instance I don't think you want this script to be on rats.
So I guess what I am getting at is that you would only have a limited number of creatures with the scripts on them.


Especially with the new version, it honestly shouldn't matter.  As I mentioned, I had the older, more generally inefficient script running on 60+ creatures with massive 20 creature battles going on without issue.  But yes, you could limit it to more powerful enemies - you probably don't care about the exact health percent of a rat with 4 HP.

FunkySwerve wrote...

Not really - you're concerned with player perception, not monster perception. My point was that this would yeild inconsistent play experience. Of course, if a player isn't damaging a monster, it's entirely possible that you just don't care about having a 100% by its name.


The new version has the 100% placed at spawn - it just doesn't update until perception occurs, and it only needs to update (generally speaking) if combat occurs.

FunkySwerve wrote...

As for closing it down when a player leaves perception, that's also problematic, since some monsters heal via regen.


True, in theory a player could attack a monster down to 50% HP and then run away.  While he's absent, the creature could heal back to full but the HP would still say 50%.  Then when the player comes back, it would still say 50% until the monster perceives the player again, at which point the percent will adjust to the correct amount.

So until the player engaged again, the 50% would be inaccurate, but a second later it would be correct (might mislead the player, though).

However, so far I'm not thinking of a solution to that situation that's easily implemented within the main code - dramatically raising the cost of the pseudo to try to cover fringe scenarios like that doesn't seem to be worth it.

One possibility might simply be to say that if builders are considered about that that situation, they can set up a small chunk of code in an area's OnEnter that calls the script on any creatures which are alive (instead of waiting for perception again since the creature already engaged in combat and thus might have regenerated health).  I've uploaded v3 which includes the following code fragment in the comment section at the top of the bulk script which accomplishes that purpose:

object oCreature = GetEnteringObject();

if (GetIsPC(oCreature))
{
    oCreature = GetFirstObjectInArea(OBJECT_SELF);
    while (GetIsObjectValid(oCreature))
    {
        if (GetObjectType(oCreature) == OBJECT_TYPE_CREATURE && !GetLocalInt(oCreature, "updatehp"))
        {
            SetLocalInt(oCreature, "updatehp", 1);
            ExecuteScript("mm_updatehp", oCreature);
        }

        oCreature = GetNextObjectInArea(OBJECT_SELF);
    }
}

               
               

               


                     Modifié par MagicalMaster, 17 mars 2013 - 08:05 .
                     
                  


            

Legacy_Nissa_Red

  • Full Member
  • ***
  • Posts: 121
  • Karma: +0/-0
UpdateHP System v4 (Put Health Percentages Into Any Module Easily and More)
« Reply #24 on: March 17, 2013, 07:48:25 pm »


               Thank you for your extensive reply.

I understand in which context you've developed it, and in which most other builders will probably use it, since it would reach its full potential there : well equipped and high-level characters.

Just saying that my players (well their characters) will probably die out of old age before being able to kill a 100 000 hp boss ^.^ My module is really meant to be rather low-key in levels and quality of equipment, focusing on story and survival instead. Being able to manage locational damage, and/or potentially other secondary systems, is therefore the *true* value of your system to me, at least in a first time. Also, the fact that players can't see their "true" current hp is another plus to me. Not excluding anything though, who knows what other good things it could inspire me in a second time.

My real concern was mostly on the side of the extra scripting load this system would apply to a module, and you have adressed it. I am now eager to get it up and running, so that I can test it and use it.

I would like to thank you again for sharing, documenting and supporting this system as you do.
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
UpdateHP System v4 (Put Health Percentages Into Any Module Easily and More)
« Reply #25 on: March 17, 2013, 09:42:21 pm »


               For Nissa_Red:
http://nwvault.ign.c....Detail&id=3730

Usually the  way it works you make something and tweak, tweak.
It's cool I like it.
I put stuff on cmbtrdend as do many others.  I wonder how it would work in that slot.
               
               

               


                     Modifié par ffbj, 18 mars 2013 - 02:05 .
                     
                  


            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
UpdateHP System v4 (Put Health Percentages Into Any Module Easily and More)
« Reply #26 on: March 18, 2013, 07:02:57 am »


               Version 4 is up.  Needed to fix a potential bug introduced in v3 that ONLY occurs if you use the advanced option. Specifically, the advanced option would call the script on any creature in the area, even if the script was not meant to run on the creature. New version will only run on creatures who previously had the script running on them.

- Fixed bug in advanced option introduced in v3 that would call the script on any creature in the area, even those who weren't meant to have the script run on them (potentially henchmen, summons, etc). No impact if you weren't using the advanced option

Nissa_Red wrote...

Just saying that my players (well their characters) will probably die out of old age before being able to kill a 100 000 hp boss ^.^


Hah, fair enough.  I wasn't actually trying to go past like 50k or so, but it turned out that the method innately would support up to 2 billion, so...

Nissa_Red wrote...

My module is really meant to be rather low-key in levels and quality of equipment, focusing on story and survival instead. Being able to manage locational damage, and/or potentially other secondary systems, is therefore the *true* value of your system to me, at least in a first time. Also, the fact that players can't see their "true" current hp is another plus to me. Not excluding anything though, who knows what other good things it could inspire me in a second time.


Makes sense.  Would be delighted to see other ideas pop out of this one.

Nissa_Red wrote...

My real concern was mostly on the side of the extra scripting load this system would apply to a module, and you have adressed it. I am now eager to get it up and running, so that I can test it and use it.

I would like to thank you again for sharing, documenting and supporting this system as you do.


Good to hear, and happy to help - feel free to let me know if you'd like help trying to figure out how to adapt the concept to another system.
               
               

               


                     Modifié par MagicalMaster, 18 mars 2013 - 07:03 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
UpdateHP System v4 (Put Health Percentages Into Any Module Easily and More)
« Reply #27 on: March 20, 2013, 12:21:13 am »


               

ShaDoOoW wrote...

Again the concept is brilliant, but the method of doing that less so. Also for very massive hit points, 10k hp base is not enought to make proper illusion of the default HP percentage so for a more than 100k hp editing the creature's base hitpoint via the method I suggested would be preferred anyway.

My point is that this isnt any big breakthrough since need for massive hitpoints over this 30k is rare circumstance even in extremely high magic really. In cases builder wants more than 30k hp without need to alter constitution/levels from any reason, this would be ideal method though.

Im revisiting my first opinion about this.

1) I was wrong. The number of hitpoints doesn't matter to make proper illusion of the correct HP status, what matter is frequence of the damaged-check or method/event where is this done.

2) It is breakthrough, I didnt want to admit that because it uses immmortality for the effect which is something I came up years ago with my 'immunity to devastating critical hit' solution. But you, MagicMaster, reused the immortality for something different and unique and you deserve appreciation. (Something I should probably give more often :innocent:)

thanks you published this at vault for anyone to use
               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
UpdateHP System v4 (Put Health Percentages Into Any Module Easily and More)
« Reply #28 on: March 20, 2013, 09:13:25 pm »


               Appreciated, ShaDoOoW.