Fallout and Fallout 2 Barter Formula?

QuantumApprentice

Look, Ma! Two Heads!
Here's another zany question probably nobody has bothered to ask...does anybody know what the actual formula or pseudo-code for how npc's price their stuff is?

I've taken the time to create a data set of several of the npc shopkeepers for both Fallout and Fallout 2, but the trend lines appear logarithmic or polynomial when looking for best fit with excel. Now I don't trust excel to give me great results with it's limited equation solving ability, so I figured I'd ask here.

It looks like the original Fallout may have a much steeper curve, but it dips into profitability at pretty low skill levels, while fallout 2 requires absurdly high skill levels even with discount bonuses.
Also, I'll happily post my data if nobody has a direct answer and somebody wants to help derive it.

There also appear to be other variables besides barter and discounts going into the formula, but (counter to Per Jorner's walkthrough) charisma does not seem to have any direct affect other than the effect it has on your barter skill.
 
Last edited:
FO1:
Code:
Master_Trader = 100;
if (player_has_master_trader) Master_Trader = 125;

barter_mod = script_modifier + reaction_modifier; // reaction_modifier is 50/0/-25 for good/neutral/bad.
barter_diff = barter_mod + player_barter_skill - trader_barter_skill + Master_Trader;

if (barter_diff < 10) barter_diff = 10;
if (barter_diff > 300) barter_diff = 300;

total_price = caps_total + (item_total_cost_without_caps * 100) / barter_diff;
example:
Ian has Barter 30%. The player has Barter 200% and Master Trader perk.
The barter_mod is 0.
Now buying a 10mm SMG (1000 caps) from him will be:
barter_diff = 0 + 200 - 30 + 125 = 295
price_on_table = (1000 * 100) / 295 = 338


FO2:
Code:
Master_Trader = 0.0;
if (player_has_master_trader) Master_Trader = 25.0;

barter_mod = script_modifier + reaction_modifier; // reaction_modifier is -15/0/25 for good/neutral/bad.
barter_percent = (barter_mod + 100.0 - Master_Trader) * 0.01;

if (barter_percent < 0.0) barter_percent = 0.0099999998;

barter_ratio = [(trader_barter_skill + 160.0) / (highest_barter_skill_in_party + 160.0)] * 2.0;

total_price = caps_total + item_total_cost_without_caps * barter_ratio * barter_percent;
example:
Eldridge has Barter 115%. The player has Barter 200% and Master Trader perk.
If the player becomes a Made Man for any family, the barter_mod will be -20.
Now buying a 10mm SMG (1000 caps) from him will be:
barter_percent = (-20 + 100 - 25) * 0.01 = 0.55
barter_ratio = [(115 + 160) / (200 + 160)] * 2 = 1.52778
price_on_table = 1000 * 1.52778 * 0.55 = 840
 
Last edited:
Heck yeah!
NovaRain with the answer AND the pseudo-code!
Where do you get the voluminous amount of information you always have?
Thank you!

A couple of odd discrepancies I noticed when trying to test these formulas out:

Ian's barter skill for Fallout 1 is listed at 20%, not 30% according to Cubik's "FO1/2 Critter Proto Editor" (v1.0.1.0), however your formula seems to work for a couple of different values in game so it's possible the critter proto editor is incorrect, but I'm not sure where to verify Ian's barter other than with this tool. Can I trust other barter values in it?

According to the wiki (and the in-game description), in both games you're supposed to get a 25% discount with the Master Trader perk, but for Fallout 1 your formula treats the perk as +25 invisible Barter skill points (which is not the same as 25% discount). Your formula still seems to give correct values, suggesting that the descriptions listed are not correct for the original Fallout.

Any thoughts? Have you run into this stuff before? Is it worth a wiki edit?

And finally, I can't get Eldridge's prices to line up with your formula for Fallout 2.
With the Made Man and Master Trader perks and 200% Barter skill I can only get the price down to 1145.
Without Master Trader the price is 1527, which makes the 25% discount seem correct this time at least, but this suggests the Made Man perk isn't being added in. That being said, I can't seem to find the Made Man perk in F2SE (the Fallout 2 Save-game Editor), so who knows if I really have it or not. My karma page lists it, and I get the option to ask for it in dialogue, but it doesn't seem to have an effect.

After checking Per Jorner's walk-through, he says:
"For each boss there is a chain of quests, upon the completion of which you become a Made Man of that family. This means you get a popularity boost among the citizenry, free sex at the Cat's Paw, special services at the New Reno Arms (but seemingly no discount on Eldridge's normal stock, nor Renesco's)".

So it appears this perk is faulty for the main vendors in New Reno (at least in current vanilla version) :(
(Also, giving an SMG to Eldridge's "special stock" and then checking the price by purchasing it again does not seem to add any sort of discount either) :( :(
Actually, it looks like this is the main reason I can't get prices to line up, as when I remove that from the math, the prices seem to match again. I'll run a few more tests and see how it goes, thanks for helping me out! XD :)

I'm testing this with the Steam version of Fallout and Fallout 2, no mods installed.

Other questions:
What is the "caps_total" variable in the formula? (You don't seem to use this in the examples you gave)

Multiple "barter_mod_from_script" variables appear to be calculated sequentially instead of cumulatively (ie Maida Buckner gives you a 20% discount if you buy one round of drinks, but a second round of drinks only gives you an extra 12% cumulative discount from the original price, but it could be a 15% discount applied to the final price after the initial 20% discount). How does the formula account for this?
 
Where do you get the voluminous amount of information you always have?
From the engine dump databases that I've already told you in an old post.

Ian's barter skill for Fallout 1 is listed at 20%, not 30% according to Cubik's "FO1/2 Critter Proto Editor" (v1.0.1.0), however your formula seems to work for a couple of different values in game so it's possible the critter proto editor is incorrect, but I'm not sure where to verify Ian's barter other than with this tool. Can I trust other barter values in it?
Download Cubik's latest critter proto editor (v1.4.6.11). Or extract Ian's proto from master.dat from FO1 and check the proto in some hex editor.

And finally, I can't get Eldridge's prices to line up with your formula for Fallout 2.
Made Man status is not a perk but a reputation from setting global variables, and his discount from Made Man is in killap's UP/RP (was bugged in vanilla).

Other questions:
What is the "caps_total" variable in the formula? (You don't seem to use this in the examples you gave)
The amount of "money/caps" item on trader's table, the value of money itself shouldn't be effected by barter skill right? $1 is $1.
 
From the engine dump databases that I've already told you in an old post.

Oh man, I forgot about that. Still wish I could open those and read them, I'd seriously abuse google translate with it :P

Download Cubik's latest critter proto editor (v1.4.6.11). Or extract Ian's proto from master.dat from FO1 and check the proto in some hex editor.

Woohoo! Thank you sir! This one is up to date (Ian's barter is 30) and shows more info besides XD
Sadly, my current dat explorer only works for FO2, so I'd have to do some searching for the FO1 dat explorer, but I'm pretty sure 30 is the correct skill level.

Made Man status is not a perk but a reputation from setting global variables, and his discount from Made Man is in killap's UP/RP (was bugged in vanilla).

Yeah, I found that out the hard way :P

The amount of "money/caps" item on trader's table, the value of money itself shouldn't be effected by barter skill right? $1 is $1.

Was this used as an exchange rate for things like Redding's mine scrip? I don't recall if Fallout had more than one currency though.
 
barter_ratio = (115 + 160) / (200 + 160) * 2 = 1.52778

I get what you're saying here, but for order of operations shouldn't it read:
2 * (115 + 160)/(200 + 160)
or
[(115 + 160)/(200 + 160)] * 2
?

Similarly:

barter_ratio = (trader_barter_skill + 160.0) / (highest_barter_skill_in_party + 160.0) * 2.0;

is it actually:
barter_ratio = 2 * (trader_barter_skill + 160.0) / (highest_barter_skill_in_party + 160.0)
or
barter_ratio = ((trader_barter_skill + 160.0) / (highest_barter_skill_in_party + 160.0)) * 2
?
 
Last edited:
Sorry for bringing it up, but thank you for understanding :)

Ok, I got both formulas to work perfectly for several characters in each game...but...

I can't get Maida Buckner's prices to match.
All the other characters I've tested so far I was able to apply a simple barter modifier of 25 or 50 or something similar to get everything to line up, but her prices have some weird non-repeating ratio applied to them, so I think I'm missing something in her barter modifier.

Is there some way to find the barter modifiers for npc's? At least for shopkeepers?
 
Is there some way to find the barter modifiers for npc's? At least for shopkeepers?
You need to check their scripts and local variable in saved games, because barter_mod is also effected by reaction value (the first local variable, not all traders set it, for example Eldridge doesn't).
Maida Buckner has Barter 55% and no barter modifier in her script. My character has Barter 170% and Master Trader perk, so buying a crowbar ($65) from her with good reaction costs:
barter_mod = 0 + (-15, from good reaction) = -15
barter_percent = (-15 + 100.0 - 25.0) * 0.01 = 0.6
barter_ratio = [(55 + 160.0) / (170 + 160.0)] * 2.0 = 1.30303
crowbar cost = 65 * 1.30303 * 0.6 = 50
 
because barter_mod is also effected by reaction value (the first local variable, not all traders set it, for example Eldridge doesn't).

It sounds like you're saying the reaction variable has a significant effect?
Does this mean each type of reaction (positive, neutral, negative as described in the wiki) gets a set bonus or penalty? If it works that way is it always 15 points? If not, what is this set bonus/penalty?

These are the two links I can find that have info about the Reaction system, but they're inconsistent and don't agree with each other:
https://fallout.fandom.com/wiki/Reaction
https://fallout.gamepedia.com/Reaction

Maida Buckner has Barter 55%

This is really frustrating, neither wiki list's her Barter skill level, the critter tables listed here: give her a 0 in Barter, the newer "FO1/2 Critter Proto Editor" you pointed me to (v.1.4.6.11) lists her barter as 16, and the only other Proto editor I managed to get working (Proto Manager v1.03 by Mr.Stalin) also lists her as having 16 barter. I will note that the proto manager does have a "Critters Flags" section where she is flagged for "Barter", but I have no idea what this means.

The crazy thing is when you used 55 for her barter skill it only takes a barter_percent of 1.25 to make her numbers line up. Even crazier, when testing Master Trader on her, it gives the same discount as if you only buy one round of drinks.
So, from what you describe, it looks like her first modifier is -25 (from bad reaction to neutral?), and her second is another -15 (from neutral to good reaction?)

Either way, how can I verify what her actual barter is? Does the "Barter" flag have something to do with it?
 
Last edited:
Does this mean each type of reaction (positive, neutral, negative as described in the wiki) gets a set bonus or penalty? If it works that way is it always 15 points? If not, what is this set bonus/penalty?
I've already updated my fist post above with reaction modifiers.

Either way, how can I verify what her actual barter is? Does the "Barter" flag have something to do with it?
Because in the game she actually uses "Bad Merchant" as her template. Sometimes you need to use Fallout mapper to check critters on a map.
 
I've already updated my fist post above with reaction modifiers.

Thanks! Oh wait, Fallout has reaction modifiers too? Well that explains Mrs. Stapleton's overpriced books.

Because in the game she actually uses "Bad Merchant" as her template. Sometimes you need to use Fallout mapper to check critters on a map.

How do you get the mapper to list her template? The only thing I can get it to list is her script file (kcmaida.int). Her script file also has a "maida_barter" procedure, but I'm unclear how to read the rest of it.

If you have the time, would you be willing to explain how to get the template to show up? Or point to a guide if one exists?
 
Ok, I found the "Bad Merchant" template in the mapper, though I have no idea how you're supposed to know this is a template.

Maida Buckner - Bad Merchant.png


So if Maida uses a template that replaces her own barter skills with whatever is in the template, how do we find out what the template skills are?
 
You can check it in the critter proto editor.

Well that just makes sense :P Thank you! :)

But I noticed there's a number in this box that looks like it might relate to the proto id number.

FO2 Mapper - proto id.png


Is that what it's supposed to be? Only it's offset by 1 since the editor starts the id's at 0, while the actual proto files start at 1? Or is it just the list order?
(I ask because 00000056.pro is listed as a Male Bad Merchant with 50 barter, but 00000057.pro is the one you highlighted which has the correct values.)
 
Last edited:
Oh, and one last question:

Does the game always recognize the Template values over the Critter values?

For instance, since Big Sally Dunton has Master Trader as her template, does that mean the game will always use 120 Barter for Sally's skill level instead of whatever her own proto file shows? Are there exceptions to this?:

sally dunton.png
 
Sally doesn't have her own proto. The case for Maida Buckner is the devs set up an unique proto (00000098.pro) for her in the game files but didn't really use it, it's a "bad merchant" critter (00000057.pro) being placed on the map with Maida Buckner's script attached.
 
Ah ok, thanks for explaining. Are there a lot of exceptions like this?

I'm specifically trying to find out if I can reliably determine what a critter's barter skill is by checking either their named proto or their template proto (give or take the wiki).
 
Last edited:
You need to check their scripts and local variable in saved games, because barter_mod is also effected by reaction value (the first local variable, not all traders set it, for example Eldridge doesn't).
Hey NovaRain, I would like to implement the barter formula into the Falltergeist engine based on your research. I already figured out the script modifier is set through gdialog_mod_barter(modifier), but where does the Master Trader perk come from? Are perk modifiers also set through some SSL functions or are they directly handled by the engine?
 
but where does the Master Trader perk come from? Are perk modifiers also set through some SSL functions or are they directly handled by the engine?
It's handled by the engine. The if (player_has_master_trader) is actually if (source == obj_dude && perk_level_(obj_dude, PERK_master_trader))
 
Back
Top