| 03-27-2009, 12:03 AM | #1 |
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. ![]() |
| 03-27-2009, 12:12 AM | #2 |
What do you want to attach a struct to a unit? Anyhow, H2I + StoreInteger is a quick and easy way to do it. The hashes are slightly more efficient (or so they claim), but /care. call StoreInteger(myGC,I2S(H2I(myUnit)),"My Field Name",myStruct) Then retrieve with GetStoredInteger. |
| 03-27-2009, 12:18 AM | #3 |
Easiest way:call SetUnitUserData(u, integer(Your_Struct)) Disadvantage, if other spell or the same spell is casted while this one is active, then it will be overwritten. Other option is to use Table, it's totally MUI and you can attach to the same unit different struct data. The only issue is that is slow for uberfast code procedure, if this is not the case, then this can be your best bet. Other option is PUI. I've never needed but there's people who love it. |
| 03-27-2009, 12:18 AM | #4 |
But everyone say the Handle Vars(Game Cache) is bad and slow, i don't know if have something better to use. I Have PUI on my map but i don't know how to use it on struct. is something like, create an integer array and use PUI index to store struct in array? |
| 03-27-2009, 12:22 AM | #5 |
handle Vars IS NOT EQUAL to gamecache. Use Table, which is optimized and safer than Handle Vars. And remember this: Any systems/script will be bad for you if you don't use it properly. |
| 03-27-2009, 12:24 AM | #6 |
moyack alternatives are pretty good. Except the first one. |
| 03-27-2009, 12:31 AM | #7 |
Table works, notice: Table's main disadvantage is not speed (that's kind of irrelevant) but that units could be recycled and thus your table attach to some ghost, this is approachable with a unit group. Go UnitIndexingUtils/PUI if you are lazy - Only disadvantage is the UserData usage. No matter what you pick you'll need to be careful about leaks. |
| 03-27-2009, 12:38 AM | #8 |
How i can use tables for it? set t = Table.create() set t[GetTriggerUnit()] = r Plz can make an exemple or something? |
| 03-27-2009, 12:41 AM | #9 |
JASS:set t = HandleTable.create() set t[GetTriggerUnit()] = myStruct |
| 03-27-2009, 01:01 AM | #10 |
I trying here, but how recover value? t is integer or don't need? Whats is wrong? 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 |
| 03-27-2009, 01:26 AM | #11 |
You never defined the table variable (it should be a private global). |
| 03-27-2009, 01:40 AM | #12 |
It finaly compile. JASS:cope 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 |
