• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Easy way to attacth a Struct on a Unit?

Status
Not open for further replies.
Level 6
Joined
Feb 19, 2008
Messages
89
I making a spell here and i need attach an struct to caster, how do it?

I ever used TimerUtils but this spells don't have timers, have something like TimerUtils to use in Units?

I tryed to use HSAS but it is too hard for me , i don't know how to use it , if someone can explain how to use HSAS thanks.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Since structs are internally integers, you can use user data with them.

JASS:
struct Bla
    integer a = 1
    integer b = 2
endstruct

function AttachBla takes unit u, Bla bla returns nothing
    SetUnitUserData(u,bla)
endfunction

function RetreiveBla takes unit u returns Bla
    return GetUnitUserData(u) 
endfunction
 
Level 6
Joined
Feb 19, 2008
Messages
89
I have PUI on my map and it uses "GetUnitUserData", =/ now i trying to use tables with it but i don't know how to use tables too.

JASS:
scope Revenge

private struct ReData
    real dmg
endstruct

//store damage taken
private function Damage takes nothing returns nothing
    local ReData r = t[GetTriggerUnit()]
    set r.dmg = r.dmg+GetEventDamage()
endfunction

private function IsSpell takes nothing returns boolean
    return GetSpellAbilityId() == 'A02M'
endfunction

//damage units with damage taken
private function Explode takes nothing returns nothing
    local ReData r = t[GetTriggerUnit()]
    call DamageArea(GetTriggerUnit(),r.dmg,GetUnitX(GetTriggerUnit()),GetUnitY(GetTriggerUnit()),600.,ENEMYS)
endfunction

private function Actions takes nothing returns nothing
    local trigger trig 
    local ReData r = ReData.create()
    set r.dmg = 0
    set t = HandleTable.create()
    set t[GetTriggerUnit()] = r
    
    set trig = CreateTrigger()
    call TriggerRegisterUnitEvent( t, GetTriggerUnit(), EVENT_UNIT_DAMAGED )
    call TriggerAddAction( t, function Damage )
    
    call TriggerRegisterUnitEvent( t, GetTriggerUnit(), EVENT_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t, Condition( function IsSpell ) )
    call TriggerAddAction( t, function Explodes )
    set trig = null
endfunction

private function Conditions takes nothing returns boolean
    return GetLearnedSkill() == 'A0G7' and GetUnitAbilityLevel(GetTriggerUnit(),'A0G7')<=1
endfunction

//===========================================================================
public function InitTrig takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_HERO_SKILL )
    call TriggerAddCondition( t, Condition( function Conditions ) )
    call TriggerAddAction( t, function Actions )
    set t = null
endfunction

endscope
 
Level 6
Joined
Feb 19, 2008
Messages
89
Have something more to do?
I will test it now, :cool: first compile.

JASS:
scope Revenge

globals
    private HandleTable t
endglobals

private struct ReData
    real dmg
endstruct

//store damage taken
private function Damage takes nothing returns nothing
    local ReData r = t[GetTriggerUnit()]
    set r.dmg = r.dmg+GetEventDamage()
endfunction

private function IsSpell takes nothing returns boolean
    return GetSpellAbilityId() == 'A02M'
endfunction

//damage units with damage taken
private function Explode takes nothing returns nothing
    local ReData r = t[GetTriggerUnit()]
    call DamageArea(GetTriggerUnit(),r.dmg,GetUnitX(GetTriggerUnit()),GetUnitY(GetTriggerUnit()),600.,ENEMYS)
endfunction

private function Actions takes nothing returns nothing
    local trigger trig 
    local ReData r = ReData.create()
    set t[GetTriggerUnit()] = r
    set r.dmg = 0 
    
    set trig = CreateTrigger()
    call TriggerRegisterUnitEvent( trig, GetTriggerUnit(), EVENT_UNIT_DAMAGED )
    call TriggerAddAction(trig, function Damage )
    
    
    set trig = CreateTrigger()
    call TriggerRegisterUnitEvent( trig, GetTriggerUnit(), EVENT_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( trig, Condition( function IsSpell ) )
    call TriggerAddAction( trig, function Explode )
    set trig = null
endfunction

private function Conditions takes nothing returns boolean
    return GetLearnedSkill() == 'A0G7' and GetUnitAbilityLevel(GetTriggerUnit(),'A0G7')<=1
endfunction

//===========================================================================
public function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_HERO_SKILL )
    call TriggerAddCondition( trig, Condition( function Conditions ) )
    call TriggerAddAction( trig, function Actions )
    set t = HandleTable.create()
    set trig = null
endfunction

endscope
 
Status
Not open for further replies.
Top