Modding Help Adding a new currency type to player inventory

Discussion in 'Starbound Modding' started by Aegonian, Dec 16, 2016.

  1. Aegonian

    Aegonian Weight of the Sky

    In the latest Starbound update, support for custom currencies was added - one of the features of the update I was looking forward to the most, as it could open up a lot of new options for my Elithian Races Mod. I'm working on updating that mod to work with the new update now, and adding those new currencies was one of the first things I started working on, but I've run into an issue which I have no idea how to resolve - I want the new currency to show in the player's inventory.

    I have already made changes to the playerinventory.config in the /interface/windowconfig folder: I rearranged the visuals for the new Essence currency to be positioned further to the left, creating some space for my new currency. I also added a new icon for my new currency, and tried to add the currency count, but this is where I got stuck.

    Let's go through all the changes I made so far:

    First, I created a new .currency item, called avikanmerittoken.currency, with the following config:
    Code:
    {
      "itemName" : "avikanmerittoken",
      "rarity" : "Rare",
      "inventoryIcon" : "avikanmerittoken.png",
      "description" : "Tokens of merit, to show your worth amongst the Avikan.",
      "shortdescription" : "Token of Merit",
      "currency" : "avikanmerittoken",
      "value" : 1,
      "pickupSoundsSmall" : [ "/sfx/objects/coinstack_small1.ogg", "/sfx/objects/coinstack_small2.ogg", "/sfx/objects/coinstack_small3.ogg" ],
      "pickupSoundsMedium" : [ "/sfx/objects/coinstack_medium1.ogg", "/sfx/objects/coinstack_medium2.ogg" ],
      "pickupSoundsLarge" : [ "/sfx/objects/coinstack_large.ogg" ],
      "smallStackLimit" : 999,
      "mediumStackLimit" : 4999,
      "maxStack" : 16777216
    }
    I also created this patch for the new currencies.config:
    Code:
    [
      { "op" : "add",
        "path" : "/avikanmerittoken",
        "value" : {
          "representativeItem" : "avikanmerittoken",
          "playerMax" : 999999
        }
      }
    ]
    Everything up to this point seems to be working alright, because the currency item can be spawned in-game, and can be used in crafting recipes as well, so no issues here. The player correctly acquires the new currency, and can use it when needed.

    My next step was to add the new currency to the player inventory screen, so I created the following patch for the playerinventory.config:
    Code:
    [
      { "op" : "add",
        "path" : "/paneLayout/imgAvikanmerittokenIcon",
        "value" : {
          "type" : "image",
          "position" : [110, 11],
          "centered" : false,
          "file" : "/interface/inventory/merittokenicon.png"
        }
      },
      { "op" : "add",
        "path" : "/paneLayout/lblAvikanmerittoken",
        "value" : {
          "type" : "label",
          "position" : [122, 11],
          "value" : "0"
        }
      },
      { "op" : "replace",
        "path" : "/paneLayout/imgEssenceIcon/position",
        "value" : [60, 11]
      },
      { "op" : "replace",
        "path" : "/paneLayout/lblEssence/position",
        "value" : [75, 11]
      }
    ]
    What this does is move the Essence visuals to the left, and add new visuals for the custom currency on the right. The result looks like this:
    [​IMG]

    All seems well and good so far, but there's one glaring issue: that number next to the new icon doesn't actually update when the player receives new avikanmerittoken items...

    What I can't seem to figure out is how to actually link the "lblAvikanmerittoken" label to the amount of currency held by the player. I had hoped that by using the same naming conventions as the vanilla currencies, the game would automatically link the currency item with that label, but that doesn't seem to be the case.


    Am I missing a configuration file somewhere? Or is there a LUA script somewhere that I need to edit in order to link the label to the player's currency count? I've looked through a lot of config files and scripts that I thought might be related to this, but I cant seem to find anything helpful.



    TLDR:
    I added a new currency to the game called avikanmerittoken, and created all the necessary config files. I then tried to add my new currency to the player's inventory screen, but I can't seem to figure out how to actually display how much of this currency the player is currently carrying.
     
  2. bk3k

    bk3k Oxygen Tank

    There has to be a pane script that is reading playerinventory.config somewhere. I'll try to look it up. I'm going to guess this script is supposed to fill in the value, but isn't being told to look for your currency type so defaults to zero.
     
  3. Aegonian

    Aegonian Weight of the Sky

    Tried looking for any sort of LUA script that could influence the player inventory, but I've yet to find anything. By searching for 'lua' in the folder where I unpacked the latest assets, I managed to find what seemed to be every LUA script in the assets, but nothing seems to apply to the player inventory.

    By looking at the LUA script for the terraformer interface, I did manage to find what the code for updating that label should be. Here's the two lines from that script that are used to update the currency label in that interface:
    Code:
    local playerEssence = player.currency("essence")
    
    widget.setText("lblEssenceCount", string.format("%s%s / %s", essenceTextDirective, playerEssence, essenceCost > 0 and essenceCost or "--"))
    With those two lines, you can get the player's current currency count, and then set the text field for the specified label. Problem is, there doesn't seem to be any LUA script in the assets that affects the player inventory, so there's no way to update the label I created. It all seems to be handled by the game's source code, which is unavailable to us...
     
  4. bk3k

    bk3k Oxygen Tank

    I didn't find anything myself, maybe that's C++ side...
    That can be frustrating, especially when what is on that end and what's on this end seems almost arbitrary. So it may be that you can use that as a currency, but not really display it meaningfully. Sort of like... well you have it.
     
  5. Tremerion

    Tremerion Existential Complex

    Thank you for this .patch configs. Been messing with it. I do not know if you noticed it before, but when you:
    { "op" : "add",
    "path" : "/paneLayout/lblAvikanmerittoken",
    "value" : {
    "type" : "label",
    "position" : [122, 11],
    "value" : "0" -> change it to any number, game shows this numer, but still game is not displaying real numer.
    }
    },
     
  6. Aegonian

    Aegonian Weight of the Sky

    That's the reason I created this thread - I can't seem to find a way to make the game update that value... I've created other custom or modified interfaces with custom values that needed to be updated in-game, but I always had a script telling the game which label to replace with which value. Unfortunately, there is no such script for the player inventory, as it seems that the player inventory is handled in C++, not LUA. Unless Chucklefish adds a way for us to use custom scripts with the player inventory, I think that displaying custom currencies will be impossible (which, IMO, makes the new custom currency support largely useless).

    I've tried adding a script to the player inventory by using this patch data for the playerinventory.config, but unfortunately, the game doesn't seem to run any scripts you add this way, so I think I'm giving up on this venture for now.
    Code:
    { "op" : "add",
        "path" : "/scripts",
        "value" : ["/interface/inventory/thea-custominventory.lua"]
      },
      { "op" : "add",
        "path" : "/scriptDelta",
        "value" : 1
      }
     
  7. projectmayhem

    projectmayhem Spaceman Spiff

    Let me know if you manage to figure this out, I was looking up tutorial for custom currency and ended up here. I wanted to add Republic Credits to my Star Wars Mod.
     
  8. projectmayhem

    projectmayhem Spaceman Spiff

    Have you tried making any kind of object, like a "banker" that you can visit using merchant scripts or something, where instead of the pixel currency showing, it shows your custom currency?

    Or maybe a modified terraformer, since local playerEssence = player.currency("essence") looks promising.

    Just tossing out ideas.
     
  9. Aegonian

    Aegonian Weight of the Sky

    I'm certain I could build such a custom interface which displays the amount of custom currency you carry, but the problem remains that if it can't be shown in the player inventory, you won't know how much of this custom currency you have until you visit the 'banker' object. The functionality for custom currency is all there, and creating scripted interfaces to display the currency is fully possible, but so long as players have to visit a specific object just to see how much of the currency they have, the system is largely useless...
     
  10. Jilly Bob the Third

    Jilly Bob the Third Star Wrangler

    Why not look at the assets that add pixels or ancient essence?
     
  11. Cyel

    Cyel Scruffy Nerf-Herder

    That's what they based their stuff on, the problem here is that there's apparently no way to make a custom currency's value self-update in the inventory, as they think they already did everything that's done in the assets for pixels / ancient essences. As they said, it's probably managed by the C++ engine, which is out of our modding reach
     
    Aegonian likes this.
  12. bk3k

    bk3k Oxygen Tank

    I'll confirm for you that the inventory screen cannot currently be scripted. I tried this for my inventory mod, but had to scale back my ambitions. That also is what is going to keep your new currency from showing up.
     
  13. RexTheFox

    RexTheFox Phantasmal Quasar

    not sure if this will help but i found this

    PlayerEntity_27_28.lua
    Code:
    function update(data)
      data.inventory.currencies = {
        money = data.inventory.money
      }
    
      data.inventory.money = nil
    
      return data
    end
    
    it was found in
    <unpacked assets folder>\unpacked\versioning
     
  14. Cyel

    Cyel Scruffy Nerf-Herder

    The versionning scripts are used to update files between each new versions; that one was moving the inventory.money to inventory.currencies.money
     

Share This Page