Author Topic: Checking the "material" item property on an object  (Read 326 times)

Legacy_Iapetus303

  • Newbie
  • *
  • Posts: 18
  • Karma: +0/-0
Checking the "material" item property on an object
« on: February 17, 2014, 08:52:00 pm »


               I am trying to check what material an object is made of, but can't get the code to work.



The code below is supposed to check if the player has an iron bar, and that it either has the "iron" material type, or no material type.  But when I compile,  I get an "ERROR: DECLARATION DOES NOT MATCH PARAMETERS" for the GetItemHasItemProperty line.

What am I doing wrong?




int StartingConditional()
{

    object oPC = GetPCSpeaker();                        // The PC
    string sItem ="x2_it_cmat_iron";                    // required item token string
    itemproperty ipReqMat = ItemPropertyMaterial(9);    // required item material

    object oItem = GetItemPossessedBy(oPC, sItem);      // The base material object, assuming it exists (returns OBJECT_INVALID if it doesn't)


    // PC doesn't have the object at all, return false
    //if (oItem == OBJECT_INVALID)
    //    return FALSE;
    if(!HasItem(GetPCSpeaker(), sItem))
        return FALSE;

    // if the PC has the object, and the material is correct, return true
    else if ( GetItemHasItemProperty(oItem, ipReqMat) )
        return TRUE;

    // or the PC has the object, and the material is undefined, return true
    else if (GetItemHasItemProperty(oItem, ItemPropertyMaterial(0)))
        return TRUE;

    // otherwise, the item has the wrong material type, so return false
    else
        return FALSE;

}

               
               

               


                     Modifié par Iapetus303, 17 février 2014 - 09:07 .
                     
                  


            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Checking the "material" item property on an object
« Reply #1 on: February 17, 2014, 11:09:32 pm »


               GetItemHasItemProperty expects the second argument to be an integer (such as an ITEM_PROPERTY_* constant) but yours has type itemproperty.

I imagine you have to cycle through the item's properties, using GetItemHasItemProperty to find one with ITEM_PROPERTY_MATERIAL. If there is one, I suspect GetItemPropertyParam1Value may give you the material constant, but I haven't verified that.
               
               

               


                     Modifié par Proleric1, 18 février 2014 - 07:14 .