# [Trigger]Help Storing a spell list as Integer Variable!

Status
Not open for further replies.

#### Zombai

Level 2
I am trying to cause a unit to learn certain, predefined spells and levels when a different spell is cast. Setting the variables wont be a problem.. Just applying them could be.
I've come to the conclusion that storing the information as an Integer would be the easiest way to do it.

Heres a dummy trigger to sorta explain what i mean
• dummy spell
• Events
• Unit - A unit Begins casting an ability
• Conditions
• Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• SpellList[(Player number of (Owner of (Casting unit)))] Equal to 100
• Then - Actions
• -------- Cause the unit to learn Spell 1 at Level 1 --------
• Else - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• SpellList[(Player number of (Owner of (Casting unit)))] Equal to 342
• Then - Actions
• -------- Cause the unit to learn Spell 1 at Level 3 --------
• -------- Cause the unit to learn Spell 2 at Level 4 --------
• -------- Cause the unit to learn Spell 3 at Level 2 --------
• Else - Actions
the variable is an integer array (to cater for each player also).
SpellList [a] = xyz

'a' represents the player number
'x' represents the level of spell 1
'y' represents the level of spell 2
'z' represents the level of spell 3
Spell 1 has 9 levels.
Spell 2 has 5 levels.
Spell 3 has 5 levels.
and a value of 0 indicates no spells.

The problem i have is when i want to apply the spells to a unit. Do i have to do an individual If/Then/Else for each possible combination (1 through to 955)? Or is there a way i can apply the spells using less triggers.

#### mckill2009

Level 29
if you stored the spell to an array then no need to to so many if/then/else...spellID afterall are integers so you can set upto 8190 spell ID's in one arrayed variable...

just do >>> call UnitAddAbility('h000', arrayedinteger[integerhere])

#### Zombai

Level 2
The unit the spells should be added to has multiple forms, changed by adding and removing units. I have already got the held items down pat.. I just need to be able to store the spells that the unit already knows, and then re-apply them to the unit when it returns to the form that uses said spells.
So adding the spellid would require some check to see what spells it already has to then re-add them.
Understand?

#### baassee

Level 22
Just store them into a hashtable, use the unit's id as parent key and then save each spell as an ability handle and when returning you just load those handles.

#### Bannar

Level 26
Since Blizz's SaveAbilityHandle doesn't work we have to do that in other way ;O

Abilities are basically treaten as integers for war3 engine. You can even Ctrl + D your obejct editor to see rawcodes everywhere. However, if you don't want to write all the rawcodes in custom scripts (although this eway you get the integer immidiately), you can always use Ability-type variable and do the following:

• Set Ability = Endurance Aura
• Custom script: set udg_AbilityID = udg_Ability
This piece will automaticaly get the rawcode of Endurance Aura ability. Now, since you got an integer.. you are able to just save that integer value in hashtable via Save Integer and later, to load that ability use Load Integer.

• Set AbilityID = Load Integer(stuff here from somehash)
• Custom script: call UnitAddAbility(u, udg_AbilityID)
• // to remove
• Custom script: call UnitRemoveAbility(u, udg_AbilityID)
Where 'u' defines a unit you want add given ability to.

Variables:
- AbilityID -> integer
- Ability -> ability

#### baassee

Level 22
Oh I see. Well hashtables are not my thing really

#### Zombai

Level 2
I've not used Hashtables, nor Custom Script before.
The way you explained Spinnaker confuses me, but doesn't appear to add the ability at a set level, but rather add the ability from level 1.

#### Bannar

Level 26
@Zombai; It's meant to do that in case later you can just use:
• Unit - Set level of (ability here) for someunit to 1/2/3/etc.
So, that shouldn't be problem to you after applying whole integer (rawcode) manipulation.

Status
Not open for further replies.

Replies
9
Views
701
Replies
5
Views
1K
[Trigger] Spell Problem
Replies
5
Views
669
Replies
13
Views
713
Replies
2
Views
658