Healing/Regen System (not quite finished)

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
Ok... so this is so you guys can tell me what you think about this system...
I made it so that a friend can check the regen on his heroes, so i made it so that it would be somewhat GUI friendly, but it should work fine for anyone's needs

please tell me what you would do different, and how i should improve it.

JASS:
/*GHD - v1.1 - by GFreak45
Gui-Friendly Healing/Regen Detection

Requires: Any unit indexer that assigns custom values to units.
Recommended:
Aids: <a href="http://www.thehelper.net/forums/showthread.php/130752-Advanced-Indexing-Data-Storage?highlight=advanced+indexing+data+storage" class="link link--internal">http://www.thehelper.net/forums/sho...rage?highlight=advanced+indexing+data+storage</a>

Implementation:

Create a new trigger in the editor, rename it GHD, and convert it to custom text.  Then delete what is inside and paste this there.  Then you will need to register the unit&#039;s you wish to record, but it is recommended that you only record heroes and limited non-heroes, as this system can become very slow and cost inefficient if you register every unit.  You will also need to create the following global variables:

      * GHDUnit (unit)
      * GHDLifeEvent (real)
      * GHDManaEvent (real)
      * GHDLifeAmmount (real)
      * GHDManaAmmount (real)
      * GHDLifePos (boolean)
      * GHDManaPos (boolean)

Before anyone rages, yes the idea of this came from Weep&#039;s GDD.  This system checks units at an interval, and under the right circumstances will register their health and or mana, compare it with their health/mana at the previous interval, and come to a conclusion determining the unit&#039;s regen, and whether or not the unit has taken any kind of healing or damaging effects in the most recent refresh interval.  This CAN detect life change type-damage (setting a unit&#039;s health lower than it is via triggers or by using a negative value in a healing ability).

function calls/GUI Uses and variables/constants:

   functions:

      call GHDRegisterUnit(what unit) - registered the indicated unit for use with the system recording all units results in a drastic speed/efficiency/accuracy (with regen) drop

      call GHDRemoveUnit(what unit) - un-registers a unit to be checked at every interval, this should be used only when a (non-hero) unit decays or is removed completely from the game or when the player would like to stop recording a specific unit

      call GHDRefreshUnit(what unit) - completely erases the saved information on a unit&#039;s regen and allows it to be overwritten, this is important because if a unit gains items/abilities/levels all at once and now their base regen is large enough it will not register any healing/damage

      function GetUnitRegenLife takes unit whichunit returns real - returns the life regen for the unit, it must have already been registered for a bit and not recently been refreshed in order to return a proper regen, otherwise, it will return null

      function GetUnitRegenMana takes unit whichunit returns real - returns the mana regen for the unit, it must have already been registered for a bit and not recently been refreshed in order to return a proper regen, otherwise, it will return null

   GUI Use:
      GUI users must register the units that they wish to record still, but this can be done by setting the unit to a variable and using: Custom Script: call GHDRegisterUnit(udg_VariableName)  This is simply something i cant change at the moment, but i will update the system with the option to use Auto-Registration for heroes.  The following variables will need to be created in order to use the system properly for GUI users.  Also, if you would like to use a unit&#039;s saved regen, just use: Custom Script: set udg_RealVariable = GetUnitRegenLife(udg_UnitVariable) or Custom Script: set udg_RealVariable = GetUnitRegenMana(udg_UnitVariable)

   GUI Variables:

      GHDUnit (unit variable) - this is the unit that had some kind of change, only use this in instant triggers or save it to another variable to use it in waits, it is not MUI

      GHDLifeEvent (real variable) - this is used as the event for a unit gains life, using the game event: Game - GHDLifeEvent becomes equal to 0.00, you can easily detect when a unit recieves some kind of healing

      GHDLifeAmmount (real variable) - this is the ammount of healing the unit took.  This is Not MUI and will be changed shortly after use if another unit takes healing, make sure to use this in instant triggers or save it in a variable

      GHDLifePos (boolean variable) - if this is true, the change in health was a positive change; ie: (healing), if it is false, the change was a negative change; ie: Unit - Set life of Unit equal to life of Unit - 100, or using a healing ability with a negative healed value

      GHDManaEvent (real variable) - this is used as the event for a unit has a change in mana, like the life event use: Event: Game - GHDManaEvent becomes equal to 0.00

      GHDManaAmmount (real variable) - also like the health variable, but used for a change in mana

      GHDManaPos (boolean variable) - also like the boolean for life, if this is true the unit gained some kind of mana, maybe through a potion, if it is false, the unit lost mana (casts or mana burn)

   Constants:

      MaxInstanceAmmount - This is the maximum ammount of saved instances of un-interupted healing that is saved for each unit with this system.  This indirectly correlates with the ammount of units that the system can have registered.  The higher the instance ammount, the lower the unit ammount but the more accurate the system is.

      RefreshTime - This is the interval at which the system refreshes and checks each unit to see if they recieved any type of healing, and the interval at which it registers regeneration

      GapMax - this is the max deviation between the health that the unit had for the last refresh interval + its regen over the interval and its current health; ie: 50.0 means that health changes larger than 50% of the current saved regen will not be registered as regen and instead healing

Special thanks to:

Grags - idea for the system
Weep - although we havent talked... ever, i loved your GDD system
thehelper.net - for teaching me all i know about GUI and Jass

Additional Notes/Change Log:
 
If anyone has any questions as far as how to implement this you can pm me on thehelper.net
*/

library GHD initializer GHDTrigger requires optional AIDS, optional UnitIndexer//or any other unit indexer that
//assigns a custom value to units that enter the map, they MUST assign a value to the unit
//and you should add the requirement here between requires and optional
    
    globals
    
        private constant integer MaxInstanceAmmount = 81//this is the ammount of saved instances of
        //eligible life/mana regen, the ammount of units save-able is equal 8190/this. Default is 100
        //units, 8 = 1000 units, 819 = 10
        
        private constant real RefreshTime = 1.0//the interval in seconds it takes while
        //one of the registered units is under their max health and does not take
        //damage, pick up an item, gain a level, cast an ability, or be the target
        //of an ability cast in order to register that as regen
        
        private constant real GapMax = 50.0//the % deviation from the units current regen that is
        //alloud to be registered, if the unit is past this it took some sort of healing.
        
        private group GHDGroup//do not change this.
        
    endglobals
    
    struct GHDStats extends array
        real GHDLastLife
        real GHDRegenLife
        integer GHDRegisterCountLife = 0
        boolean GHDChangeLife = true
        boolean GHDClearLife = false
        trigger GHDTrigLife
        real GHDTimeLife
        real GHDRegisteredLife
        real array GHDListLife[MaxInstanceAmmount+1]
        integer GHDListOrderLife
        
        real GHDLastMana
        real GHDRegenMana
        integer GHDRegisterCountMana = 0
        boolean GHDChangeMana = true
        boolean GHDClearMana = false
        trigger GHDTrigMana
        real GHDTimeMana
        real GHDRegisteredMana
        real array GHDListMana[MaxInstanceAmmount + 1]
        integer GHDListOrderMana
        
        static method register takes unit u returns thistype
            local thistype this = GetUnitUserData(u)
            return this
        endmethod
        
        static method remove takes unit u returns nothing
            local integer i = GetUnitUserData(u)
            local integer l = 1
            set GHDStats<i>.GHDLastLife = null
            set GHDStats<i>.GHDRegenLife = null
            set GHDStats<i>.GHDRegisterCountLife = 1
            set GHDStats<i>.GHDChangeLife = true
            set GHDStats<i>.GHDClearLife = false
            set GHDStats<i>.GHDTimeLife = 0.0
            call DestroyTrigger(GHDStats<i>.GHDTrigLife)
            loop
                exitwhen l == MaxInstanceAmmount + 1
                set GHDStats<i>.GHDListLife[l] = null
                set l = l + 1
            endloop
            set l = 1
            set GHDStats<i>.GHDLastMana = null
            set GHDStats<i>.GHDRegenMana = null
            set GHDStats<i>.GHDRegisterCountMana = 1
            set GHDStats<i>.GHDChangeMana = true
            set GHDStats<i>.GHDClearMana = false
            set GHDStats<i>.GHDTimeMana = 0.0
            call DestroyTrigger(i.GHDTrigMana)
            loop
                exitwhen l == MaxInstanceAmmount + 1
                set GHDStats<i>.GHDListMana[l] = null
                set l = l + 1
            endloop
            
        endmethod
    endstruct
    
    function GHDDamageActions takes nothing returns nothing
        local integer i = GetUnitUserData(GetTriggerUnit())
        set i.GHDLastLife = i.GHDLastLife - GetEventDamage()
        set i.GHDChangeMana = false
    endfunction
    
//======================================================================================================
//Here we have the register unit function, this can be used via: call GHDRegisterUnit(unit)
//The system only checks the units that have been registered.  All this function does is add the unit to
//GHDGroup (the group that contains all registered units), creates any triggers used to determine
//eligibility, and preps the unit to be checked for health/mana changes
    
    function GHDRegisterUnit takes unit u returns nothing
        local integer l = 0
        local GHDStats i = null
        local group g = GHDGroup
        local code c = function GHDLifeActions
        loop
            exitwhen (FirstOfGroup(g) == null)
            set l = l + 1
            call GroupRemoveUnit(g, FirstOfGroup(g))
        endloop
        if (i &lt; R2I(8190 / I2R(MaxInstanceAmmount))) then
            call GroupAddUnit(GHDGroup, u)
            set i = GHDStats.register
            set i.GHDTrigLife = CreateTrigger()
            set i.GHDTrigMana = CreateTrigger()
            call GHDLifeEvents(i)
            call GHDManaEvents(i)
            call TriggerAddCondition(i.GHDTrigLife, Filter(c))
            set c = function GHDManaActions
            call TriggerAddAction(i.GHDTrigMana, Filter(c))
        else
            call BJDebugMsg(&quot;ERROR: You have too many units registered for mana/health regen and alteration detection.&quot;)
        endif
        set c = null
        call DestroyGroup(g)
    endfunction
    
//======================================================================================================
//you can use this function to refresh the unit&#039;s regen, this will erase the current saved data, but
//allow the unit to begin re-freshing it&#039;s regen anew, without previous data corrupting the accuracy or
//stopping new values from being registered.

    function GHDRefreshUnit takes unit u returns nothing
        local integer i = GetUnitUserData(u)
        local integer a = 1
        loop
            exitwhen a &gt; MaxInstanceAmmount
            set GHDStats<i>.GHDListLife[a] = 0
            set GHDStats<i>.GHDListMana[a] = 0
            set a = a + 1
        endloop
        set GHDStats<i>.GHDListOrderLife = 1
        set GHDStats<i>.GHDListOrderMana = 1
        set GHDStats<i>.GHDRegenLife = null
        set GHDStats<i>.GHDRegenMana = null
        set GHDStats<i>.GHDTimeLife = 0.0
        set GHDStats<i>.GHDTimeMana = 0.0
        set GHDStats<i>.GHDRegisteredLife = 0.0
        set GHDStats<i>.GHDRegisteredMana = 0.0
    endfunction
    
//======================================================================================================
//you can use these functions to get unit&#039;s regen, if you try to get a unit that has recently been
//registered and has not gotten the chance to regenerate yet, or has not been registered at all, then
//this will return: null

    function GetUnitRegenLife takes unit whichunit returns real
        if (IsUnitInGroup(whichunit, GHDGroup)) then
            if (GetUnitUserData(whichunit).GHDRegenLife != 0.0) then
                return GetUnitUserData(whichunit).GHDRegenLife
            else
                return null
            endif
        endif
        return null
    endfunction
    
    function GetUnitRegenMana takes unit whichunit returns real
        if (IsUnitInGroup(whichunit, GHDGroup)) then
            if (GetUnitUserData(whichunit).GHDRegenMana != 0.0) then
                return GetUnitUserData(whichunit).GHDRegenMana
            else
                return null
            endif
        endif
        return null
    endfunction
    
//======================================================================================================
//here we can unregister or remove units from the system, this is so that you can register other units
//so you dont hit the max ammount of registered units, and so that you can remove decaying/removed units
//from the system
    
    function GHDRemoveUnit takes unit u returns nothing
        local integer i = GetUnitUserData(u)
        call GHDStats.remove
        call GroupRemoveUnit(GHDGroup, u)
    endfunction
    
//======================================================================================================
//here are the actions for the core trigger to the system, this is what occurs at every refresh interval
//it checks each unit that has been registered for mana/healing checking and compares whether the unit
//is eligible for it&#039;s mana/health to be registered, if not it sets the unit to be eligible and
//continues on to the other units, this way the next interval will be eligible if the unit has not done
//anything that would make them not eligible
    
    private function GHDActions takes nothing returns nothing
        local group g = GHDGroup
        local unit u = null
        local real r = 0.0
        loop
            exitwhen (FirstOfGroup(g) = null)
            set u = FirstOfGroup(g)
            set r = ((GetUnitState(u, UNIT_STATE_LIFE) - GHDStats[GetUnitUserData(u)].GHDLastLife)/RefreshTime)
            if (GHDStats[GetUnitUserData(u)].GHDChangeLife = true) then
                if (GHDStats[GetUnitUserData(u)].GHDRegenLife != null) then
                    if (r &lt;= (GHDStats[GetUnitUserData(u)].GHDRegenLife * RefreshTime * (1.0 + (GapMax/100.0)))
                    if (r &gt;= (GHDStats[GetUnitUserData(u)].GHDRegenLife * RefreshTime * (1.0 - (GapMax/100.0)))
                        set GHDStats[GetUnitUserData(u)].GHDRegisteredLife = GHDStats[GetUnitUserData(u)].GHDRegisteredLife + r
                        if (GHDStats[GetUnitUserData(u)].GHDRegisterCountLife &lt; MaxInstanceAmmount) then
                            set GHDStats[GetUnitUserData(u)].GHDTimeLife = GHDStats[GetUnitUserData(u)].GHDTimeLife + RefreshTime
                            set GHDStats[GetUnitUserData(u)].GHDRegisterCountLife = GHDStats[GetUnitUserData(u)].GHDRegisterCountLife + 1
                            set GHDStats[GetUnitUserData(u)].GHDRegenLife = (GHDStats[GetUnitUserData(u)].GHDRegisteredLife / GHDStats[GetUnitUserData(u)].GHDTimeLife)
                            set GHDStats[GetUnitUserData(u)].GHDListLife[GHDStats[GetUnitUserData(u)].GHDRegisterCountLife] = r
                        else
                            if (GHDStats[GetUnitUserData(u)].GHDListOrderLife &lt; MaxInstanceAmmount)
                                set GHDStats[GetUnitUserData(u)].GHDListOrderLife = GHDStats[GetUnitUserData(u)].GHDListOrderLife + 1
                            else
                                set GHDStats[GetUnitUserData(u)].GHDListOrderLife = 1
                            endif
                            set GHDStats[GetUnitUserData(u)].GHDRegenLife = (GHDStats[GetUnitUserData(u)].GHDRegisteredLife / GHDStats[GetUnitUserData(u)].GHDTimeLife)
                            set GHDStats[GetUnitUserData(u)].GHDRegisteredLife = GHDStats[GetUnitUserData(u)].GHDRegisteredLife - GHDStats[GetUnitUserData(u)].GHDListLife[GHDStats[GetUnitUserData(u)].GHDListOrderLife]
                            set GHDStats[GetUnitUserData(u)].GHDListLife[GHDStats[GetUnitUserData(u)].GHDListOrderLife] = r
                        endif
                    else
                        set udg_GHDUnit = u
                        set udg_GHDLifeAmmount = r - (GHDStats[GetUnitUserData(u)].GHDRegenLife * RefreshTime)
                        set udg_GHDLifePos = false
                        set udg_GHDLifeEvent = 0.0
                        set udg_GHDLifeEvent = 1.0
                    endif
                    else
                        set udg_GHDUnit = u
                        set udg_GHDLifeAmmount = r - (GHDStats[GetUnitUserData(u)].GHDRegenLife * RefreshTime)
                        set udg_GHDLifePos = true
                        set udg_GHDLifeEvent = 0.0
                        set udg_GHDLifeEvent = 1.0
                    endif
                else
                    set GHDStats[GetUnitUserData(u)].GHDRegisteredLife = GHDStats[GetUnitUserData(u)].GHDRegisteredLife + r
                    set GHDStats[GetUnitUserData(u)].GHDRegisterCountLife = 1
                    set GHDStats[GetUnitUserData(u)].GHDTimeLife = GHDStats[GetUnitUserData(u)].GHDTimeLife + RefreshTime
                    set GHDStats[GetUnitUserData(u)].GHDRegenLife = (GHDStats[GetUnitUserData(u)].GHDRegisteredLife / GHDStats[GetUnitUserData(u)].GHDTimeLife)
                    set GHDStats[GetUnitUserData(u)].GHDListLife[GHDStats[GetUnitUserData(u)].GHDRegisterCountLife] = r
                endif
            else
                if (GHDStats[GetUnitUserData(u)].GHDRegenLife != null) then
                if (r &gt;= (GHDStats[GetUnitUserData(u)].GHDRegenLife * RefreshTime * (1.0 + (GapMax/100.0)))
                    set udg_GHDUnit = u
                    set udg_GHDLifeAmmount = r - (GHDStats[GetUnitUserData(u)].GHDRegenLife * RefreshTime)
                    set udg_GHDLifePos = true
                    set udg_GHDLifeEvent = 0.0
                    set udg_GHDLifeEvent = 1.0
                elseif (r &lt;= (GHDStats[GetUnitUserData(u)].GHDRegenLife * RefreshTime * (1.0 - (GapMax/100.0)))
                    set udg_GHDUnit = u
                    set udg_GHDLifeAmmount = r - (GHDStats[GetUnitUserData(u)].GHDRegenLife * RefreshTime)
                    set udg_GHDLifePos = false
                    set udg_GHDLifeEvent = 0.0
                    set udg_GHDLifeEvent = 1.0
                endif
                endif
                set GHDStats[GetUnitUserData(u)].GHDChangeLife = true)
            endif

//here is where the life check ends and the mana check starts

            set r = ((GetUnitState(u, UNIT_STATE_MANA) - GHDStats[GetUnitUserData(u)].GHDLastMana)/RefreshTime)
            if (GHDStats[GetUnitUserData(u)].GHDChangeMana = true) then
                if (GHDStats[GetUnitUserData(u)].GHDRegenMana != null) then
                    if (r &lt;= (GHDStats[GetUnitUserData(u)].GHDRegenMana * RefreshTime * (1.0 + (GapMax/100.0)))
                    if (r &gt;= (GHDStats[GetUnitUserData(u)].GHDRegenMana * RefreshTime * (1.0 - (GapMax/100.0)))
                        set GHDStats[GetUnitUserData(u)].GHDRegisteredMana = GHDStats[GetUnitUserData(u)].GHDRegisteredMana + r
                        if (GHDStats[GetUnitUserData(u)].GHDRegisterCountMana &lt; MaxInstanceAmmount) then
                            set GHDStats[GetUnitUserData(u)].GHDTimeMana = GHDStats[GetUnitUserData(u)].GHDTimeMana + RefreshTime
                            set GHDStats[GetUnitUserData(u)].GHDRegisterCountMana = GHDStats[GetUnitUserData(u)].GHDRegisterCountMana + 1
                            set GHDStats[GetUnitUserData(u)].GHDRegenMana = (GHDStats[GetUnitUserData(u)].GHDRegisteredMana / GHDStats[GetUnitUserData(u)].GHDTimeMana)
                            set GHDStats[GetUnitUserData(u)].GHDListMana[GHDStats[GetUnitUserData(u)].GHDRegisterCountMana] = r
                        else
                            if (GHDStats[GetUnitUserData(u)].GHDListOrderMana &lt; MaxInstanceAmmount)
                                set GHDStats[GetUnitUserData(u)].GHDListOrderMana = GHDStats[GetUnitUserData(u)].GHDListOrderMana + 1
                            else
                                set GHDStats[GetUnitUserData(u)].GHDListOrderMana = 1
                            endif
                            set GHDStats[GetUnitUserData(u)].GHDRegenMana = (GHDStats[GetUnitUserData(u)].GHDRegisteredMana / GHDStats[GetUnitUserData(u)].GHDTimeMana)
                            set GHDStats[GetUnitUserData(u)].GHDRegisteredMana = GHDStats[GetUnitUserData(u)].GHDRegisteredMana - GHDStats[GetUnitUserData(u)].GHDListMana[GHDStats[GetUnitUserData(u)].GHDListOrderMana]
                            set GHDStats[GetUnitUserData(u)].GHDListMana[GHDStats[GetUnitUserData(u)].GHDListOrderMana] = r
                        endif
                    else
                        set udg_GHDUnit = u
                        set udg_GHDManaAmmount = r - (GHDStats[GetUnitUserData(u)].GHDRegenLife * RefreshTime)
                        set udg_GHDManaPos = true
                        set udg_GHDManaEvent = 0.0
                        set udg_GHDManaEvent = 1.0
                    endif
                        set udg_GHDUnit = u
                        set udg_GHDManaAmmount = r - (GHDStats[GetUnitUserData(u)].GHDRegenLife * RefreshTime)
                        set udg_GHDManaPos = true
                        set udg_GHDManaEvent = 0.0
                        set udg_GHDManaEvent = 1.0
                    endif
                else
                    set GHDStats[GetUnitUserData(u)].GHDRegisteredMana = GHDStats[GetUnitUserData(u)].GHDRegisteredMana + r
                    set GHDStats[GetUnitUserData(u)].GHDRegisterCountMana = 1
                    set GHDStats[GetUnitUserData(u)].GHDTimeMana = GHDStats[GetUnitUserData(u)].GHDTimeMana + RefreshTime
                    set GHDStats[GetUnitUserData(u)].GHDRegenMana = (GHDStats[GetUnitUserData(u)].GHDRegisteredMana / GHDStats[GetUnitUserData(u)].GHDTimeMana)
                    set GHDStats[GetUnitUserData(u)].GHDListMana[GHDStats[GetUnitUserData(u)].GHDRegisterCountMana] = r
                endif
            else
                if (GHDStats[GetUnitUserData(u)].GHDRegenMana != null) then
                if (r &gt;= (GHDStats[GetUnitUserData(u)].GHDRegenMana * RefreshTime * (1.0 + (GapMax/100.0)))
                    set udg_GHDUnit = u
                    set udg_GHDManaAmmount = r - (GHDStats[GetUnitUserData(u)].GHDRegenMana * RefreshTime)
                    set udg_GHDManaPos = true
                    set udg_GHDManaEvent = 0.0
                    set udg_GHDManaEvent = 1.0
                elseif (r &lt;= (GHDStats[GetUnitUserData(u)].GHDRegenMana * RefreshTime * (1.0 - (GapMax/100.0)))
                    set udg_GHDUnit = u
                    set udg_GHDManaAmmount = r - (GHDStats[GetUnitUserData(u)].GHDRegenMana * RefreshTime)
                    set udg_GHDManaPos = false
                    set udg_GHDManaEvent = 0.0
                    set udg_GHDManaEvent = 1.0
                endif
                endif
                set GHDStats[GetUnitUserData(u)].GHDChangeMana = true
            endif
            set GetUnitUserData.GHDLastLife = GetUnitState(u, UNIT_STATE_LIFE)
            set GetUnitUserData.GHDLastMana = GetUnitState(u, UNIT_STATE_MANA)
            call GroupRemoveUnit(g, u)
        endloop
        set u = null
        call DestroyGroup(g)
    endfunction
    
//======================================================================================================
//Mana Cancellation occurs when a unit casts an ability or is the target of an ability, this is so that
//whenever a unit uses mana or has a chance to be a target of a mana burn type ability, they do not
//register mana on the upcoming refresh
    
    private function GHDManaCancellation takes nothing returns nothing
        if (IsUnitInGroup(GetTriggerUnit(), GHDGroup)) then
            set GetUnitUserData(GetTriggerUnit()).GHDChangeMana = false
        endif
        if (IsUnitInGroup(GetSpellTargetUnit(), GHDGroup)) then
            set GetUnitUserData(GetSpellTargetUnit().GHDChangeMana = false
        endif
    endfunction
    
//======================================================================================================
//In this we create the core triggers and create actions using conditions saved as code... relatively
//simple
    
    private function GHDTrigger takes nothing returns nothing
        local trigger t = CreateTrigger()
        local code c = function GHDActions
        call TriggerRegisterTimerEvent(t, RefreshTime, true)
        call TriggerAddCondition(t, Filter(c))
        set c = function GHDManaCancellation
        set t = CreateTrigger()
        call TriggerRegisterUnitEvent(t, null, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(t, Filter(c))
        set c = null
        set t = null
    endfunction
endlibrary</i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i>
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
Well, ignoring the fact that it's uncompilable, I think a better approach would be:

JASS:
function GetUnitLifeRegen takes unit u returns real
    local real result = 0
    local integer item_index
    local integer item_type_id

    set result = result + GetUnitTypeBaseRegeneration(GetUniTypeId(u)) // the value set in the OE
   
    if IsUnitType(u, UNIT_TYPE_HERO) then
        set result = result + GetHeroStr(u, true) * HP_REGEN_BOUNS_PER_STR_POINT
    
        set item_index = 0
        loop
            exitwhen i &gt;= bj_MAX_INVENTORY

            set item_type_id = GetItemTypeId(UnitItemInSlot(u, item_index))
            if item_type_id == &#039;rlif&#039; then // ring of regeneration +2 hp regen
                set result = result + 2

            // elseif item_type_id == custom_item_with_hp_regen_id then
            //
            endif

            set item_index = item_index + 1
        endloop
    endif

    set result = result + GetUnitAbilityLevel(u, &#039;AUau&#039;) * 0.50 // under the effect of Unholy aura?
    // and other custom auras that stack?! =)

    return result
endfunction

// the same thing with mana except the attribute, items and auras are different.
function GetUnitManaRegen takes unit u returns real
...
endfunction


As you can probably tell this is pretty efficient and could work for every unit.
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
its supposed to be able to detect healing, not regen, the regen was just a part of that that came along with it
and what is it that makes it not compile?
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
>and what is it that makes it not compile?

I meant that GHD (being "unfinished") won't compile and posted a "skeleton" script that just needs the GetUnitTypeBaseRegeneration function and the HP_REGEN_BONUS_PER_STR_POINT constant.

>its supposed to be able to detect healing, not regen,

hp regeneration is not healing? if so then detecting healing is as simple as detecting all the healing abilities being cast
 

luorax

Invasion in Duskwood
Reaction score
67
and what is it that makes it not compile?

JASS:
private function GHDManaCancellation takes nothing returns nothing
        if (IsUnitInGroup(GetTriggerUnit(), GHDGroup)) then
            set GetUnitUserData(GetTriggerUnit()).GHDChangeMana = false
        endif
        if (IsUnitInGroup(GetSpellTargetUnit(), GHDGroup)) then
            set GetUnitUserData(GetSpellTargetUnit().GHDChangeMana = false
        endif
    endfunction


AFAIK integers do not have members. Guess you wanted to write something like this:

JASS:
private function GHDManaCancellation takes nothing returns nothing
        if (IsUnitInGroup(GetTriggerUnit(), GHDGroup)) then
            set GHDStats(GetUnitUserData(GetTriggerUnit())).GHDChangeMana = false
        endif
        if (IsUnitInGroup(GetSpellTargetUnit(), GHDGroup)) then
            set GHDStats(GetUnitUserData(GetSpellTargetUnit())).GHDChangeMana = false
        endif
    endfunction


or either this:

JASS:
private function GHDManaCancellation takes nothing returns nothing
        if (IsUnitInGroup(GetTriggerUnit(), GHDGroup)) then
            set GHDStats[GetTriggerUnit()].GHDChangeMana = false
        endif
        if (IsUnitInGroup(GetSpellTargetUnit(), GHDGroup)) then
            set GHDStats[GetSpellTargetUnit()].GHDChangeMana = false
        endif
    endfunction
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
hp regeneration is not healing? if so then detecting healing is as simple as detecting all the healing abilities being cast
ok its supposed to detect both, but its supposed to be able to tell the difference between regen and healing... and detecting healing isnt as simple as the GetUnitTypeBaseRegeneration function, that does not take into account strength, items, buffs, auras, and plenty of other things, and mana regeneration is the same way...

JASS:
private function GHDManaCancellation takes nothing returns nothing
        if (IsUnitInGroup(GetTriggerUnit(), GHDGroup)) then
            set GHDStats[GetTriggerUnit()].GHDChangeMana = false
        endif
        if (IsUnitInGroup(GetSpellTargetUnit(), GHDGroup)) then
            set GHDStats[GetSpellTargetUnit()].GHDChangeMana = false
        endif
    endfunction
thanks, ill change that right now

EDIT: Updated it, properly referencing struct variables now, i think...
any other slip ups that you see feel free to tell me
 

Dirac

22710180
Reaction score
147
I'm kinda lost here, how are GUI users supposed to have events such as "unit is healed" with your library?
Also if you're planning to code a GUI-friendly resource be prepared to code one that doesn't use the JASS helper, because most GUI users don't.
 

luorax

Invasion in Duskwood
Reaction score
67
Well, it took me like an hour to make my JASSHelper compile this monster, but 25% of the code is still unclear, and not to mention that this is honestly an overkill (writing my own, efficient vJASS snippet would be way easier and faster). I'm not going to post it since I still didn't change a lot of things, and it's not even my own code, but you have to work A LOT on it.

Also, "udg_"?
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
>Well, it took me like an hour to make my JASSHelper compile this monster,
You did?! xD... +1 for bothering
So did it work =)?

>(writing my own, efficient vJASS snippet would be way easier and faster)
What method would it be using? Just curious...
 

luorax

Invasion in Duskwood
Reaction score
67
Dunno, I didn't test it, because it had some unclear parts (non-existent trigger actions, "udg_" global variables, etc)

Well, I think I'd use an AIDS struct combined with a linked list so that I can loop through it periodically as fast as possible. Or something like this, because it might change while I'm writing the script; I keep coming up with ideas while I'm coding.
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
the global variables were for gui users to hook into it...
i guess i could do it a lot more efficiently... ill try re-writing this using a linked list instead of a group
and uhmmm, i dont think there is a GetUnitTypeBaseRegen function or a regen per str constant
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
>i dont think there is a GetUnitTypeBaseRegen function or a regen per str constant

You don't say...

The constant simply reflects the value the user/mapmaker has set in the Gameplay Constants window for the constant Hero Attributes - HP Regen. Bonus per Strength Point (default: 0.05), and the function would look like something like this:

JASS:
function init_units_base_hp_regen takes nothing returns nothing
    call SaveReal(HT, &#039;e000&#039;, HP_REGEN_KEY, ...)
    call SaveReal(HT, &#039;ebal&#039;, HP_REGEN_KEY, ...)
    call SaveReal(HT, &#039;hfoo&#039;, HP_REGEN_KEY ...)
    ...
    etc. for all the units(custom or preset) in the map making essentially a small database
    ...
endfunction

function on_init takes nothing returns nothing
     ExecuteFunc(&quot;init_units_base_hp_regen&quot;) // making sure not to hit the op limit
endfunction

function GetUnitTypeBaseLifeRegeneration takes integer unit_type_id returns real
    return LoadReal(HT, unit_type_id, HP_REGEN_KEY)
endfunction


With this "method" of extracting the data that is available in the OE but unavailable for the Jass's api, we simple extract the data and put
it in to a hashtable/gamecache/etc in the map's script; this way every unit's property is available even defense and attack type =).

Of course we are not bound of extracting only unit data, but it seams most useful due to units/heroes being a central part in the game of Warcraft 3 [TFT]
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
In the GHD Actions function, you should assign GetUnitUserData(u) to a local integer so you don't have to call the function several times. (instead you can just use the local variable)
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
updated... now referencing local variables instead of GetUnitUserData(u), fixed a few local variable declarations, and cleaned up some documentation, more in the next update
sometime this week i will update it with the version that uses a linked list isntead of a group
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
@GFreak45

Have you actually tried to compile this script yourself??!! Compile = using newgen/jasshelper and save the map.
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
every time i try to compile anything, including approved systems, it says that every single line is outside a function statement... even the line:
[ljass]function Name takes nothing returns nothing[/ljass] is outside a function statement?!?!? that makes 0 sense
 

Dirac

22710180
Reaction score
147
Don't compile with the syntax check button, it's broken, instead save the map
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
guess i need to learn more about the actual program before i really get into using it... is there some sort of tutorial for each of the JNPG resources?
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top