In a new mod, by default vendors are not enabled, you need to set up some stuff in the story scripting to get them to work. If you don't know how to add story scripting, I think there's a couple of larian tutorials up about it that you can watch.

Anyway, the first thing we want to do is make sure our vendor is global and then call this function:

CharacterSetCanTrade(CHARACTER_Player1, CHARACTER_OurVendor, 1);

If you have more than one character, you're going to have to call this for each player. Note that your player may not be called Player1 by default, you can change the name in the character menu (don't get confused, this is not the Display Name of the character and remember to generate definitions each time you change the name so that the compiler knows about your new name).

During dialog, the vendor will now have the trade icon available, however clicking it will do nothing.

What we need to do is add the function:

IF
RequestTrade(_char, _trader)
THEN
ActivateTrade(_char, _trader, 1, 1, 1);


This will open a trade window, showing the vendor's inventory (they probably don't have much at this point). The player also won't have any money.

If we add the line:

ItemTemplateAddToCharacter("e7dd9633-26d4-4782-9d76-d7c27054f445", CHARACTER_OurVendor, 2);
CharacterAddGold(CHARACTER_Player1, 10000);

To our story file and compile, then the vendor will have some two pairs of cloth boots to sell us and we should have enough money to buy them. However, when we attempt to buy the boots, nothing happens.

We need to add one last function:

IF
HappyWithDeal(_Player,_Npc,_ValuePlayer,_ValueNpc)
AND
_ValuePlayer >= _ValueNpc
THEN
ExecuteDeal(_Player,1,0);

Now, when we make an offer, the vendor will sell to us if we've given gold equal or more in value to the goods we want.

At this point, very basic trading works. You can look in trade.txt for ways to expand it by generating random goods, affecting attitude, and checking for stolen goods.*

Oh. You probably just wanted to add a vendor to the main campaign. Well, all you need to do is make a global character, assign them some dialog, and add them in trade.txt. Then rebuild everything.

*Only being able to sell goods to Black Market Traders didn't make it into the shipped game, but there's remnants of the code lying around.

Last edited by roguelike; 21/07/14 09:58 AM.