Aller au contenu

Photo

Check for a specific property


  • Veuillez vous connecter pour répondre
14 réponses à ce sujet

#1
kalbaern

kalbaern
  • Members
  • 824 messages
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

#2
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
untested at the moment. 

Try :

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

#3
kalbaern

kalbaern
  • Members
  • 824 messages
TY .. my own attempts failed as I wasn't first getting the base light property I think.

#4
ffbj

ffbj
  • Members
  • 593 messages
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 .


#5
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

ffbj wrote...

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


Bummer, I was hoping it would.

#6
ffbj

ffbj
  • Members
  • 593 messages
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 .


#7
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
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.

#8
ffbj

ffbj
  • Members
  • 593 messages
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.

#9
ffbj

ffbj
  • Members
  • 593 messages
#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 .


#10
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

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.

#11
ffbj

ffbj
  • Members
  • 593 messages
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 .


#12
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
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;
}

#13
ffbj

ffbj
  • Members
  • 593 messages
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.

#14
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

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 .


#15
ffbj

ffbj
  • Members
  • 593 messages
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.