Skip to content

Checking If An Item Is Equipable

echooechoo Member Posts: 43
edited December 2019 in Builders - Scripting
I'm making a tag based scripting widget that checks if an item is equipable (and meets level requirements in a scripted item level restriction system). In this case, the widget only works when clicking on items in a player inventory.

My script checks for base item types that are able to be equipped by the player. The problem is that it always returns as FALSE—no matter which inventory item the widget is used on (equipable or not).

The check relies on a big GetBaseItemType conditional that apparently isn't working.

The script that's not working correctly (script name - j_ilrchecker): https://pastebin.com/igfhRXUP
An include used for the above script (name - j_inc_itemlvl): https://pastebin.com/x1gMLKFz

Widget item tag name: "j_ilrchecker" with Cast Spell: Unique Power (Unlimited Uses/Day)

Any help will be appreciated, especially alternate ways to check if an item can be equipped in an inventory slot.

Thanks

Comments

  • KamirynKamiryn Member Posts: 74
    edited December 2019
    if (GetBaseItemType(oTarget) != BASE_ITEM_AMULET || BASE_ITEM_ARMOR || BASE_ITEM_ARROW || ...
    

    That part will never work!

    Should be something like
    int nBaseItemType = GetBaseItemType(oTarget);
    if ((nBaseItemType != BASE_ITEM_AMULET) && (nBaseItemType!=BASE_ITEM_ARMOR) && ...)
    {
    	...
    

    or at least
    if (GetBaseItemType(oTarget) != BASE_ITEM_AMULET || GetBaseItemType(oTarget) != BASE_ITEM_ARMOR || GetBaseItemType(oTarget) != BASE_ITEM_ARROW || ...
    


    I however would probably write something like:
    switch (GetBaseItemType(oTarget))
    {
    case BASE_ITEM_AMULET:
    case BASE_ITEM_ARMOR:
    case ...
    	return TRUE;
    	break;
    }
    return FALSE;
    
    Post edited by Kamiryn on
  • echooechoo Member Posts: 43
    edited December 2019
    Will test it out later today. Thanks! :)
  • KamirynKamiryn Member Posts: 74
    You could also read column 'EquipableSlots' from baseitem.2da. Seems that for equippable items it's somthing != 0x00000:
    int GetEquippable(object oTarget)
    {
    	return (Get2DAString("baseitem","EquipableSlots", GetBaseItemType(oTarget)) != "0x00000"); 
    }
    
  • echooechoo Member Posts: 43
    Using the "switch (GetBaseItemType(oTarget))" worked for me flawlessly. Just a matter of entering the large list of base item types.

    I tried your Get2DAString method. It would have been easier, but it returned TRUE for all items, not just equippable ones (in my initial test).

    Thanks again!
  • KamirynKamiryn Member Posts: 74
    Ah sorry, the name of the 2da file was misspelled (it's baseitems.2da) :/ ... this should work:
    int GetEquippable(object oTarget)
    {
    	return (Get2DAString("baseitems","EquipableSlots", GetBaseItemType(oTarget)) != "0x00000"); 
    }
    
  • echooechoo Member Posts: 43
    No worries.

    It's some nwscript sorcery. Nice work! :)
Sign In or Register to comment.