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 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