Different Shield Help

cleeezzz

The Undead Ranger.
Reaction score
268
SOLVED

other one was having problems with actually creating the system

ive edited it and created this.

JASS:
scope Shield initializer Init

struct SS
    //! runtextmacro PUI()
    unit u
    real shield
    effect sfx
    real life
    real life2
    real dmg
    
    private method onDestroy takes nothing returns nothing
        set .u = null
        call DestroyEffect(.sfx)
        set .sfx = null
    endmethod
endstruct

private function Actions takes nothing returns nothing
    local unit u = GetSpellTargetUnit()
    local integer i = GetUnitAbilityLevel(GetTriggerUnit(), GetSpellAbilityId())
    local real max = 200 + ( i * 100)
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local texttag txt = CreateTextTag()
    local SS d = SS<u>    
        if d == 0 then
            set d = SS.create()
            set d.u = u
            set d.shield = 50 + ( i * 50)
            set SS<u> = d
            set d.sfx = AddSpecialEffectTarget(&quot;Abilities\\Spells\\Items\\StaffOfSanctuary\\Staff_Sanctuary_Target.mdl&quot;, u, &quot;overhead&quot;)
        else
            set d.shield = d.shield + (50 + ( i * 50))
        endif
        if d.shield &gt; max then
            set d.shield = max
        endif
    
    call SetTextTagText( txt,  &quot;|c0033FF00&quot; +  I2S(R2I(d.shield)) + &quot;|r&quot; , 0.023 )
    call SetTextTagPos ( txt, x, y, 150)
    call SetTextTagVelocity( txt, (64 * 0.071 / 128) * Cos(90 * 3.14/180 ) , (64 * 0.071 / 128) * Sin(90 * 3.14/180 ) )
    call SetTextTagPermanent( txt, false )
    call SetTextTagLifespan( txt, 1.70 )
    call SetTextTagFadepoint( txt, 1.00 )
    if IsFoggedToPlayer( x, y, GetLocalPlayer()) or IsMaskedToPlayer( x, y, GetLocalPlayer()) then
        call SetTextTagVisibility( txt, false)
    endif
    set u = null
    set txt = null
endfunction

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == &#039;A00C&#039;
endfunction


//===========================================================================
private function Init takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition( trig, Condition(function Conditions))
    call TriggerAddAction( trig, function Actions )
endfunction

endscope</u></u>


JASS:
scope SD initializer Init

//======================================================================

private function Execute takes nothing returns nothing
    local SS d = GetCSData(GetExpiredTimer())
    call UnitRemoveAbility(d.u, &#039;A008&#039;)
        if d.dmg &gt; 0 then
            set d.shield = d.shield - d.dmg
                if d.shield &lt; 0 then
                    call SetUnitState(d.u, UNIT_STATE_LIFE, d.life + d.shield)
                    call d.release()                    
                else
                    call SetUnitState( d.u, UNIT_STATE_LIFE, d.life)
                endif
        endif
    call ReleaseTimer(GetExpiredTimer())
endfunction
    
private function Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local SS d = SS<u>
    local timer t = NewTimer()
        if d != 0 then
            set d.life = GetUnitState( d.u, UNIT_STATE_LIFE)
            set d.dmg = GetEventDamage()
            call SetUnitState(d.u, UNIT_STATE_LIFE, GetUnitState(d.u, UNIT_STATE_MAX_LIFE))
            call UnitAddAbility(d.u, &#039;A008&#039;)
            call TimerStart(t,0.00,false, function Execute)
            call SetCSData(t,d)
        endif
    
    set u = null
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    set SD = CreateTrigger(  )
    call TriggerAddAction( SD, function Actions )
endfunction

endscope</u>


problem is, when the user gets hit by a spell, an error says Double free of struct SS and the shield instantly dies even if the damage was less than the shield. (however getting hit by a physical attack works perfectly O_O)

EDIT: for some reason, the damage event took the spell damage 3 times causing it to try to destroy the struct twice... i still have no idea why the event happens 3 times because my spell only damages once., but i added a condition that Damage > 0 and it fixed it.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good
  • The Helper The Helper:
    I would like to see it again like Ghan had it the first time with pagination though - without the pagination that view will not work but with pagination it just might...
  • The Helper The Helper:
    This drink recipe I have had more than a few times back in the day! Mind Eraser https://www.thehelper.net/threads/cocktail-mind-eraser.194720/

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top