• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

System fix to 1.24b (Shield System)

Status
Not open for further replies.
Level 8
Joined
Jun 18, 2007
Messages
214
JASS:
//================
function H2I takes handle h returns integer
 return GetHandleId(h)
endfunction

// ===========================
function LocalVars takes nothing returns gamecache
    return udg_hash
endfunction

function SetHandleHandle takes handle subject, string name, handle value returns nothing
    if value==null then
        call FlushStoredInteger(LocalVars(),I2S(GetHandleId(subject)),name)
    else
call StoreInteger(LocalVars(), I2S(GetHandleId(subject)), name, GetHandleId(value))
    endif
endfunction

function SetHandleInt takes handle subject, string name, integer value returns nothing
    if value==0 then
        call FlushStoredInteger(LocalVars(),I2S(GetHandleId(subject)),name)
    else
call StoreInteger(LocalVars(), I2S(GetHandleId(subject)), name, value)
    endif
endfunction

function SetHandleReal takes handle subject, string name, real value returns nothing
    if value==0 then
        call FlushStoredReal(LocalVars(), I2S(GetHandleId(subject)), name)
else
        call StoreReal(LocalVars(), I2S(GetHandleId(subject)), name, value)
    endif
endfunction

function SetHandleString takes handle subject, string name, string value returns nothing
    if value==null then
        call FlushStoredString(LocalVars(), I2S(GetHandleId(subject)), name)
else
        call StoreString(LocalVars(), I2S(GetHandleId(subject)), name, value)
    endif
endfunction
function SetHandleBoolean takes handle subject, string name, boolean value returns nothing
    if value==false then
        call FlushStoredBoolean(LocalVars(), I2S(GetHandleId(subject)), name)
    else
call StoreBoolean(LocalVars(), I2S(GetHandleId(subject)), name, true )
    endif
endfunction

function GetHandleBoolean takes handle subject, string name returns boolean
    return GetStoredBoolean(LocalVars(), I2S(GetHandleId(subject)), name)
endfunction
function GetHandleHandle takes handle subject, string name returns handle
    return GetStoredInteger(LocalVars(), I2S(GetHandleId(subject)), name)
    call DoNothing()
return null
endfunction
function GetHandleInt takes handle subject, string name returns integer
    return GetStoredInteger(LocalVars(), I2S(GetHandleId(subject)), name)
endfunction
function GetHandleReal takes handle subject, string name returns real
    return GetStoredReal(LocalVars(), I2S(GetHandleId(subject)), name)
endfunction
function GetHandleString takes handle subject, string name returns string
    return GetStoredString(LocalVars(), I2S(GetHandleId(subject)), name)
endfunction

function GetHandleUnit takes handle subject, string name returns unit
    return GetStoredInteger(LocalVars(), I2S(GetHandleId(subject)), name)
    call DoNothing()
return null
endfunction
function GetHandleTimer takes handle subject, string name returns timer
    return GetStoredInteger(LocalVars(), I2S(GetHandleId(subject)), name)
    call DoNothing()
return null
endfunction
function GetHandleTrigger takes handle subject, string name returns trigger
    return GetStoredInteger(LocalVars(), I2S(GetHandleId(subject)), name)
    call DoNothing()
return null
endfunction
function GetHandleEffect takes handle subject, string name returns effect
    return GetStoredInteger(LocalVars(), I2S(GetHandleId(subject)), name)
    call DoNothing()
    return null
endfunction
function GetHandleTextTag takes handle subject, string name returns texttag
    return GetStoredInteger(LocalVars(), I2S(GetHandleId(subject)), name)
    call DoNothing()
    return null
endfunction
function GetHandleTriggerAction takes handle subject, string name returns triggeraction
    return GetStoredInteger(LocalVars(), I2S(GetHandleId(subject)), name)
    call DoNothing()
    return null
endfunction

function FlushHandleLocals takes handle subject returns nothing
    call FlushStoredMission(LocalVars(), I2S(GetHandleId(subject)) )
endfunction


// Shield System
// By Shadow1500
// HandleVars by KaTTaNa

// configuration


constant function BarColor takes nothing returns string
    return "|cFF8000FF"
endfunction
constant function BarChar takes nothing returns string
    return "'"
endfunction
constant function BarLength takes nothing returns integer
    return 20
endfunction
constant function BarSize takes nothing returns real
    return 12.50
endfunction
constant function BarOffset takes nothing returns real
    return -32.00
endfunction
constant function BarOffsetY takes nothing returns real
    return -42.00
endfunction
constant function DeadFixerAbility takes nothing returns integer
    return 'A00N'
endfunction
constant function AllowDamageSpill takes nothing returns boolean
    return true
endfunction //if true then when the shield breaks it will only block some of the damage done depending on its HP
// end configuration


function DamageModify_Child takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit u = GetHandleUnit(t,"u")

    if GetHandleBoolean(t,"fix") then
call UnitRemoveAbility( u, DeadFixerAbility() )
    endif
    call SetUnitState(u ,UNIT_STATE_LIFE, GetHandleReal(t,"finalhp") )

    set u = null
    call FlushHandleLocals(t)
    call DestroyTimer(t)
    set t = null
endfunction

// This function will "block" a certain amount of damage done to the unit
// Needs to be used in the EVENT_UNIT_DAMAGED event.
function DamageModify takes unit whichUnit, real dmg, real dmgnew returns nothing
    local timer t = CreateTimer()
    local real life = GetUnitState(whichUnit, UNIT_STATE_LIFE)
    local real maxlife = GetUnitState(whichUnit, UNIT_STATE_MAX_LIFE)
    local boolean usetimer = false
    local real dmgback = dmg-dmgnew
    local real finalhp = life-dmgnew
    if dmgnew>dmg then
        return
    endif
    if dmg > maxlife then
        call UnitAddAbility( whichUnit,DeadFixerAbility())
        call SetHandleBoolean(t, "fix", true)
        set maxlife = 1000+maxlife
        set usetimer = true
    endif
    if ( life+dmgback > maxlife ) then
        call SetUnitState(whichUnit ,UNIT_STATE_LIFE, maxlife )
        set usetimer = true
    else
call SetUnitState(whichUnit ,UNIT_STATE_LIFE, life+dmgback )
    endif
    if usetimer then
        call SetHandleHandle(t,"u",whichUnit)
        call SetHandleReal(t,"finalhp",finalhp)
        call TimerStart(t, 0, false, function DamageModify_Child)
    else
        call DestroyTimer(t)
    endif
    set t = null
endfunction

function UpdateBar takes unit whichUnit returns nothing
    local string bar = GetHandleString(whichUnit,"scolor")
    local integer y = 0
    local real slife = GetHandleReal(whichUnit,"slife")
    local real maxslife = GetHandleReal(whichUnit,"maxslife")
    local boolean endc = false

    loop
exitwhen y==BarLength()
        if (not endc) and (slife < (y * (maxslife/BarLength()))+1) then
            set endc = true
            set bar = bar+"|r|cFF000000"
        else
            set bar = bar+BarChar()
        endif
        set y = y + 1
    endloop
    set bar = bar+"|r"
    call SetTextTagTextBJ(GetHandleTextTag(whichUnit,"lifebar"),bar,BarSize())
endfunction
function DestroyShield takes unit whichUnit returns nothing
    local texttag tag = GetHandleTextTag(whichUnit,"lifebar")
    local trigger trig = GetHandleTrigger(whichUnit,"shielddmg")
    local timer t = GetHandleTimer(whichUnit,"shieldtimer")
    call SetHandleBoolean(whichUnit,"sd",false)

    // destroy shield
    call UnitRemoveAbility(whichUnit,GetHandleInt(t,"buff"))
    call SetHandleReal(whichUnit,"slife",0)
    call SetHandleReal(whichUnit,"maxslife",0)
    call SetHandleReal(whichUnit,"reg",0)
    call SetHandleReal(whichUnit,"sarmor",0)
    call SetHandleString(whichUnit,"scolor",null)

    // destroy tag
    call DestroyTextTag(tag)
    call SetHandleHandle( whichUnit, "lifebar", null )
    set tag = null

    // destoy trigger
    call SetHandleHandle(whichUnit,"shielddmg",null)
call TriggerRemoveAction(trig,GetHandleTriggerAction(trig,"action"))
    call FlushHandleLocals(trig)
    call DestroyTrigger(trig)
    set trig = null

    // destroy timer
    call SetHandleHandle(whichUnit,"shieldtimer",null)
    call PauseTimer(t)
    call FlushHandleLocals(t)
    call DestroyTimer(t)
    set t = null
endfunction
function ShieldDamage takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local real dmg = GetEventDamage()
    local real slife = GetHandleReal(u,"slife")
    local real take = 1-GetHandleReal(u,"sarmor")
    if GetTriggerEventId() == EVENT_UNIT_DEATH then
        call DestroyShield(u)
        set u = null
        return
    endif
    if (slife<(dmg*take)) then
        if GetHandleBoolean(u,"sd") then
            call DestroyShield(u)
        else
            call SetHandleReal(u,"slife",0)
        endif
if AllowDamageSpill() then
            call DamageModify(u,dmg,dmg-(slife*(1/take))) // use the remaining power of the shield to block some of the damage
        else
            call DamageModify(u,dmg,0)
        endif
    else
        call DamageModify(u,dmg,0) // block all damage
        call SetHandleReal(u,"slife",slife-(dmg*take))
        call UpdateBar(u)
    endif
    set u = null
endfunction
function CreateShield_Child takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit whichUnit = GetHandleUnit(t,"u")
    local texttag tag = GetHandleTextTag(whichUnit,"lifebar")
    local real x = GetUnitX(whichUnit)+BarOffset()
    local real y = GetUnitY(whichUnit)+BarOffsetY()
    local integer pulse = GetHandleInt(t,"pulse")
    local real upcheck = GetHandleReal(t,"check")
    local real reg = GetHandleReal(whichUnit,"reg")
    local real slife = GetHandleReal(whichUnit,"slife")
    local real maxslife = GetHandleReal(whichUnit,"maxslife")
    local integer buffId = GetHandleInt(t,"buff")
    if (GetHandleBoolean(whichUnit,"sd") and pulse==0) or ((GetUnitAbilityLevel(whichUnit,buffId)==0) and buffId!=0) then
        call DestroyShield(whichUnit)
        set t = null
        return
    endif

    if reg!=0 then
       if (slife+reg)>=maxslife then
           call SetHandleReal(whichUnit,"slife",maxslife)
       else
           call SetHandleReal(whichUnit,"slife",slife+reg)
       endif
       call UpdateBar(whichUnit)
    if upcheck!=GetHandleReal(whichUnit,"slife") then
        call SetHandleReal(t,"check",GetHandleReal(whichUnit,"slife"))
        call UpdateBar(whichUnit)
    endif

// countdown on how many times did timer ran
    if pulse>0 then
        call SetHandleInt(t,"pulse",pulse-1)
    endif

    call SetTextTagPos(tag,x,y,140)
    call SetTextTagVisibility(tag,IsUnitVisible(whichUnit,GetLocalPlayer()))

    set whichUnit = null
    set tag = null
    set t = null
endfunction
function CreateShieldEx takes unit target, real shieldhp, real duration, integer buffId, real regenerate, real armor, string color, boolean dmgspill returns nothing
    // duration of -1 = shield remains on unit when depleted
    // duration of 0 = shield stays on unit until depleted
    // duration of 1 or higher = shield stays until depleted or until duration ends
    // buffId is optional
    // regenerate is the amount of points regenerated every second
    // armor must be between 0 and 1, with 1 making the shield take no damage
    // color must in blizzard's color code format
    // when dmgspill is off the shield will block all damage when depleted
    local texttag tag = GetHandleTextTag( target, "lifebar")
    local trigger whenDamaged = GetHandleTrigger(target,"shielddmg")
    local timer t = GetHandleTimer(target,"shieldtimer")
    local boolean useOld = false
    local real x = GetUnitX(target)+BarOffset()
    local real y = GetUnitY(target)+BarOffsetY()

    if GetHandleReal(target,"slife")!=0 then
        if GetHandleInt(t,"buff")!=buffId then
            call UnitRemoveAbility(target,GetHandleInt(t,"buff"))
        endif
        call PauseTimer(t)
        call SetHandleReal(target,"reg",0)
        call SetHandleReal(target,"sarmor",0)
        call SetHandleString( target, "scolor", null)
        call DestroyTextTag(tag)
        set useOld = true
    else
        set t = CreateTimer()
        set whenDamaged = CreateTrigger()
    endif
    set tag = CreateTextTag()
    call SetHandleReal( target, "slife", shieldhp)
    call SetHandleReal( target, "maxslife", shieldhp)

    call SetHandleString( target, "scolor", color)

    // take care of the texttag
    call SetTextTagTextBJ(tag,"tag",BarSize())
    call SetTextTagPos(tag,x,y,140)
    call SetTextTagPermanent(tag,true)
    call SetTextTagColor(tag,255,255,255,255)
    call SetTextTagVisibility(tag,IsUnitVisible(target,GetLocalPlayer()))
    call SetHandleHandle( target, "lifebar", tag )
    call UpdateBar(target)

    // take care of the trigger
    if not useOld then
        call TriggerRegisterUnitEvent(whenDamaged,target,EVENT_UNIT_DAMAGED)
        call TriggerRegisterUnitEvent(whenDamaged,target,EVENT_UNIT_DEATH)
        call SetHandleHandle(whenDamaged,"action",TriggerAddAction(whenDamaged,function ShieldDamage))
        call SetHandleHandle(target,"shielddmg",whenDamaged)
    endif
    call SetHandleBoolean( whenDamaged, "dmgspill", dmgspill)

    // take care of the timer
    call SetHandleHandle( target, "shieldtimer", t)
    call SetHandleHandle( t,"u",target)
    call SetHandleReal( t, "check", shieldhp)
    if regenerate!=0 then
        call SetHandleReal(target,"reg",(regenerate)/(1/0.04))
    endif
    if armor!=0 then
        call SetHandleReal(target,"sarmor",armor)
    endif
    call SetHandleInt(t,"pulse",-1)
    if duration>=0 then
        call SetHandleBoolean( target, "sd", true)
if duration>0 then
            call SetHandleInt(t,"pulse",R2I(duration/0.04))
        endif
endif
    call SetHandleInt(t,"buff",buffId)

    call TimerStart(t,0.04,true,function CreateShield_Child)

    set whenDamaged = null
    set t = null
    set tag = null
endfunction
function CreateShield takes unit target, real shieldhp, real duration, integer buffId, real regenerate, real armor returns nothing
    call CreateShieldEx( target, shieldhp, duration, buffId, regenerate, armor, BarColor(), AllowDamageSpill())
endfunction
function CreateShieldSimple takes unit target, real shieldhp, real duration, integer buffId returns nothing
    call CreateShieldEx( target, shieldhp, duration, buffId, 0, 0, BarColor(), AllowDamageSpill())
endfunction

So, I posted this code in help zone, but I had a comment saying that it would be better of here (it's an old shield system made by Shadow1500, worked before, doesn't work with new patch). So, I'm trying to find a solution on how to make this code working in 1.24b... I think the problem is in KaTTana's HadleVars, as much as I can tell. I tryed: changing H2I to GetHandleId, replecing elseif with if calls, adding call DoNothing() action in function that have more then one return. In short, nothing worked, which means I really need help. And I'm trying to find a solution without using private functions (vJASS), so If anyone can help me fix this, please do so I'm desperate.
 
Level 8
Joined
Aug 2, 2008
Messages
193
Since 1.24, you cannnot use the return bug anymore like these way:

JASS:
function H2I takes handle h returns integer
    return h
    call DoNothing()
    return 0
endfunction

I also recommend you, to use Vexorians Faux HandleVars, they are pretty good
 
Status
Not open for further replies.
Top