Merchant

From Dragon Age Toolset Wiki
Jump to: navigation, search

A merchant resource keeps track of an inventory of items that can be bought and sold, along with various properties to determine the details of those deals.

A merchant is placed in the area editor, but it cannot be seen or interacted with directly by the player. In theory you could place the merchant object anywhere in an area, but in practice it is best to place the merchant object in close proximity to the location where the player will be interacting with it.

Triggering in dialog

The use of a merchant's store is triggered by a script, specifically by the OpenStore function. This function is usually called by a script triggered in a conversation with an NPC merchant.

To simplify matters you could write a generic "store opening" script using a code snippet such as:

// Open a store
#include "core_h"
 
void main()
{
    object oMerchantOwner = OBJECT_SELF;
    object oStore = GetObjectByTag("store_" + GetTag(oMerchantOwner));
 
    if(IsObjectValid(oStore))
    {
        ScaleStoreItems(oStore);
        OpenStore(oStore);
    }
    else
    {
        Log_Trace(LOG_CHANNEL_SYSTEMS, GetCurrentScriptName(), "INVALID STORE OBJECT");
    }
}

You would then be able to reuse this script for all merchants in your game by tagging each merchant object with the same tag as the creature you're conversing with to open the store and adding the "store_" prefix to the merchant's tag. So for example if you have a character in your game whose tag is "fishmonger_alice", you could set the above script to run as an "action" script in her dialog tree and when that node is reached it'll open the store with the tag "store_fishmonger_alice", and if you used the same action script in a dialog attached to "blacksmith_steve" it would open the store with the tag "store_blacksmith_steve".

A script with this generic approach can be triggered by setting the plot flag "GEN_OPEN_STORE" in the "gen00pt_generic_actions" plot. This plot is a wrapper for commonly used generic conversation script code like this.

Variables

Variable name Type Default Description
MERCHANT_COUNTER_1 to 3 int [Undocumented]
MERCHANT_HIGH_CHANCE float [Undocumented]
MERCHANT_IS_SCALED int [Undocumented]
MERCHANT_LEVEL_MODIFIER int [Undocumented]
MERCHANT_LEVEL_OVERRIDE int [Undocumented]

Properties

General
Comments General information about this merchant
Name Name of this merchant as seen within the game.
NameRequiresReTranslation A flag used in game development during localization
Resource Name A unique string identifier the toolset and the game both use to refer to this resource.
Script Event script assigned to the resource. The default merchant_core script contains only an empty main() function.
Tag A non-unique string identifier used mostly by scripts and other resources to refer to this resource.
Variable 2da Allows selecting a variable table. Only the values in the table can be set and retrieved by scripting.
Variables Displays the table selected in the "Variable 2da" field. Allows setting intial values for parameters.
Inventory
Inventory a list of the items the merchant has for sale.
Restricted Items A list of types of items that the merchant can be set to refuse to buy, or alternately can be set to buy exclusively. For example, you could set a pacifistic merchant to refuses to deal in weapons or armor, or set a hunter to only buy arrows and other such items that are useful to him.
Pricing
Buy Mark Down a percentage value dictating how much the price of items the merchants buy from the player is scaled down from their default price
Sell Mark Up percentage value of how much the price of items sold by the merchant to the player is scaled up from their default price.

Inventory

Merchant inventory in "item palette" selection mode, the default
Merchant inventory in "store panel" selection mode

The inventory Ellipsis.png button brings up the merchant inventory selection screen. This screen is similar to the inventory screen used by the creature or placeable editors, with a list of all available items that can be placed in the merchant's inventory to the left and a list of all the items currently in the merchant's inventory to the right. It defaults to the "item palette" selection mode, which shows items in the same subfolder arrangement that they appear in the resource palette. It can also be set to the "store panel" selection mode, which groups all items into the general categories that they would appear in when in the merchant's inventory. This can be useful if you've got (for example) armor items scattered through several different folders of your palette or mixed in with other item types in the same folder, but you want to pick from all available armor items to stock the merchant's inventory.

The merchant's inventory table has the following columns:

  • Label - shows items' resource name, followed by the name shown to the player in parenthesis
  • Subgroup - [Undocumented]
  • Stack size - the number of copies of this item that the merchant has.
  • Infinite - a checkbox that, when checked, gives this merchant an endless supply of this item to sell.

Scaling

Merchants are scaled when first opened, but this can easily be reset by setting MERCHANT_IS_SCALED back to 0. Check out ScaleStoreItems in core_h.

Restricted items

Merchant restricted items.png

The restricted items Ellipsis.png button brings up this simple popup that sets which base item types the merchant will be willing to buy from the player. A list of all base item types is on the left and a list of selected types is on the right. A radio button sets whether the merchant refuses to buy selected item types, or exclusively buys selected item types.