Author Topic: Get Value of a Custom Item Property?  (Read 2204 times)

Legacy_Zeke

  • Jr. Member
  • **
  • Posts: 86
  • Karma: +0/-0
Get Value of a Custom Item Property?
« on: July 11, 2016, 06:10:22 pm »


               

After tinkering with CEP I saw a new Item property - Use Limitation: Gender.


 


ehEiy3n.jpg


 


It doesn't have or at least I can't find any functionalities implemented, so I started implementing my own. I saw in itempropdef.2da that the ID of the property is 150 and that it is getting its values from gender.2da


 


nahK7eA.jpg


 


The problem is that I can't get what gender is selected (I think it's called subtype?) for it to limit.


 


GetItemPropertyCostTableValue() in the following function always returns 0:



// This scipt is attached on OnPlayerEquipItem

object oItem = GetPCItemLastEquipped();
object oPC   = GetPCItemLastEquippedBy();
itemproperty ipLoop = GetFirstItemProperty(oItem);

while (GetIsItemPropertyValid(ipLoop))
{   
   if  (GetItemPropertyType(ipLoop) == 150 ) // Check to see if the item has UseLimitationGender
      {
         int nCost = GetItemPropertyCostTableValue(ipLoop);
         SendMessageToPC(oPC, IntToString(nCost));
      }

   ipLoop = GetNextItemProperty(oItem);
}

I guess GetItemPropertyCostTableValue() is not the function I have to use?


 


 


Yes, I know all of this can be achieved with a simple variable on the equipment but I want to use the property (it has a text in the game interface).



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Get Value of a Custom Item Property?
« Reply #1 on: July 11, 2016, 06:36:25 pm »


               

You want the subtype. i.e. : GetItemPropertySubType(ipLoop).



               
               

               
            

Legacy_Zeke

  • Jr. Member
  • **
  • Posts: 86
  • Karma: +0/-0
Get Value of a Custom Item Property?
« Reply #2 on: July 11, 2016, 07:00:18 pm »


               

Ah, sounds so logical. Couldn't find this function in the Lexicon... Thank you, once again!



               
               

               
            

Legacy_Zeke

  • Jr. Member
  • **
  • Posts: 86
  • Karma: +0/-0
Get Value of a Custom Item Property?
« Reply #3 on: July 11, 2016, 08:36:27 pm »


               

Oh, and now - a bonus question time!


 


Is there OnEquip for henchmen? Because currently, if I make Female-Only Armor, I can equip it on a male henchman.



               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Get Value of a Custom Item Property?
« Reply #4 on: July 12, 2016, 04:29:49 am »


               

No, OnPlayerEquipItem is only for players. You have to prevent the henchman from acquiring the item in OnAcquireItem. This is my custom code for single player:


 



   Spoiler
   


 


Sorry that oPC is a confusing variable name, it ought to be oHenchman or whatever, but I don't have time to edit it this morning!



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Get Value of a Custom Item Property?
« Reply #5 on: July 12, 2016, 01:57:24 pm »


               

@proleric, does that actually work? I've been under the impression that OnAcquireItem and friends also only fire for PCs. 



               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Get Value of a Custom Item Property?
« Reply #6 on: July 12, 2016, 06:19:08 pm »


               Yes, it works. Live code from my Dark Energy module. OnPlayerX events only work for player (the clue is in the name) but OnAcquireItem works for NPCs.
               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Get Value of a Custom Item Property?
« Reply #7 on: July 12, 2016, 06:53:17 pm »


               

Interesting!


 


Someone should update some of the lexicon pages then.  Grimlar's Tag based scripting tutorial, for example, clearly says no (at least in the CHM version).  Having read that I had not bothered looking at it closely...  Does it fire when stores acquire items or just creature objects? Chests?


 


I like the ghosting visuals hack. I'm going to crib that one for my cursed item stuff which has that issue '<img'>


               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Get Value of a Custom Item Property?
« Reply #8 on: July 13, 2016, 12:45:51 am »


               

Well cool.  Seems to fire for all creatures. How about activate? I did not think you could make NPCs activate item special powers.   I guess I need to use a bigger grain of salt when looking at the lexicon '<img'>



               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Get Value of a Custom Item Property?
« Reply #9 on: July 13, 2016, 10:13:34 pm »


               I don't know of a way to force a creature to activate an item (unless there is some backdoor using spell functions). If that's correct, then OnActivateItem is player-only.


You could, of course, by-pass the event, by modding the creature AI to execute a similar script if it has the item in inventory and ought to activate it. I do something like that with thieves' tools, for example.
               
               

               
            

Legacy_Zeke

  • Jr. Member
  • **
  • Posts: 86
  • Karma: +0/-0
Get Value of a Custom Item Property?
« Reply #10 on: July 15, 2016, 04:18:39 pm »


               

Aah, this worked! Nice!


 


What is the purpose of the last line (the conversation one)?


 


And what is that ghosting visuals hack that meaglyn talks about?



               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Get Value of a Custom Item Property?
« Reply #11 on: July 18, 2016, 04:20:29 pm »


               The conversation simply displays custom token 12. Sorry, should have explained that. If you prefer floaty text or a message instead, no problem. I prefer conversation because it's more obvious and has to be cleared by the player once read.


Dummy out the OpenInentiory lines to see the ghosting they prevent.