logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Windows functions - NWNx_funcs - SetItemValue

 
Post new topic   Reply to topic    nwnx.org Forum Index -> General Discussion
View previous topic :: View next topic  
Author Message
BelowTheBelt



Joined: 28 Jul 2010
Posts: 29

PostPosted: Sun Mar 16, 2014 5:52    Post subject: Windows functions - NWNx_funcs - SetItemValue Reply with quote

I'm using the windows version of the Functions plugin, specifically the SetItemValue function. I'm running into some behavior different than my expectation and was hoping to get some insight.

I use the function to set an item's value, hoping to help manage the world's economy by mitigating the value of magic items.

I set the value through: NWNXFuncs_SetItemValue (oItem , iValue);

A few questions:

1) When I take the item to a merchant, the item's value is not affected - it still sells for the original gp value. Does this function affect the actual value of the item as determined by merchants?

2) I presume to use the IDENTIFIED VALUE as what I'm setting, but should I be using the UNIDENTIFIED VALUE or possibly a negative ADDITIONAL COST value to reduce the value of an item?

2) Does SetItemValue persist over resets?

Thanks!
_________________
www.arenthyor.com
Back to top
View user's profile Send private message Visit poster's website
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Mon Mar 17, 2014 3:00    Post subject: Reply with quote

Code:

int CNssItems::SetItemValue(CGameObject *oObject, char *Params) {
   CNWSItem *Item = oObject->AsNWSItem();
   if (!Item) {
      _log(2, "o Error SetItemValue used on non-item object.\n");
      sprintf(Params, "-1");
      return 0;
   }

   uint32_t Value, ValueType, ZeroAdditionalValue;
   CParams::ExtractP3<uint32_t>(Params, Value, ValueType, ZeroAdditionalValue);

   if (Value < 0) Value = 0;

   switch (ValueType) {
      case ITEM_VALUE_IDENTIFIED   :
         Item->it_cost_ided = Value;
         if (ZeroAdditionalValue) Item->it_cost_add = 0;
      break;
      case ITEM_VALUE_UNIDENTIFIED: Item->it_cost_unided = Value; break;
      case ITEM_VALUE_ADDITIONAL   : Item->it_cost_add = Value; break;
   }

   return 1;
}


There appears to be 3 different modes of use.
Identified, Unidentified, and Additional/
It appears that you should be able to use the
ITEM_VALUE_IDENTIFIED
option, along with the Zero additional : to set the end price of the item.

Have you tried the different options?

This is the function declaration from Maxrocks funcs.

Code:

// Sets one of 3 different item values, determined by iType
// The value of an (identified) item is Identified Value + Additional Cost/Value
// ITEM_VALUE_IDENTIFIED: The item value when the item is identified. If bZeroAdditionalCost is TRUE, the additional cost of the item will be set to zero. (just to save a function call)
// ITEM_VALUE_UNIDENTIFIED: The value of an item as long as it is unidentified
// ITEM_VALUE_ADDITIONAL: An additional value which is added to the identified value of the item (This was used in the toolset since there was no other way of
// directly adjusting the value of an item. Can be set beyond the 32,000 allowed in the toolset.
void NWNXFuncs_SetItemValue(object oItem, int iValue, int iType = ITEM_VALUE_IDENTIFIED, int bZeroAdditionalCost = TRUE);


And yes - because the changes are made to the gff object for the item, the changes will persist beyond resets, unless for some reason the item is modified further by item property additions etc: which may cause the engine to recalculate the price/value.
Back to top
View user's profile Send private message
BelowTheBelt



Joined: 28 Jul 2010
Posts: 29

PostPosted: Mon Mar 17, 2014 17:53    Post subject: Reply with quote

Thanks for the help.

This is part of a unique item generation system, so I'm setting the value of the item after applying any item properties. I use the function to make the items fall within my custom ILR requirements and want to make sure items have a merchant value that is relevant to the world.

By setting value, I'm by default using the Identified parameter and zero additional cost. I've not tried setting it via the other parameters, as it seems to be 'working' (see below), just not with merchants.

After I set the item's value, I tried a separate GetGoldPieceValue call on the item and confirmed that the value of the item is indeed changed (it returns the revised value). So I guess that it is indeed working.

However, when I go to a merchant with the item (as a DM, not sure if that matters), the price he offers is based upon the original value of the item, rather than being based off of the revised GP value of the item.

Do merchants calculate item costs differently or separately from a standard GetGoldPieceValue call? I also use the markup/markdowns on the merchants.

For example:
Original unmodified item gp value: 144,536
SetItemValue gp value: 9,635
Actual Merchant offer for item: 14,453

I would have expected the Merchant to offer 963 based upon the SetItemValue revised value.
_________________
www.arenthyor.com
Back to top
View user's profile Send private message Visit poster's website
BelowTheBelt



Joined: 28 Jul 2010
Posts: 29

PostPosted: Mon Mar 17, 2014 20:55    Post subject: Reply with quote

Possibly of interest, too, is that when the item is examined, the gp value is still the original gp, not the revised SetItemValue gp.

I'm not sure if the item or data is supposed be updated after the SetItemValue call to change that, or if whatever is pulling that information for the view is also being used by the merchant.
_________________
www.arenthyor.com
Back to top
View user's profile Send private message Visit poster's website
BelowTheBelt



Joined: 28 Jul 2010
Posts: 29

PostPosted: Tue Mar 18, 2014 0:27    Post subject: Reply with quote

Well, I think I've figured it out, based on your comment about the engine recalculating the cost.

A couple of functions in my system, just prior to setting the item's revised value, affect the item's description. One time to add the item's level and a second time to add the item's quality. I was setting the value inside the script after calling those functions via an include.

I presume that the way the engine works with its processing of the functions, the #include functions affecting the item's description were being called or processed after the SetItemValue had been set (and was subsequently overwritten).

So, I put in a short delay in setting the item's revised value and it seems to work - the correct value is displayed on the item when it is viewed. It isn't the way I'd prefer to do it...I don't like to use DelayCommand in this way, but it works.

Does this seem to make sense?
_________________
www.arenthyor.com
Back to top
View user's profile Send private message Visit poster's website
BelowTheBelt



Joined: 28 Jul 2010
Posts: 29

PostPosted: Wed Mar 19, 2014 2:55    Post subject: Reply with quote

A couple of strange quirks with this function I've noticed:

1) It won't set the item value on bullets, bolts, shuriken, darts, throwing axes, or arrows if those items have item properties.

I wrote a loop to attempt to set the value continuously if, after a GetGoldPieceValue call, the item does not have the revised price. Those items never get the correct price.

Is there something different with the cost parameter/field of these ammo/thrown weapons that this function is not hooking into correctly?

2) Unidentified items 'might' be able to be set, but once they are identified, they go back to their original value (if it was every set correctly). Using the same looping check as above, it appears that it 'was' set (the Gold Piece value of the item equaled the revised price), but whenever I viewed the item to identify it, the price was always the original price.

My earlier issues seem to have stemmed from the unid'd issue, which is still an issue. I've temporarily solved it by not setting the items as unidentified in the custom item script (which is a bummer, as what's more fun than finding a weapon so good that you can't tell what is is?!)
_________________
www.arenthyor.com
Back to top
View user's profile Send private message Visit poster's website
BelowTheBelt



Joined: 28 Jul 2010
Posts: 29

PostPosted: Wed Mar 19, 2014 21:35    Post subject: Reply with quote

I was able to solve the bolt, dart, shuriken, arrow, and throwing axe issue. Since those are stacked items, the SetItemValue function would not return the same as a GetGoldPieceValue call, since the SetItemValue tries to set the value of 1 item, whereas the GetGoldPieceValue call gets the value of the stacked size.

By moving the creation of the stack size to a point below where I set the value, the value is set on 1 item and then the stack is applied on top of that, making the value become a multiple of that one item's cost.
_________________
www.arenthyor.com
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> General Discussion All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group