System ItemAbilities

Waaaaagh

I lost all my rep and my title being a jerk
Reaction score
70
Very short, very simple.

JASS:
library ItemAbilities uses AbilityDatabase
private function GameCache takes nothing returns gamecache
return InitGameCache("AbilityCache.w3v") //Put your global gamecache here, for instance, udg_GC
endfunction

globals
    private constant integer NoAbility = 'Abdt' //This is what the system puts in if an item has 
    //no ability in the slot you looked up. It should be either '0' or a dummy ability, like
    //burrow detection ('Abdt') which does absolutely nothing.
    private constant integer DummyId = 'h000' //This is the id used for creating a dummy unit. It
    //should have no abilities visible in the object editor. It doesn't have to be a hero.
    private constant boolean IndexRefine = true //If set to true, putting a value like 100 for the
    //index in GetItemTypeAbility will scale it down to 3. If false, putting a bad index will
    //simply return NoAbility.
    private constant integer MaxAbilities = 4 //This is the maximum number of abilities you items can
    //have. Usually it is four, unless you are sneaky like cohadar or something. But you should
    //probably keep it at four.
endglobals

function GetItemTypeAbility takes integer id, integer which returns integer
local gamecache g=GameCache()
local unit DummyUnit
local item DummyItem
local integer i
local integer a = 0
local integer b = 1
local integer m
if which > MaxAbilities-1 then
    if IndexRefine then
        set which=MaxAbilities-1
    else
        return NoAbility
    endif
elseif which < 0 then
    if IndexRefine then
        set which=0
    else
        return NoAbility
    endif
endif
set i = GetStoredInteger(g,I2S(id),"Ability"+I2S(which))
if i != 0 then
    return i
else
    set m = GetStoredInteger(g,"AbilityCount","Database")
    set DummyUnit=CreateUnit(Player(15),DummyId,0.0,0.0,0.0) 
    call ShowUnit(DummyUnit,false)
    call UnitAddAbility(DummyUnit,'AInv')
    call UnitRemoveAbility(DummyUnit,'Aalr')
    set DummyItem=UnitAddItemById(DummyUnit,id)
    loop
        exitwhen a > MaxAbilities-1
        loop        
            set i = GetStoredInteger(g,"AbilitySet","Database"+I2S(b))
            if i == 'AInv' then
                set b = b + 1
                set i = GetStoredInteger(g,"AbilitySet","Database"+I2S(b))
            endif
            exitwhen GetUnitAbilityLevel(DummyUnit,i) > 0 or b > m
            set b = b + 1
        endloop
        if b > m then
            set i = NoAbility
        endif
        call StoreInteger(g,I2S(id),"Ability" + I2S(a), i)
        call UnitRemoveAbility(DummyUnit, i)
        set a = a + 1
    endloop
    call RemoveItem(DummyItem)
    call RemoveUnit(DummyUnit)                
    set DummyUnit = null        
    set DummyItem = null
    set i = GetStoredInteger(g,I2S(id),"Ability"+I2S(which))
endif    
set g = null
return i 
endfunction

function GetItemTypeAbilityBJ takes integer id, integer which returns integer
return GetItemTypeAbility(id,which-1)
endfunction

function ItemTypeHasAbility takes integer itemid, integer abilityid returns boolean
local integer i=0
loop
    exitwhen i>MaxAbilities-1
    if GetItemTypeAbility(itemid,i) == abilityid then
        return true
    endif
    set i=i+1
endloop
return false
endfunction
endlibrary


Unfortunately, it requires this.

What does it do? Well, as you know, items can have four abilities. What this system does, is takes an item id, and an index, and returns the ability stored on the item. For instance, GetItemAbility('phea',0) will return 'AIh1' ('phea' is Potion of Healing, 'AIh1' is the healing ability on it).

Why do we need it? Well, it's really for some advanced systems, but it can be used on the everyday level. It allows you to eliminate many painful configs involving items (if you want to make something involving item abilities), since it can just go and get them directly from what you put in the object editor. You can use it to add flags to items if you give them dummy abilities, which can be helpful, I guess.

The indexes for GetItemAbility() range from 0-3. GetItemAbilityBJ() ranges from 1-4. Inputing an index that is too high will change it automatically to 3 (or 4, for the BJ). One that is too low will become 0 (or 1).

I've attached a map with a modified version of the system in the above link. To initialize the ability database, you only need to copy the trigger called 'AbilityDatabase' into your map. The library will load it automatically. To use the 'GetItemAbility' function, copy that trigger into your map (but it needs the ability database trigger). Note that GetItemAbility takes the id of an item, not an actual item.


*Lots of Credits to Pitzermike, for writing out the AbilityDatabase system at WC3Jass.com. It is so long that I could not paste it in this post without breaking the size limit.
*There's a chance it won't work since I made the base of it ~2 years ago and decided to just clean it up and submit it.
 

Attachments

  • AbilityDatabase.w3m
    27.2 KB · Views: 200

GoGo-Boy

You can change this now in User CP
Reaction score
40
Yeah, as far as I've heard you can simply shift-click and add further ability raw id's to the item... or doesn't that work?
 

Waaaaagh

I lost all my rep and my title being a jerk
Reaction score
70
Fine. I'll add a constant for max abilities -.-

~Updated.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top