• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Adding Abilities to Spellbook

Status
Not open for further replies.
Level 2
Joined
Dec 10, 2010
Messages
16
Well, the title tells it all.

A unit X buys a spell (O) from shop A. X has two spellbooks, Offensive and Defensive. O has Editor Suffix [Offensive]. How do you make is to that when the spell has the Editor Suffix [Offensive], it will be automatically added to the spellbook [Offensive] and when it has the Editor Suffix [Defensive], it will automatically be added into the spellbook [Defensive]. It will refuse to add when the unit has that ability already and will display text "You have already learned that ability".

Can someone also express this in an event where unit X learns and automatically adds the ability to the corresponding spellbook when entering a region but will refuse to add when it has been added already.
 
Level 4
Joined
Jul 24, 2010
Messages
85
From http://www.hiveworkshop.com/forums/world-editor-help-zone-98/adding-ability-spell-book-29844/

Listen:

1. Create a spell book (just cnp from itemabilities)
2. set max and min ability number to 12
3. make it unit ability
4. add all spells you want
5. create trigger that disables those abilities for player
6. create trigger that enables them foor player!
7. YAY! It's complete ;)

The same; add all offensive ability to offensive spell book; add all defensive ability to defensive spell book. When the game start, disable all those ability and enable it when the player buy item from shop.
 


-Create a spellbook to be given to your hero

-For each spell that the hero can buy, create another spellbook, and make sure that its BaseOrderID is similar to that of the spellbook of your hero

-Then create the spells, and put them inside they're respective spellbook

-Disable all of the dummy spellbooks, then just add the spellbook corresponding to the learned spell to the hero...

-Since the dummy spellbook is disabled, it will not show on the hero, but since it has the same orderID as the spellbook of the hero, all spells inside that spellbook will show on the spellbook of your hero...


for the next question: you need to save those abilities into a variable array, since you cannot get the editor suffix in-game...

JASS:
scope SPELLS_SETTINGS initializer init
  //Things you need to do:
  //Do everything on that I said above, but do it twice, one for the offensive the 2nd for the defensive
  //And make sure that the Offensive Spellbook and offensive dummy spellbooks have different BaseOrderId from the       //Defensive ones
  globals
     private integer array OFFENSIVE_SPELLS
     private integer array DEFENSIVE_SPELLS
     private integer array OFF_SPELLS_ITEM_ID
     private integer array DEF_SPELLS_ITEM_ID
     private integer TOTAL = 0
  endglobals
  
  private function AddSpell takes nothing returns nothing
     local integer i = 0
     local integer spell = GetItemTypeId(GetSoldItem())
     loop
         exitwhen i > TOTAL
         if spell == OFF_SPELLS_ITEM_ID[i] then
             if not UnitAddAbility(OFFENSIVE_SPELL[i], GetTriggerUnit()) then
                call DisplayTextToPlayer(GetOwningPlayer(GetTriggerUnit()),0,0, "You already Learned that ability")
             endif
             set i = TOTAL + 1 
         endif
         set i = i + 1
     endloop
     set i = 0
     loop
         exitwhen i > TOTAL
         if spell == DEF_SPELLS_ITEM_ID[i] then
             if not UnitAddAbility(DEFENSIVE_SPELL[i], GetTriggerUnit()) then
                call DisplayTextToPlayer(GetOwningPlayer(GetTriggerUnit()),0,0, "You already Learned that ability")
             endif
             set i = TOTAL + 1 
         endif
         set i = i + 1
     endloop
  endfunction

  private function init takes nothing returns nothing
     local trigger t = CreateTrigger()
     local integer i = 0
     call TriggerAddAction(t, function AddSpell)
     loop
      exitwhen i > 15
      call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SELL_ITEM, null)
      set i = i + 1
     endloop
     set OFFENSIVE_SPELLS[0] = RawCode of the dummy spellbook of offensive spell 1 //to get raw code of objects, just hit ctrl + d
     set OFF_SPELLS_ITEM_ID[0] = RawCode of item that will add this ability to unit  
     //and so on...
     set TOTAL = Highest index that you used
  endfunction
endscope

Or See this system by Vercas:
http://www.hiveworkshop.com/forums/...system-137421/?prev=search=buying&d=list&r=20
 
Last edited:
Status
Not open for further replies.
Top