Protoss Unit Shields

SarChasm

New Member
Reaction score
15
I did some searching around the forum and I found a threat that lead to a link to a map where some guy managed to create a shield system nearly identical to the Protoss shields from Starcraft. The map is attatched.

I've figured out how to implement the system into my own map, which was easy enough, but my very basic knowledge of JASS is preventing me from doing some things:

1. Give the self shield buff to a unit upon creation. (I know how to edit the shield stats depending on which unit is made, I just don't know how to give it to a created unit)
2. I want to make a Shield Battery structure that is able to fully regenerate shields within an AoE, at the cost of some of the structure's mana. I do not how to program this either.
3. Lastly, I need an EMP skill that will completely destroy (not permanently, just reduce shield level to 0, it can still regenerate afterwards) units' shields within an AoE at the cost of some mana.

Thanks in advance.
 

Attachments

  • Shield System 1.2.w3x
    28.5 KB · Views: 74

SarChasm

New Member
Reaction score
15
For convenience, here's the script. A lot of it is might be unnecessary since I do not plan on using the energy shield or the deflecting shield. I only need the self shield, which is the one that gives a unit a shield that regenerates, and cannot be permanently destroyed:

JASS:
//================
function H2I takes handle h returns integer
    return h
    return 0
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(H2I(subject)),name)
    else
        call StoreInteger(LocalVars(), I2S(H2I(subject)), name, H2I(value))
    endif
endfunction
 
function SetHandleInt takes handle subject, string name, integer value returns nothing
    if value==0 then
        call FlushStoredInteger(LocalVars(),I2S(H2I(subject)),name)
    else
         call StoreInteger(LocalVars(), I2S(H2I(subject)), name, value)
    endif
endfunction
 
function SetHandleReal takes handle subject, string name, real value returns nothing
    if value==0 then
        call FlushStoredReal(LocalVars(), I2S(H2I(subject)), name)
    else
        call StoreReal(LocalVars(), I2S(H2I(subject)), name, value)
    endif
endfunction
 
function SetHandleString takes handle subject, string name, string value returns nothing
    if value==null then
        call FlushStoredString(LocalVars(), I2S(H2I(subject)), name)
    else
        call StoreString(LocalVars(), I2S(H2I(subject)), name, value)
    endif
endfunction
function SetHandleBoolean takes handle subject, string name, boolean value returns nothing
    if value==false then
        call FlushStoredBoolean(LocalVars(), I2S(H2I(subject)), name)
    else
        call StoreBoolean(LocalVars(), I2S(H2I(subject)), name, true )
    endif
endfunction

function GetHandleBoolean takes handle subject, string name returns boolean
    return GetStoredBoolean(LocalVars(), I2S(H2I(subject)), name)
endfunction
function GetHandleHandle takes handle subject, string name returns handle
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleInt takes handle subject, string name returns integer
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
endfunction
function GetHandleReal takes handle subject, string name returns real
    return GetStoredReal(LocalVars(), I2S(H2I(subject)), name)
endfunction
function GetHandleString takes handle subject, string name returns string
    return GetStoredString(LocalVars(), I2S(H2I(subject)), name)
endfunction
 
function GetHandleUnit takes handle subject, string name returns unit
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleTimer takes handle subject, string name returns timer
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleTrigger takes handle subject, string name returns trigger
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleEffect takes handle subject, string name returns  effect
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleTextTag takes handle subject, string name returns  texttag
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleTriggerAction takes handle subject, string name returns triggeraction
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
 
function FlushHandleLocals takes handle subject returns nothing
    call FlushStoredMission(LocalVars(), I2S(H2I(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 'A004'
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)
    elseif 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


And here's the GUI trigger that gives a unit a shield.
Trigger:
  • Self Shield
    • Events
      • Time - Elapsed game time is 2.00 seconds
    • Conditions
    • Actions
      • Set guy = Protector of Men 0000 <gen>
      • Custom script: call CreateShieldEx(udg_guy,300,-1,0,3,0,"|cFF3232FF",true)
      • -------- CreateShieldEx takes unit target, real shieldhp, real duration, integer buffId, real regenerate, real armor, string color, boolean dmgspill --------
      • -------- Target = Guy --------
      • -------- Shield Hitpoints = 300 --------
      • -------- Duration = -1 (Indestructable) --------
      • -------- Buff = None (not using buff cuz shield is indestructable) --------
      • -------- Regeneration = 3 HP per second --------
      • -------- Armor = 0 (reduce 0% dmg taken) --------
      • -------- Color = |cFF3232FF (Blue) --------
      • -------- Damage Spill = Yes --------
 

Naga'sShadow

Ultra Cool Member
Reaction score
49
First off when posting a Jass trigger use the Jass tags instead of the code tags that block you've got there is an eyesore. Here I reposted it in Jass Tags.

JASS:
//================
function H2I takes handle h returns integer
return h
return 0
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(H2I(subject)),name)
else
call StoreInteger(LocalVars(), I2S(H2I(subject)), name, H2I(value))
endif
endfunction

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

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

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

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

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

function FlushHandleLocals takes handle subject returns nothing
call FlushStoredMission(LocalVars(), I2S(H2I(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 'A004'
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)
elseif 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,func tion 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


For your first question are you having trouble adding the shield to a unit that you just built? Or you want to add a readable buff. For the readable buff you would insert a line into the primary function CreateShield that would give the unit either an aura that doesn't do anything but provides a buff or cast a spell on the unit giving it a buff. The first way can't be dispelled. CreateShieldEx is the function and as long as you add your bit before the start timer line it will get carried out when you call this function in the GUI.

If you mean that you want to call the shield for a unit that has just be created and not preplaced you would only need to call the shield function in the trigger that made the unit or detect when your unit enters the map and give ti the buff. You would have to either set it to a variable, and use the variable to call the function or use the last created unit line. In jass that is bj_lastCreatedUnit.

Sorry can't help you with question 2 and 3 as that would require a familiarity with handle vars. If you want to look your looking for a variable holding shield life and then you want to add a line that changes it.
 

SarChasm

New Member
Reaction score
15
I was looking for the bj_lastCreatedUnit line, thanks. Also thanks for reposting the code.

And what do you mean by handle variables? There's a shieldhp real in the CreateShieldEx function if that's what you mean.

JASS is pretty alien to me. I've got a little experience in C++ and Java, so I can recognize some of the stuff, but not much.
 

SarChasm

New Member
Reaction score
15
UPDATE: bj_lastCreatedUnit doesn't work with the Unit - Enters playable map event. Is there a different event I should be using or a different line of code?
 

bOb666777

Stand against the ugly world domination face!
Reaction score
117
GetTriggerUnit()? Lol

For your EMP (based on any instant/no-target ability):
JASS:
//*************Settings*************
function abilityId takes nothing returns integer
    return 'A000' //abilityId of your ability
endfunction

function Radius takes nothing returns real
    return 500.00 //radius of your EMP ability
endfunction

//*******************************************

function Trig_EMP_Conditions takes nothing returns boolean
    if ( GetSpellAbilityId() == abilityId() )  then
        return true
    endif
    return false
endfunction

function Trig_EMP_Actions takes nothing returns nothing
    local group g
    local unit cast = GetTriggerUnit()
    local unit u
    local location p = GetUnitLoc(cast)
    local real radius = Radius()
    call GroupEnumUnitsInRangeOfLoc(g, p, radius, null) 
    loop
      set u = FirstOfGroup(g)
      exitwhen u==null
      if  IsUnitEnemy(u, GetOwningPlayer(cast))==true then
        call GroupRemoveUnit(g,u)
        call SetHandleReal(u, "slife", 0)
      endif
    endloop
    call DestroyGroup(g)
    set g = null
    set u = null
    set cast = null
    call RemoveLocation(p)
    set p = null
endfunction

//===========================================================================
function InitTrig_EMP takes nothing returns nothing
    set gg_trg_EMP = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_EMP, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_EMP, Condition( function Trig_EMP_Conditions ) )
    call TriggerAddAction( gg_trg_EMP, function Trig_EMP_Actions )
endfunction



Shield Battery (based on something like Spirit Touch with no mana regen):
JASS:
//*************Settings*************
function BatteryabilityId takes nothing returns integer
    return 'A000' //abilityId of your Battery ability
endfunction

function BatteryRadius takes nothing returns real
    return 500.00 //radius of your Battery ability
endfunction

function BatteryRegen takes nothing returns real
    return 100.00 //Amount of shield life regenerated per cast
endfunction

//*******************************************

function Trig_Battery_Conditions takes nothing returns boolean
    if ( GetSpellAbilityId() == BatteryabilityId() )  then
        return true
    endif
    return false
endfunction

function Trig_Battery_Actions takes nothing returns nothing
    local group g
    local unit cast = GetTriggerUnit()
    local unit u
    local location p = GetUnitLoc(cast)
    local real radius = BatteryRadius()
    local real regen = BatteryRegen()
    call GroupEnumUnitsInRangeOfLoc(g, p, radius, null) 
    loop
      set u = FirstOfGroup(g)
      exitwhen u==null
      if  IsUnitEnemy(u, GetOwningPlayer(cast))==true then
        call GroupRemoveUnit(g,u)
        call SetHandleReal(u, "slife", GetHandleReal(u, "slife")+regen)
      endif
    endloop 
    call DestroyGroup(g)
    set g = null
    set u = null
    set cast = null
    call RemoveLocation(p)
    set p = null
endfunction

//===========================================================================
function InitTrig_Battery takes nothing returns nothing
    set gg_trg_Battery = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Battery, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Battery, Condition( function Trig_EMP_Conditions ) )
    call TriggerAddAction( gg_trg_Battery, function Trig_EMP_Actions )
endfunction
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top