Modding Help Lua Scripts !!

Discussion in 'Starbound Modding' started by HerrJunky, Mar 11, 2017.

  1. HerrJunky

    HerrJunky Void-Bound Voyager

    Hi guys !
    I've been around quite a while now searching for some Lua tutorials, but i wasn't very lucky ...
    I need some Help by lua talented people :

    Question 1:
    All scripts are , at least in some way, connected to an object(items,weapons etc.) ,right ?
    For example the physic script , is it connected to every object that should have a realistic behavior?
    Or is it a script that is always running ?
    Question 2:
    How are lua-scripts called in Starbound ? Because you can of course include a custom script with your custom object , but how is this script actually called , is there a script a haven't noticed yet which is doing all that or is it done by the .exe ?

    Question 3: if the physic-script is always running , how is it called, i there a hardcoded list inside the .exe , or what ?

    Question 4:
    The title screen for example ... How is it managed , by the .exe or by a script ? And how is the protectorate mission .lua file called ?

    Thats a bunch of questions!:nurushock:
    Hopefully there is someone out there who could give me an answer !

    HerrJunky

    (Sorry for bad grammar and stuff sometimes, but its (almost)
    11pm and im not even a native :nuruwink:)
     
  2. MetaFace

    MetaFace Guest

    Question 1: yes every weapon uses lua, armor doesn't, and some objects use lua.
    Question 2: scripts are called in a json file using the tag "scripts" : [script goes here]
    Anything that isn't a lua script is json.
    Question 3: physics is called constantly on the player, most objects don't have physics enabled, the physics script is usually called by function name in another lua that is hooked to an item.
    Question 4: I personally don't know.
     
  3. HerrJunky

    HerrJunky Void-Bound Voyager

    Okay , so you can only call a script from within an weapon, questtemplate etc. not from somewhere else , right ?
     
  4. bk3k

    bk3k Oxygen Tank

    I'll tell you something important up front. Many things(sometimes arbitrarily) are hard coded. Starbound has a compiled C++ core engine. LUA is the scripted side. For the title menu, that's a .config(JSON) file the engine uses. You can edit it of course. Some interfaces though(not all) are scripted, meaning you can do a lot more. Some non-scripted interfaces can be scripted(for example some mods script containers).

    The protectorate's scripts are defined in the .questtemplate(JSON) files.

    There are also activeItems too. Those are scripted. All weapons are activeItems, but not all activeitems are weapons. Not all items are activeItems either.

    Generally you aren't "calling" a script ever. They're always present with the entities that are scripted. An exception would be within a script
    require("/scripts/someScripts.lua")
    etc that could be called conditionally if you really wanted.

    And you'll want to look good at the vanilla stuff for a while. As I say the scripts are always running, but there are some notes.
    1. init() runs when the associated entity is spawned/loaded/etc.
    2. update() runs constantly, the frequency of which can be set by the entity's JSON.
    3. There are some calls that will be made by the engine in response to events. For example onInteraction() would be called when you attempt to interact with something(if it even can be interacted with).
    4. There is a messaging system, but don't get into that until you have everything else down good. Don't think of this as "calling a script" but calling the entity. Or rather, you're calling that entity's individual script environment.
     
    Last edited: Mar 11, 2017
  5. HerrJunky

    HerrJunky Void-Bound Voyager

    Okay so that means the gameplay-wise best way of implementing a custom script is by just linking it with a quest ?
     
  6. Cyel

    Cyel Scruffy Nerf-Herder

    ^it depends of what your custom script is supposed to do; quest scripts have access to scripts weapons do not (for example, the player's gender or specie) and vis-versa (for example, the player's aim), object scripts have access to functions quests scripts do not (for example, managing "server-side" stuff), etc. Most things actually use Lua scripts to run: weapons and more generally items, monsters, custom interfaces, quests, objects, techs, vehicles, and most of the content is stored as Json files that you can easily patch. The main things that are hardcoded are vanilla interfaces (you can only edit the size and appearance of eg. the songbook, it's behavior is hardcoded and there's no way to change it), some specific parameters in every items (for example the "soundEffectRangeMultiplier" on objects emitting sounds will be interpretted by the engine directly), and a few things like that.

    Using a quest script to do stuff other scripts can't a "classical hack" to circumvent some of the limitations Lua scriptting have.

    Most likely you'll never encounter things you can't change unless you're going crazy in your ideas (Last time I got that was when I was trying to modify a scantool (they don't take scripts), then to make a fake scan tool (the engine manages the overlay on scannable objects)).

    The "physic script" is a script that is constantly running on the player, and is different from the one npcs and monsters have; you can look at them in /stats/<type>_primary. That script is "made running on the player" by it's entry in the "primaryScriptSources" array of the /player.config json file. That script also handles damages and resources.
    I believe dropped item and liquid's gravities are managed by the engine tho

    The title screen is an interface like any other; it's files are located in /interface/title, and it's configuration in /interface/windowconfig/title.config.
     
    HerrJunky likes this.
  7. bk3k

    bk3k Oxygen Tank

    Yeah you'd need to be far more specific. You need to think in terms of context.

    Look at every entity as its own script environment, glued together by the core engine. Some entities are multiple environments. For example the terraformer is an object with a script. When interacted with, an interface is "spawned" lets say. That interface is actually a separate entity with its own scripts. But they message each other to work as one.

    And note that you can patch the JSON files to add your own scripts into things. If it already has a script, it is usually better to hook the script itself(where "scripts" is an array thus can take more strings pointing to scripts) rather than replace the script.
     
    HerrJunky likes this.
  8. Cyel

    Cyel Scruffy Nerf-Herder

    (You can also find documentation about the modding Lua api in the /doc/lua folder, in the game's folder
     
  9. HerrJunky

    HerrJunky Void-Bound Voyager

    Ok thanks Guys !
    So i think i'll just hook my script into the destryoruin questtemplate and check whether or not the quest is completed and then trigger my own stuff...
    Its a little bit complicated, but im trying to make the transition between the vanilla stuff and my own(which should be triggered after the story) as smooth as possible without immersion-breaking quest pop-ups...
    Or is there another way, I know you can make these follow-up thing , but it shows you a pop-up as well...
     
  10. bk3k

    bk3k Oxygen Tank

    I've only lightly played around with the quest system. I've seen options like
    Code:
      "invisible" : false,
      "logOnly" : false,
    But I haven't seen for sure if they do what I think they'd do. I haven't examined to see if any quest scripts use these values, or if that's part of the hard-coded handling.
     
  11. HerrJunky

    HerrJunky Void-Bound Voyager

    Yep thanks, definitely a thing I'm going to try... Just to see what it does :nuruawe:
     

Share This Page