Alright everyone, after receiving a few PM, asking me to explain how I manage to make a merchant sell specific stuff I decide to let you guys know about it. <img src="style_emoticons/<#EMO_DIR#>/cool.gif" style="vertical-align:middle" emoid="8)" border="0" alt="cool.gif" /> I didn't finish testing yet but the script I made for my merchant so far work fine.
First let's create a merchant:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--> // Arthur Wellington
makeref(ch,Characters[n]);
ch.old.name = "Arthur";
ch.old.lastname = "Wellington";
ch.name = LanguageConvertString(tmpLangFileID,"Arthur");
ch.lastname = LanguageConvertString(tmpLangFileID,"Wellington");
ch.id = "Arthur Wellington";
ch.model = "50M5";
ch.sex = "man";
ch.location = "Greenford_Town";
ch.location.group = "merchant";
ch.location.locator = "merchant1";
ch.Dialog.Filename = "00_Arthur_Wellington_Dialog.c";
ch.greeting = "Gr_Arthur_Wellington";
ch.quest.area = "Greenford";
ch.nation = ENGLAND;
ch.rank = 30;
ch.reputation = "70";
ch.experience = "900000";
ch.skill.Leadership = "6";
ch.skill.Fencing = "3";
ch.skill.Sailing = "4";
ch.skill.Accuracy = "9";
ch.skill.Cannons = "5";
ch.skill.Grappling = "5";
ch.skill.Repair = "6";
ch.skill.Defence = "8";
ch.skill.Commerce = "7";
ch.skill.Sneak = "8";
ch.perks.list.BasicDefense = true;
ch.perks.list.AdvancedDefense = true;
ch.perks.list.Toughness = true;
ch.perks.list.CriticalHit = true;
ch.perks.list.FastReload = true;
ch.perks.list.BasicBattleState = true;
ch.perks.list.AdvancedBattleState = true;
ch.perks.list.ShipSpeedUp = true;
ch.perks.list.ShipTurnRateUp = true;
ch.perks.list.StormProfessional = true;
ch.perks.list.SharedExperience = true;
ch.perks.list.BasicCommerce = true;
ch.perks.list.AdvancedCommerce = true;
ch.perks.list.Trustworthy = true;
ch.perks.list.BasicLandOwner = true;
TakenItems(ch, "blade23+3", 1);
TakenItems(ch, "pistol9+3", 1);
TakenItems(ch, "ammopouch", 1);
TakenItems(ch, "powderflask", 1);
TakenItems(ch, "GoldArmor", 1);
TakenItems(ch, "potion2", 5);
TakenItems(ch, "potion3", 5);
if (ENABLE_AMMOMOD)
{
TakenItems(ch, "gunpowder", 12);
TakenItems(ch, "pistolbullets", 12);
}
LAi_SetMerchantType(ch);
LAi_SetHP(ch, 330.0, 330.0);
ch.HPBonus = 220;
LAi_group_MoveCharacter(ch, "ENGLAND_CITIZENS");
n = n + 1;<!--c2--></div><!--ec2-->
The way you create your character is not really important, what's important is those 2 line but I will explain it more later:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->ch.Dialog.Filename = "00_Arthur_Wellington_Dialog.c";
LAi_SetMerchantType(ch);<!--c2--></div><!--ec2-->
To be able to set a merchant so it sell specific items you got to specify those items, so that they always show in the trade. To do so you got to open the quests_reaction.c file and open a case and in that case specify witch items need to be always there, like this:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->case "Arthur_Wellington_Shop":
PChar.AlwaysShowItems.SpyGlass3 = true;
PChar.AlwaysShowItems.AmmoPouch = true;
PChar.AlwaysShowItems.PowderFlask = true;
PChar.AlwaysShowItems.CommonArmor = true;
PChar.AlwaysShowItems.Blade14 = true;
PChar.AlwaysShowItems.Blade16 = true;
PChar.AlwaysShowItems.Blade17 = true;
PChar.AlwaysShowItems.Blade19 = true;
PChar.AlwaysShowItems.Blade20 = true;
PChar.AlwaysShowItems.Blade22 = true;
PChar.AlwaysShowItems.Blade25 = true;
PChar.AlwaysShowItems.Pistol1 = true;
PChar.AlwaysShowItems.Pistol2 = true;
PChar.AlwaysShowItems.Pistol3 = true;
PChar.AlwaysShowItems.Pistol4 = true;
PChar.AlwaysShowItems.Pistol5 = true;
PChar.AlwaysShowItems.Pistol6 = true;
PChar.AlwaysShowItems.Pistol7 = true;
PChar.AlwaysShowItems.Pistol8 = true;
PChar.AlwaysShowItems.Pistol9 = true;
PChar.AlwaysShowItems.PistolMtoon = true;
PChar.AlwaysShowItems.PistolMket = true;
break;<!--c2--></div><!--ec2-->
<-- This tell the game to always show that specific item. This will not add the item to the merchant, to do so you must specify in the Dialog.c file of the merchant witch item he will be selling like this:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->//#include "DIALOGS\Item Trader_dialog.h"
void ProcessDialogEvent()
{
ref NPChar, PChar, d;
PChar = GetMainCharacter();
aref Link, Diag;
string NPC_Meeting;
DeleteAttribute(&Dialog,"Links");
makeref(NPChar,CharacterRef);
makearef(Link, Dialog.Links);
makeref(d, Dialog);
makearef(Diag, NPChar.Dialog);
string iDay, iMonth;
iDay = environment.date.day;
iMonth = environment.date.month;
string lastspeak_date = iday + " " + iMonth;
if(!CheckAttribute(NPChar, "quest.item_date")) NPChar.quest.item_date = NPChar.quest.meeting;
switch(Dialog.CurrentNode)
{
// -----------------------------------Äèà ëîã ïåðâûé - ïåðâà ÿ âñòðå÷Ã
case "exit":
Diag.CurrentNode = Diag.TempNode;
NPChar.quest.meeting = NPC_Meeting;
DialogExit();
break;
case "Trading":
NPChar.ItemTrade.TradeType = IT_TYPE_SNEAKY;
if (!CheckAttribute(npchar, "quest.item_date") || NPChar.Quest.Item_Date != LastSpeak_Date)
{
GiveItemToTrader(NPChar);
TakeNItems(NPChar,"spyglass3", Rand(1)+1));
TakeNItems(NPChar,"ammopouch", Rand(1)+1));
TakeNItems(NPChar,"powderflask", Rand(1)+1));
TakeNItems(NPChar,"commonarmor", Rand(6)+1));
TakeNItems(NPChar,"gunpowder", Rand(12)+4));
TakeNItems(NPChar,"pistolbullets", Rand(12)+4));
TakeNItems(NPChar,"pistolgrapes", Rand(12)+4));
TakeNItems(NPChar,"blade14", Rand(4)+1);
TakeNItems(NPChar,"blade16", Rand(4)+1);
TakeNItems(NPChar,"blade17", Rand(4)+1);
TakeNItems(NPChar,"blade19", Rand(4)+1);
TakeNItems(NPChar,"blade20", Rand(4)+1);
TakeNItems(NPChar,"blade22", Rand(4)+1);
TakeNItems(NPChar,"blade25", Rand(4)+1);
TakeNItems(NPChar,"pistol1", Rand(4)+1);
TakeNItems(NPChar,"pistol2", Rand(4)+1);
TakeNItems(NPChar,"pistol3", Rand(4)+1);
TakeNItems(NPChar,"pistol4", Rand(4)+1);
TakeNItems(NPChar,"pistol5", Rand(4)+1);
TakeNItems(NPChar,"pistol6", Rand(4)+1);
TakeNItems(NPChar,"pistol7", Rand(4)+1);
TakeNItems(NPChar,"pistol8", Rand(4)+1);
TakeNItems(NPChar,"pistol9", Rand(4)+1);
TakeNItems(NPChar,"pistolmtoon", Rand(2)+1);
TakeNItems(NPChar,"pistolmket", Rand(2)+1);
NPChar.Quest.Item_Date = LastSpeak_Date;
}
Diag.CurrentNode = Diag.TempNode;
DialogExit();
LaunchItemsTrade(NPChar);
break;
case "First time":
Dialog.defAni = "dialog_stay2";
Dialog.defCam = "2";
Dialog.defLinkAni = "dialog_1";
Dialog.defLinkCam = "1";
Dialog.ani = "dialog_stay2";
Dialog.cam = "1";
d.Text = DLG_TEXT[0];
Link.l1 = DLG_TEXT[1];
Link.l1.go = "Trading";
Link.l2 = DLG_TEXT[2];
Link.l2.go = "exit";
break;
}
}<!--c2--></div><!--ec2-->
If you look at the <i>case "Trading":</i> it is where I specify witch item I want the merchant to sell. As you notice both files(quests_reaction.c and 00_Item_Trader_Dialog.c)got the same items except the gunpowder and bullets they are not specify as always show in the quests_reaction.c file, I'll explain it later why.
Now let me explain the:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->TakeNItems(NPChar,"pistol9", Rand(4)+1);<!--c2--></div><!--ec2-->
This give the merchant the pistol9 and tell the merchant to sell up to 4 of them +1. So the merchant will sell the amount of pistol9 from 0 to 4 and will add 1 more so 0-4+1.
Now that the items are set so they always show and that we specify the merchant witch item to sell we are ready to go right, <b>WRONG</b>. We got to use a command to tell the game to start the case in the quests_reaction.c so they actually always show those items that we give to the merchant.
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->AddDialogExitQuest("Arthur_Wellington_Shop");<!--c2--></div><!--ec2-->
To do so you got to use another character and put that command to him, I use Rys Bloom for my merchant since he his the one that introduce the merchant to you, so in Rys Bloom_dialog.c file I put the code in:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->case "Exit_Hire":
SetQuestHeader("Bloom");
AddQuestRecord("Bloom", "1");
AddDialogExitQuest("Arthur_Wellington_Shop");
NPChar.Quest.Help = "Told_About_Arthur_Wellington";
Diag.CurrentNode = "Node_1";
DialogExit();
break;<!--c2--></div><!--ec2-->
As soon you exit the dialog with Rys, the game will execute the case "Arthur_Wellington_Shop": in the quests_reaction.c file. Then when you go and see the merchant he will sell what you give him. I try to put that command to the merchant directly but for some reason it doesn't work, maybe because the merchant has to open the trading window avoiding to exit the dialog correctly, if you want to command to work correctly you must make sure that you exit the dialog correctly that's the reason i use Rys for the command.
Remember the:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->ch.Dialog.Filename = "00_Arthur_Wellington_Dialog.c";
LAi_SetMerchantType(ch);<!--c2--></div><!--ec2-->
Well the ch.Dialog.Filename is the file that the character will use for it's dialog, so once you create your character make sure the dialog.c file you create for your merchant match this one.
For the LAi_SetMerchantType(ch); it tell the merchant how to act, merchant never move so it won't move, when you get close to the character you will hear him yelling to the public, so they see what it sale. A common phrase will be: <i>Please come around, we got it all.</i>
If you want your merchant to sell only those items remove the <i>GiveItemToTrader(NPChar);</i> this command give random items to the merchant according to your rank(level), for me, I leave it there because I wanted my merchant to sell regular stuff, then later he sell regular stuff + the one I specify.
For the gunpowder and bullets, I don't see the reason to set them as always show since your main character most of the time always have them.
I think I cover pretty much everything, if you guys got question please feel free to ask.
P.S: Also I'm still testing and this is not the perfect script yet for now it work fine but I didn't extend the testing on it.
<b>Cheers,</b> <img src="style_emoticons/<#EMO_DIR#>/par-ty.gif" style="vertical-align:middle" emoid="

" border="0" alt="par-ty.gif" />