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: 202

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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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