Author Topic: Check for a specific property  (Read 365 times)

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
Check for a specific property
« on: September 09, 2012, 03:19:47 pm »


               I need to place a check in a script so that the script only fires when the equipped item has the following properties, (IP_CONST_LIGHTBRIGHTNESS_BRIGHT, IP_CONST_LIGHTCOLOR_WHITE) I can't seem to figure out how to make the check however.

TY in advance
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Check for a specific property
« Reply #1 on: September 09, 2012, 04:03:16 pm »


               untested at the moment. 

Try :

  if (
        GetItemPropertyType(iProp) == ITEM_PROPERTY_LIGHT
      &&GetItemPropertyCostTableValue(iProp)== IP_CONST_LIGHTBRIGHTNESS_BRIGHT
      && GetItemPropertyParam1Value(iProp)== IP_CONST_LIGHTCOLOR_WHITE
     )
               
               

               
            

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
Check for a specific property
« Reply #2 on: September 09, 2012, 04:42:40 pm »


               TY .. my own attempts failed as I wasn't first getting the base light property I think.
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Check for a specific property
« Reply #3 on: September 09, 2012, 04:44:38 pm »


               Removed since it did not work to try and get the visual effect.

Although this does work:
//ffbj
void main()
{
object oPC=GetEnteringObject();
 if (!GetIsPC(oPC)) return;
   object oItem =  GetItemInSlot( INVENTORY_SLOT_LEFTHAND, oPC);
 if  (
       GetItemHasItemProperty(oItem, IP_CONST_LIGHTBRIGHTNESS_BRIGHT)
      && GetItemHasItemProperty(oItem, IP_CONST_LIGHTCOLOR_WHITE)
     )
 
   FloatingTextStringOnCreature("Light", oPC,TRUE);
}
               
               

               


                     Modifié par ffbj, 09 septembre 2012 - 07:46 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Check for a specific property
« Reply #4 on: September 09, 2012, 08:41:03 pm »


               

ffbj wrote...

Removed since it did not work to try and get the visual effect.


Bummer, I was hoping it would.
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Check for a specific property
« Reply #5 on: September 09, 2012, 08:50:34 pm »


               I can only assume the visual effects are pre-supposed to be on placeable and creatures, while properties, understandably only go on items. Although you can use the function GetItemHasProperty as above, which seems a bit simpler, though it does not seem to work. Though I thought it did till I moved brackets.
(There is a constant int ITEM_PROPERTY_VISUALEFFECT, though I don't think you want or need that in this case. Not sure how that would work.  For instance in determing if an item had any visual effect on it, so in that case going from the general to the specific.  And a use in a specific case would be to remove a visual effect without affecting the property on the item.  There must be something on that in the darkness spells for a better understanding of the various realtionships.
               
               

               


                     Modifié par ffbj, 09 septembre 2012 - 08:23 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Check for a specific property
« Reply #6 on: September 09, 2012, 09:30:25 pm »


               That looks like it would work,  Assuming that the item had only one light property on it.    An item with a Dim white and a bright red would still return true, with your code.
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Check for a specific property
« Reply #7 on: September 09, 2012, 11:38:52 pm »


               Yes, since GetHasProperty only seems to detect if something has light on it, not the sub-type properties.  So it is useless for this specific instance.
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Check for a specific property
« Reply #8 on: September 10, 2012, 01:44:36 am »


               #include "x2_inc_itemprop"

//ffbj
void main()
{
object oPC=GetEnteringObject();
if (!GetIsPC(oPC)) return;

object oItem = GetItemInSlot( INVENTORY_SLOT_LEFTRING, oPC);
itemproperty iProperty = ItemPropertyLight(IP_CONST_LIGHTBRIGHTNESS_BRIGHT,IP_CONST_LIGHTCOLOR_WHITE);
if

(IPGetItemHasProperty(oItem, iProperty, -1, TRUE))
{
SendMessageToPC(oPC, "Bight White Light");
}

}


Function Description:

IPGetItemHasProperty(object, itemproperty, int, int)
Checks if an item has a matching itemproperty.int IPGetItemHasProperty(
    object oItem,
    itemproperty ipCompareTo,
    int nDurationType,
    int bIgnoreSubType = FALSE
);
Parameters
oItem
Item to check for property.
ipCompareTo
ItemProperty to compare to
nDurationType
See description and remarks.
bIgnoreSubType
TRUE to ignore subtype. Otherwise FALSE. (Default: FALSE)

Description
Wrapper for GetItemHasItemProperty that returns true if oItem has an itemproperty that matches ipCompareTo by Type AND DurationType AND SubType

nDurationType = Valid DURATION_TYPE_* or -1 to ignore
bIgnoreSubType - If set to TRUE an item property will be considered identical even if the SubType is different.


Remarks
Only DURATION_TYPE_TEMPORARY, DURATION_TYPE_PERMANENT, and -1 are valid for nDurationType.

This differs from GetItemHasItemProperty in several ways. First of all because it also takes duration type and subtype into account. And also because it uses an itemproperty value for parameter, instead of the ITEM_PROPERTY_* integer constant.

Returns TRUE if oItem has the same type of itemproperty that ipCompareTo is. If nDurationType is different from -1, it also needs to be that same duration type. If bIgnoreSubType is FALSE, it also needs to be of the same subtype.

Returns FALSE if the above isn't mean. It also prints "Not Found" to the log.

Requirements
#include "x2_inc_itemprop"
               
               

               


                     Modifié par ffbj, 10 septembre 2012 - 12:58 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Check for a specific property
« Reply #9 on: September 10, 2012, 02:14:39 am »


               

ffbj wrote...

#include "x2_inc_itemprop"

//ffbj
void main()
{
object oPC=GetEnteringObject();
if (!GetIsPC(oPC)) return;

object oItem = GetItemInSlot( INVENTORY_SLOT_LEFTRING, oPC);
itemproperty iProperty = ItemPropertyLight(IP_CONST_LIGHTBRIGHTNESS_BRIGHT,IP_CONST_LIGHTCOLOR_WHITE);
if

(IPGetItemHasProperty(oItem, iProperty, -1, TRUE))
{
SendMessageToPC(oPC, "Bight White Light");
}

}



No good,  That function only check  PropertyType && ItemPropertySubType.  

Light has no sub type.  It only has a Pram1 for the color and a CostTablevalue for the brightness.

So that function will return TRUE for any light on the item. 

I tested the first code fragment i posted and it works.
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Check for a specific property
« Reply #10 on: September 10, 2012, 02:28:56 am »


               Ok. So it does not check the properties of the light, just the fact there is one. So how do you get the object? As posted the fragment you gave only lists the properties not the properties on the item. I guess that's what I don't get. Unless you are using a while loop.  There does not seems to be a function that gets all the properties on an item, maybe the number but not the specific properties.
               
               

               


                     Modifié par ffbj, 10 septembre 2012 - 01:42 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Check for a specific property
« Reply #11 on: September 10, 2012, 02:48:27 am »


               int GetHasIPBrightWhite(object oItem)
{

   itemproperty iProp = GetFirstItemProperty (oItem);

   while( GetIsItemPropertyValid(iProp))
   {
    if (
        GetItemPropertyType(iProp) == ITEM_PROPERTY_LIGHT
        &&GetItemPropertyCostTableValue(iProp)== IP_CONST_LIGHTBRIGHTNESS_BRIGHT
        && GetItemPropertyParam1Value(iProp)== IP_CONST_LIGHTCOLOR_WHITE
       ) return TRUE;
    iProp = GetNextItemProperty (oItem);
   }
  return FALSE;
}
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Check for a specific property
« Reply #12 on: September 10, 2012, 04:52:55 am »


               Yeah, that's what I figured a while loop.  It seems that is the only way since the function that will create an item with those parameters cannot be used to retrieve the said object.  That seems odd that the function only works one way.
Thanks for the instruction.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Check for a specific property
« Reply #13 on: September 10, 2012, 07:43:54 am »


               

ffbj wrote...

Yeah, that's what I figured a while loop. It seems that is the only way since the function that will create an item with those parameters cannot be used to retrieve the said object. That seems odd that the function only works one way.
Thanks for the instruction.


It may have to do with the fact that the prop on the item has a duration Type.   The prop created in the script, having never been applyed to an item, having a null entry for the druation and duration type.  I have never looked at the comparsion operator of Item Propterys to see what it compairs.


EDIT: If I get a wild hair tomorow, I might just do that. (the wet messy hair on the cat avatar not included)  
               
               

               


                     Modifié par Lightfoot8, 10 septembre 2012 - 06:45 .
                     
                  


            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Check for a specific property
« Reply #14 on: September 10, 2012, 11:32:16 pm »


               Yeah.  I think that makes sense, because in creating an item with the property light, in the toolset there are the paramters of light color and brightness too.  I imagine that if it ever came up that maybe someone wants to find the color and brightness of a light on an item, oh well they can just do a while loop to get those properties, besides there may be more properites on an item anyway.
It seems to mirror the thinking with get first effect etc..Earlier... the ip visual effect question, which can only be put on weapons could present a way to get bight white light if it's on a weapon.
.
So that function compares the item property type, and the duration and the subtype, but you can just tell it to ignore the last two properties, if you want. Just conjecturing that that function was implemented originally as a way to curtail certain exploits.  The continual light one for instance.