script_game_get_item_buy_price_factor

Users who are viewing this thread

Pr123

Regular
Hello!

I just got into modding and I have a question about this script:
  #script_game_get_item_buy_price_factor:
  # This script is called from the game engine for calculating the buying price of any item.
  # INPUT:
  # param1: item_kind_id
  # OUTPUT:
  # trigger_result and reg0 = price_factor
  ("game_get_item_buy_price_factor",
    [
      (store_script_param_1, ":item_kind_id"),
      (assign, ":price_factor", 100),

      (call_script, "script_get_trade_penalty", ":item_kind_id"),
      (assign, ":trade_penalty", reg0),

      (try_begin),
        (is_between, "$g_encountered_party", centers_begin, centers_end),
        (is_between, ":item_kind_id", trade_goods_begin, trade_goods_end),
        (store_sub, ":item_slot_no", ":item_kind_id", trade_goods_begin),
        (val_add, ":item_slot_no", slot_town_trade_good_prices_begin),
        (party_get_slot, ":price_factor", "$g_encountered_party", ":item_slot_no"),
        (val_mul, ":price_factor", 100), #normalize price factor to range 0..100
        (val_div, ":price_factor", average_price_factor),
      (try_end),
     
      (store_add, ":penalty_factor", 100, ":trade_penalty"),
     
      (val_mul, ":price_factor", ":penalty_factor"),
      (val_div, ":price_factor", 100),

      (assign, reg0, ":price_factor"),
      (set_trigger_result, reg0),
  ]),

Using common sense I understand that this script calculates the price for buying an item, but I would like that someone explains the script, because my programming/coding skills in python are rather poor.

First question: Does this script affect all the items in the game? So if I would like to make all items cheaper or more expensive, would it be easier to modify this script rather than all the items in module_items.py?

Second question: Do I have to modify this script or the get_trade_penalty script to make items more expensive or cheaper? Or both?

And third question: What do all these :price_factor, :penalty_factor, :trade_penalty_factor variables exactly do?

Also the fourth not-so important question: What is the easiest way to make all items cheaper/more expensive at once?

I am sorry if I sound like a complete n00b, but I just got into modifying mount and blade.
 
[quote author= Pr123]but I would like that someone explains the script, because my programming/coding skills in python are rather poor.[/quote]
Poor excuse, aswell!  :razz: This is pure logic (and looking into header files), nothing (much) related to Python..

Basically, this script, at first, gives the :price_factor the value of 100. Then, it gives the :trade_penalty the attribute of reg0. Afterwards, it checks if the guy your buying from if in a town and is selling a trading good, if he is, then make the price lower by a few operations, otherwise, continue on.

In the end, it assigns the registry "0" the value of the new :price_factor aqcuired by the preceding operations and sets the trigger result to it. That means it will run back the value to the engine, the game will read it and set the items price.

EDIT: Btw, you don't sound like a complete noob. It's actually a pretty somewhat complicated script, you should probably start with something easier.

EDIT2:
[quote author= Pr123]First question: Does this script affect all the items in the game? So if I would like to make all items cheaper or more expensive, would it be easier to modify this script rather than all the items in module_items.py?[/quote]
Yes, it does, and yes, you should modify this script to make all items more expensive. Probably increasing the variable :price_factor will do the trick.

[quote author= Pr123]Second question: Do I have to modify this script or the get_trade_penalty script to make items more expensive or cheaper? Or both?[/quote]
I haven't looked at the other script, but I'd say editing only this will do it.

[quote author= Pr123]And third question: What do all these :price_factor, :penalty_factor, :trade_penalty_factor variables exactly do?[/quote]
They're used to calculate the end result. If you look closely at the script and follow through the operations (for the definition of operations, look in header_operations.py).

[quote author= Pr123]Also the fourth not-so important question: What is the easiest way to make all items cheaper/more expensive at once?[/quote]
Possibly by editing this script.
 
Thank you very much! You solved every problem I had with this script(and with get_item_sell_price_factor)!

Wow... I can't believe how stupid I can be. The script just makes operations with variables. val_mul multiplies, val_add adds... It's just too simple. But I blame my lazyness. It's all his fault.

Edit:You were right. Editing :price_factor does make all items more expensive.
 
Back
Top Bottom