HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Item type detection

09-15-2006, 08:39 AM#1
burnt_pizza
Hey I'm trying to set up a map and I've come across a problem with items. I have a number of items that are weapons (such as swords etc) and I want to somehow make it that a hero can carry only one weapon at a time (ie can't pick up a weapon if one is already equipped). I've had a look at a few different triggers but can't find anything that allows me to do it.

Any help or links to other threads/sites that will help would be greatly appreciated.
09-15-2006, 12:58 PM#2
Naakaloh
You can use one of several different methods, but if you're looking for something easy just try setting setting an initial condition the defines the type of item, so when you try to pick it up you can tell what type of item it is.

Collapse JASS:
function IsItemWeapon takes item i returns boolean

    if( GetItemTypeId(i) == 'IAAA' ) then
        return true
    elseif( GetItemTypeId(i) == 'IAAB' ) then
        return true
    else
        retrun false
    endif

endfunction 

Another idea is give each item type an integer value, so you check the integer value associated with the item.

Collapse JASS:
function GetItemTypeInteger takes item i returns integer

// 0 == Misc or null
// 1 == Armor
// 2 == Weapon
// 3 == etc.

    if( GetItemTypeId(i) == 'IAAA' ) then
        return 1
    elseif( GetItemTypeId(i) == 'IAAB' ) then
        return 2
    else
        retrun 0
    endif

endfunction 
09-15-2006, 02:06 PM#3
Vexorian
hmnn, but don't those methods simply suck?

If gamecache is good for something is for tables. I doubt you really need speed here, I also don't think you can make a faster alternative.


Collapse JASS:
call StoreInteger(somegamecache,"Itemtypes",I2S('Imsk'), 1 ) // type 1 is weapon
call StoreInteger(somegamecache,"Itemtypes",I2S('Iask'), 7 ) // type 7 is helmet

To get just use GetStoredInteger(somegamecache,"Itemtypes",I2S(GetItemTypeId(it))) and you got it's type.


it is even easy to give multiple item types to an item
09-15-2006, 06:41 PM#4
Naakaloh
Well, yes... they do suck... I wouldn't use them, but they are simple and easy. (That's not to say that using gamecache isn't straightforward, but not everyone thinks so...)