| 02-25-2010, 07:19 AM | #1 |
Is it possible to add a spell to a hero via its rawcode? I wish to have spell rawcodes stored in an item's target field as a string, then call it to have the spell added to the hero when the item is acquired. Cant seem to find any option in the GUI to do so though =( PS: I would like to avoid having to hardcode adding spells based on different items.. It would become a problem if there are 100 items. I can accept JASS solutions to this but im not very good with it yet. |
| 02-25-2010, 07:39 AM | #2 |
I would recommend learning Jass to do this: JASS:library AddAbilityByItem initializer onInit requires Table globals private Table storage endglobals function LinkAbilityToItem takes integer abilID, integer itemID returns nothing set storage[itemID] = abilID endfunction function AddAbilityByItem takes item whichItem, unit whichUnit returns nothing local integer itemID = GetItemTypeId(whichItem) local integer abilID = storage[itemID] call UnitAddAbility(whichUnit, abilID) endfunction function RemoveAbilityByItem takes item whichItem, unit whichUnit returns nothing local integer itemID = GetItemTypeId(whichItem) local integer abilID = storage[itemID] call UnitRemoveAbility(whichUnit, abilID) endfunction private function onInit takes nothing returns nothing set storage = Table.create() endfunction endlibrary requires vJass (JassNewGenPack / JassHelper) and Table. Call LinkAbilityToItem('abilityRawcode', 'itemRawcode') to register the ability to the item when an item is aquired, call AddAbilityByItem(item whichItem, unit whichUnit) to add the linked ability when an item is dropped/lost, call RemoveAbilityByItem(item whichItem, unit whichUnit) to remove the linked ability. This isn't the most elegant solution, but it gets the job done. |
| 02-25-2010, 07:46 AM | #3 |
Awesome. Thanks for the swift reply. I never would have known what search criteria o use to find that code. JassNewGenPack, does it work as an add on to my world edit? or is it a separate compiler? Never used it before so i have no idea @_@ Oh and um, once i get JassNewGenPack, where do i dump the library so I can call it? |
| 02-25-2010, 02:22 PM | #4 |
I wrote the code quickly for this, so call it your lucky day =P JassNewGenPack is a collection of programs that interface with the world editor. You download it and run its editor and everything is injected into the world editor. To add libraries to JassHelper, you create a new trigger and then go to edit > convert to custom script. You can then copy and paste this directly on top of the script that will be there. Then do the same for Table. You should end up with 2 triggers that are in vJass code (not GUI). One containning this code and the other containning Table. Then, if you are working in vJass, make your library require AddAbilityByItem. If you are working in GUI, use custom scripts to just call the functions within your triggers. Edit: just saw your post here: http://www.wc3c.net/showpost.php?p=1121104&postcount=25 JassNewGenPack does not always contain the most recent files. The file that updates most often is JassHelper. Once you download the latest version, unzip the contents into your JassNewGenPack/JassHelper folder. Then when you start WE, you will have the latest version. |
| 02-26-2010, 03:39 PM | #5 | |
Yeah i figured out how to get it workin =) Still havnt tried the Itemdex though, the main reason i needed it was to run Grim001's ItemUtils which had a function to retrieve the slot number of items in your inventory. Ended up manually coding it myself >_> More importantly I managed to get the function you posted earlier, for linking abilities to items. It works fine with the vanilla abilities, but when I attempted to link a custom spell to it 'A000', it doesnt seem to register and i've no idea why. I tested it out in game and picking up the item linked to A000 a channel based spell, doesnt add any abilities to my hero. Quote:
Edit: It seems to be a problem with the spell. I tried manually adding it to the hero. When i apply the skill point it doesn't appear. I find it very wierd though, after all i just copy and pasted the spell off one of the vanilla spells. Edit 2: Solved, By setting channel spell option to visible. Next step, custom spell triggers |
