HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

GettingItemAbilities

05-24-2007, 03:33 AM#1
Here-b-Trollz
GetItemAbility is a function that takes an integer (item id) and an integer (which) and returns the ability the item id has. It is extremely useful for eliminating configuration functions, as well as for simply retrieving information about an item. Credits to Weaaddar (actually more to him than me) for the idea.

Collapse Here is the Code:
function GetItemAbility takes integer id, integer which returns integer
    local gamecache g=udg_gc
    local unit DummyUnit
    local integer i
    local integer a = 0
    local integer b = 1
    local integer m
    if which > 3 then
        set which=3
    elseif which < 0 then
        set which=0
    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),GetDummyId(),0.0,0.0,0.0) 
        call ShowUnit(DummyUnit,false)
        call UnitAddAbility(DummyUnit,'AInv')
        call UnitRemoveAbility(DummyUnit,'Aalr')
        call UnitAddItemById(DummyUnit,id)
        loop
            exitwhen a > 3
            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 = 'Abdt'
            endif
            call StoreInteger(g,I2S(id),"Ability" + I2S(a), i)
            call UnitRemoveAbility(DummyUnit, i)
            set a = a + 1
        endloop
        call RemoveUnit(DummyUnit)
        set i = GetStoredInteger(g,I2S(id),"Ability"+I2S(which))
    endif    
    set DummyUnit = null        
    set g = null
    return i 
endfunction



You must be using PitzerMike's ability database functions to use this, and this version uses a gamecache called udg_gc. Call it at anytime (after initializing the ability database, that is)!
05-24-2007, 03:47 AM#2
weaaddar
well you can use vjass and some slks to preload the data to structs for the abilities. Items can only have 4 abilities I think so you can probably store about 2000 item definitions.
05-24-2007, 03:56 AM#3
Here-b-Trollz
Can anybody see any abilities that I might have missed (as far as removing) that all units have? (Aalr I think is one...)
05-24-2007, 01:00 PM#4
weaaddar
Look in weHelper manual and check out the slk demo. You'll still need gamecache, and you probably will have to edit the Slk file to remove fields you don't care about.
05-24-2007, 02:01 PM#5
UnMi
How about, using native gamecache?
call StoreInteger(udg_gamecache,"Item Abilities","Staff of Silence",'A000') And in order to get it, use
GetStoredInteger(udg_gamecache,"Item Abilities",GetItemName(item)
05-24-2007, 05:47 PM#6
weaaddar
THe problem is that given a map using standard melee items that is a righteous pain in the ass as there is HUNDREDS of them. vJass getting information from an SLK makes this hugely easier.
Plus many items have more then one ability so you would need some sort of indexing not just the name, but maybe name+index
05-24-2007, 10:22 PM#7
Toadcop
or you would better use some advanced sys... for example my BX-TRSII xD !
// but i would not get the full potential of it =(
05-25-2007, 03:57 AM#8
weaaddar
As the only person I know whose written an item based spellbook my advice is to give up. It's a bit easier now that we have vjass. But since you want to add the abilities from the item to the unit (at least thats what I assume) you'll find that its very annoying as abilities give you nothing. You'll need a queueing system as units can only display certain amount of data you'll need triggers for channeling spells you'll need timers to figure out when spells are running, if they are removable etc. Its really an annoying horrible system.
05-25-2007, 07:42 PM#9
weaaddar
It's actually really impossible to do anyway, items have pasive abilities and such too.

Here is my old implementation of the spellbook:
http://eden.rutgers.edu/~weaaddar/war3e/bag3a.w3x

You can also try this horrible looking function to try to do it on the fly:
http://wc3jass.com/viewtopic.php?t=3...t=item+ability

When a unit aquires an item the abilities are basically added to him so you'll just have to loop through trying to figure out if the item added an ability or not.

Oh that means that you could be losing ability spaces and so your way won't work.
06-19-2007, 08:40 PM#10
Here-b-Trollz
I really hate to double post, but, as I slowly descended into madness for the (3, was it?) weeks Wc3Campaigns was down, my only salvation was TheHelper.net, and Weaaddar's last D4-somethin' or another system. Only two days ago, I finally got this function working! (I am now back to doing it on the fly, and the function runs surprisingly fast).

A deletion of my other posts is rather imminent, as they can not be used at all for reference, on account of I completely rewrote the function.

Collapse Here is the Code:
function GetItemAbility takes integer id, integer which returns integer
    local gamecache g=udg_gc
    local unit DummyUnit
    local integer i
    local integer a = 0
    local integer b = 1
    local integer m
    if which > 3 then
        set which=3
    elseif which < 0 then
        set which=0
    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),GetDummyId(),0.0,0.0,0.0) 
        call ShowUnit(DummyUnit,false)
        call UnitAddAbility(DummyUnit,'AInv')
        call UnitRemoveAbility(DummyUnit,'Aalr')
        call UnitAddItemById(DummyUnit,id)
        loop
            exitwhen a > 3
            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 = 'Abdt'
            endif
            call StoreInteger(g,I2S(id),"Ability" + I2S(a), i)
            call UnitRemoveAbility(DummyUnit, i)
            set a = a + 1
        endloop
        call RemoveUnit(DummyUnit)
        set i = GetStoredInteger(g,I2S(id),"Ability"+I2S(which))
    endif    
    set DummyUnit = null        
    set g = null
    return i 
endfunction


You must be using PitzerMike's ability database functions to use this, and this version uses a gamecache called udg_gc. Call it at anytime (after initializing the ability database, that is)!