• 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.

Add ability Jass code

Status
Not open for further replies.
Level 3
Joined
Sep 17, 2004
Messages
24
Another ignorant worldedit user here looking for a little jass help.

The custom script:

call SelectHeroSkill( GetLastCreatedUnit(), udg_SaveLoad_Abilities[ udg_Save[ udg_SaveCount ] ] )

seems to learn an ability for a hero. I am looking for a way to transform this script as a means to ADD an ability, any ability to a hero. I believe I have found the correct function to do so:

Function: native UnitAddAbility takes unit whichUnit, integer abilityId returns boolean

The custom script I have made for it looks like this:

call UnitAddAbility( GetLastCreatedUnit(), udg_SaveLoad_Abilities[ udg_Save[ udg_SaveCount ] ] )

but I am missing the boolean. I don't know what True or False would do for me here - what the boolean is. Maybe someone can help me write the correct version of the UnitAddAbility custom script. Let me know if more info is needed.
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
I think you've posted on the wrong section. Anyway

The function returns true if the ability is added and false if it failed, you don't need to worry about the return value here, you can use it like so. One cause of the function to fail is if the ability you are trying to add is already added.

If you'd like to use it, you can do something like this:
JASS:
if UnitAddAbility(whichUnit,abilityId) then
 // Unit ability added, do actions here
else
 // function failed to add ability, do actions here
endif
 
Level 3
Joined
Sep 17, 2004
Messages
24
Sorry about posting in the wrong section. Since its already posted though, I was wondering why if I replace

call SelectHeroSkill( GetLastCreatedUnit(), udg_SaveLoad_Abilities[ udg_Save[ udg_SaveCount ] ] )

with

call UnitAddAbility( GetLastCreatedUnit(), udg_SaveLoad_Abilities[ udg_Save[ udg_SaveCount ] ] )

that I get an error from Jasshelper and it corrupts the map.

Note that the variable "Save" is an array and "SaveCount" is an index inside the array for the specific ability. The variable SaveLoad_Abilities is an ability array.
 
Status
Not open for further replies.
Top