• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[snippet]UnitRegen

Level 31
Joined
Jul 10, 2007
Messages
6,306
JASS:
library UnitRegen /* v2.0.0.1
*************************************************************************************
*
*   A snippet that allows negative hp regeneration. Just copy and paste into the map
*   and watch it work.
*
*************************************************************************************
*   */uses/*
*   
*       */ UnitStateEvent /*    hiveworkshop.com/forums/submissions-414/snippet-unitstateevent-191707/
*
************************************************************************************/
    private struct UnitRegen extends array
        private static method h takes nothing returns boolean
            local integer i = GetEventUnitStateUnitId()
            local real r = GetUnitState(GetUnitById(i), UNIT_STATE_MAX_LIFE)
            set r = r-r*0.000050000
            if (GetWidgetLife(GetUnitById(i)) >= r) then
                call EnableEventUnitState(false)
                call SetWidgetLife(GetUnitById(i), r)
                call EnableEventUnitState(true)
            endif
            return false
        endmethod
        private static method m takes nothing returns boolean
            local integer i = GetEventUnitStateUnitId()
            local real r = GetUnitState(GetUnitById(i), UNIT_STATE_MAX_MANA)
            set r = r-r*0.000050000
            if (GetUnitState(GetUnitById(i), UNIT_STATE_MANA) >= r) then
                call EnableEventUnitState(false)
                call SetUnitState(GetUnitById(i), UNIT_STATE_MANA, r)
                call EnableEventUnitState(true)
            endif
            return false
        endmethod
        private static method a takes nothing returns boolean
            local real r
            local integer i = GetIndexedUnitId()
            set r = GetUnitState(GetUnitById(i), UNIT_STATE_MAX_LIFE)
            set r = r-r*0.000050000
            call EnableEventUnitState(false)
            if (GetWidgetLife(GetUnitById(i)) >= r) then
                call SetWidgetLife(GetUnitById(i), r)
            endif
            set r = GetUnitState(GetUnitById(i), UNIT_STATE_MAX_MANA)
            set r = r-r*0.000050000
            if (GetUnitState(GetUnitById(i), UNIT_STATE_MANA) >= r) then
                call SetUnitState(GetUnitById(i), UNIT_STATE_MANA, r)
            endif
            call EnableEventUnitState(true)
            return false
        endmethod
        private static method onInit takes nothing returns nothing
            call GetHealthEvent().register(Condition(function thistype.h))
            call GetManaEvent().register(Condition(function thistype.m))
            call RegisterUnitIndexEvent(Condition(function thistype.a), UnitIndexer.INDEX)
        endmethod
    endstruct
endlibrary
 
Last edited:

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,468
How much lag will this system generate, looping through all units constantly setting their hp and mp 32 times per second? With hundreds, of units, combine that with some good battles with spells going off, I doubt this will shine.

Since this is manual, give it more features than "more accurate regeneration than in-game". Add features to turn regeneration on/off (such as not regenerating during battle). Would be a start.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
Since this is manual, give it more features than "more accurate regeneration than in-game". Add features to turn regeneration on/off (such as not regenerating during battle). Would be a start.

Already supports that, and hasn't lagged for me in the slightest.


Any other features outside of what this does belongs in a separate lib. I will not be adding anything to this as it already supports everything that it needs to support.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,468
Yeah, hasn't lagged on your computer, with how many units and with how many other systems running at the same time? And how powerful is your computer? My computer at home is an Intel Atom 1.66, 1 GB of RAM, single-processor - a much better computer for testing for lag because if it runs smoothly on that, imagine how nicely it will run on other machines.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
The only way? I've had negative regeneration auras right out of Object Editor (change unholy aura to a negative value).

We already went over this in chat. When a unit is at max hp, they are not flagged to regenerate. The whole point of this script is to make it so that all unit's on the map have slightly less than max hp, that way they are always flagged to regenerate.

People have already suggested tons of abilities to work around this and none of them worked when a unit wasn't flagged to regen.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,468
Then it just makes it even more annoying to implement. You use LUA for things that have a 0.000001% chance of conflicting (Unit Indexer) and make it extremely annoying for users to put in their map, but instead of doing it the easy way with this one (where LUA actually appears damn useful) you let this one go manually.

Ease of implementation is a huge factor that's really not stressed enough.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
->Ease of implementation is a huge factor that's really not stressed enough.

And again, setting a bundle of default units to have a custom value in them is going to bloat the map size way up. Most maps I see use very few if any of the default units. There might be 5 default units used and 200+ custom.

That's why I haven't done it =/=.
 
Top