Modding Help Adjusting Merchant Prices Based on Player Stat

Discussion in 'Starbound Modding' started by Zaakari, Jun 27, 2019.

  1. Zaakari

    Zaakari Pangalactic Porcupine

    Greetings,

    I've been trying to alter the merchants buy and sell prices based off of a custom player stat, but it seems I am in over my head, and was wondering if someone could help me out (or point me in the right direction).

    I have successfully added (via a patch) a stat named "charm" to the player.config using the following:
    Code:
    [
      { "op": "add",
        "path": "/statusControllerSettings/stats/charm",
        "value": {"baseValue": 0.5}
      }
    ]
    Furthermore, I found that I could alter the buy/sell factor of regular (wandering?) merchants by editing the file "scripts/actions/merchant.lua". However, I don't know how to factor in the player's charm stat, as when I use something like:
    Code:
    storage.sellFactor = status.stat("charm")
    the selling price results in zero, as--I suppose--it tries to use the npc's charm stat, which is non-existent, and defaults to zero.
    Is it possible to get the interacting player's stats in the merchant.lua file? Or is there some other file I should be editing?
     
  2. projectmayhem

    projectmayhem Spaceman Spiff

    Have you tested your theory on the 0 by giving the merchant a charm stat? just curious
     
  3. Zaakari

    Zaakari Pangalactic Porcupine

    Just tested it now by adding the code in my first post to the file /npcs/base.npctype.patch, and that affected the price. So theory proven, I guess.
    While I was trying to figure out how to do that, I stumbled across a few interesting files that might be of use. But I'm still not sure how to get the player's stats.

    When a file uses various LUA table functions (like player.currency or status.stat) how does the script know which object is being referenced (like which player or which statusController)? Does that get passed to the script at some point?
     
  4. projectmayhem

    projectmayhem Spaceman Spiff

    Not sure, I was looking into some lua files myself to see if i can find something that may help point you in the right direction

    did you try anything similar to
    storage.sellFactor = player.status.stat("charm")
     
    Last edited: Jun 28, 2019
  5. Zaakari

    Zaakari Pangalactic Porcupine

    Hmm, no, that generates an error saying:
    So that merchant file must not know about the player table.
    I found another script "/interface/scripted/goodstrader/goodstradergui.lua" which seems to be aware of the player table. But I don't know what that file applies to (who is / what is the goodstrader?).

    Edit: the "merchant.lua" file does know about the world table, so if there were some way to get the player from that...
     
    Last edited: Jun 28, 2019
  6. projectmayhem

    projectmayhem Spaceman Spiff

    \npcs\space\electronicgoodstrader.npctype
    \npcs\space\foodgoodstrader.npctype

    There are two more in that file. Maybe make your merchant a goods trader? Or patch all merchants to use the goodstrader lua?
     
  7. projectmayhem

    projectmayhem Spaceman Spiff

    wonder if patching merchants to use require "/scripts/util.lua" would work.
     
  8. Zaakari

    Zaakari Pangalactic Porcupine

    Well, after doing some (on and off) searching and testing, the best I could find was the file "/interface/scripted/cropshipper/cropshippergui.lua".
    In the "init" function in that file, I was able to change this line:
    Code:
    self.itemValues[itemName] = math.ceil(itemConfig.config.price * sellFactor)
    to this:
    Code:
    self.itemValues[itemName] = math.ceil(itemConfig.config.price * status.stat("charm"))
    which actually used the player's charm stat that I had given him.

    It's not the greatest discovery, as it only affects the shipping container (purchased at the Terramart). But at least it's something.
    It seems to me the code that handles the purchasing/selling of all the Ark's shops must either be in a very obscure place, or is hard-coded somewhere and not accessible in the assets. Their buy/sell factors could be changed (through their object/config files), but I see no way to base those changes upon any of the player's stats.

    P.S.
    As for the "/scripts/util.lua" file, the "merchant.lua" file includes it by default. So no change there, unfortunately.
    Also, I think the "/interface/scripted/goodstrader/goodstradergui.lua" file has to do with some merchant that exists on certain space stations you can travel to.
     

Share This Page