Modding Discussion Is their any lua scripts for crafting?

Discussion in 'Starbound Modding' started by dantevfenris, Feb 16, 2017.

  1. dantevfenris

    dantevfenris Space Hobo

    First sorry for so many posts. I'm excited about all this stuff and getting things underway.

    So I recently played with the commonpistol.activeitem. Their I found it was attached to three scripts. One for the gun, the shot itself and how the gun is randomly generated. While a lot of information to behold for a beginner I could kind of read what was happening and make the changes I needed.

    However, for my next step I may need to change the fundamentals of crafting for my new crafting station. But I cant seem to find not even one .lua file that is associated with crafting. A file I'd need so I don't need to start from scratch and have some guidance. I'm looking for the script that would for example take out the copper ore and give you a copper bar in return as well as the file that would call that script. As from the looks of it seems JSON has something to do with calling scripts.

    JSON can't do anything by itself it's just a way to organize information. So why is their only seem to be JSON associated with crafting? Is this something hardcoded that I can not view, or am I missing it somewhere?
     
  2. IHart

    IHart Scruffy Nerf-Herder

    Likely an example of a hard-coded function, if you search yielded nothing.
     
  3. The | Suit

    The | Suit Agent S. Forum Moderator

    Some parts are hardcoded. So the JSON directly feeds into the engine.
     
  4. bk3k

    bk3k Oxygen Tank

    To what they're saying, mostly yes but with some clarification. This is from my (presently growing) understanding anyhow. Much of this is hardcoded and found in .config files within
    /interface/windowconfig/
    with the PNG files being referenced mostly within
    /interface/crafting/
    But there are also several examples scripted interfaces that you can find in
    /interface/scripted/
    Now much of that is in fact still hardcoded, but some of it isn't. Where you see something like
    Code:
    "callback" : "techSelected",
    you can find in the associated script something like this
    Code:
    function techSelected()
      local listItem = widget.getListSelected(self.techList)
      if listItem then
        local techName = widget.getData(string.format("%s.%s", self.techList, listItem))
        setSelectedTech(techName)
      end
    end
    There are some container mods that are good examples of this out there. Enhanced Storage, Better Containers etc. For example their sort buttons have to be handled via script(trying to use the function present in inventory doesn't work... hard coded).

    You can add scripted callbacks to the interfaces which don't already have them, and hook those that do. My tech mod hooks
    /interface/scripted/techupgrade/techupgradegui.config
    But I'll admit I got the base idea from another mod. A creative person could use patch test conditions to see if a vanilla config file has been scripted(and by what script) - and hook if so - for example if you wanted your container tweaks to (optionally) work with Enhanced Storage etc.

    In your case though I'd just clone(rather than patch) a vanilla crafting station interface as a base, and modify as desired. It would be better to simply have your own.
    You might also look at
    /interface/objectcrafting/
    because some of that uses an itemgrid.

    I see no reason you can't make your own button that runs a function which spawns an item(after deciding the parameters.
    player.hasCountOfItem()
    can be used to decide which buttons become available or are greyed out.

    player.consumeItem()
    take the ingredients
    player.giveItem()
    Give them the output

    Now if you want to see an example of creating a dynamic button based off conditions, check out Tabula Rasa. The newest version is slightly outdated(a couple image locations moved) but still functions.
     
  5. dantevfenris

    dantevfenris Space Hobo

    Which JSON file would I put this custom button in? interface/windowconfig/ files or in /interface/objectcrafting/. Cause I have a clone of a crafting station in their. Can I add a script to one of those?

    Yea ive seen a script that detects the 20 cores for the quest progression so I've seen that part sort of done.

    Also if the json is
    Code:
    "input" : [
      { "item" : "commonpistol", "count" : 2 }
      ],
      "output" : {
      "item" : "commonpistollight",
      "count" : 1
      },
      "duration" : 0.15,
      "groups" : [ "modificationStation", "bars", "all" ],
    
    how do i than consume the item. player.consumeItem("input")

    but I want to get the 1st value from the array so I am unsure if its something like this

    player.consumeItem("input.item")

    or

    player.consumeItem("input[0]")

    or something else entirley

    also if the script is supposed to be on the interface section than how does it connect with this recipe section. It seems like Im trying to do something advance from the beginning but thats how you learn. I'll probably have to rewrite everything. Like not include these recipes and include my own system?
     

Share This Page