Modding Help Is it possible to use crewmembers' ranks to determine equipment on spawn?

Discussion in 'Starbound Modding' started by Uacher, Mar 28, 2017.

  1. Uacher

    Uacher Scruffy Nerf-Herder

    I've been messing around the .npctype files of the crew to see how it works. One thing I've noticed is the list for the possible ranks and titles for the NPCs. My question is: Is it possible to use this names as values to determine default equipment for the NPCs?
  2. bk3k

    bk3k Oxygen Tank

    Depends if you know LUA. I don't know the crew system all that well, but it should be possible.

    I looked at it. Not too complex. It seems you'd want to hook the player companion scripts. in particular you'd want to hook the recruitable.setUniform function. The hooking part is easy.

    There seems to be a large amount of rank combinations available and that would be the real pain. crewmembermechanic has a base type "crewmember" thus it imports attributes from crewmember.npctype(the higher level type over-writes common attributes). That in turn has a base type of "base" aka base.npctype

    Possible ranks are pulled from crewmember.npctype.
          "ranks" : [
            "Second-to-Last <role>",
            "3rd Technical Assistant <field> Officer",
            "Assistant Deputy <role> Guy/Gal",
            "Trainee Apprentice <role>",
            "Temporary Relief <role>",
            "3rd Rear Lieutenant <role>",
            "64th Commodore <role>",
            "Standing <field> Officer",
            "Sitting <field> Officer",
            "Executive Coffee-Making <role>",
            "Command Master Chief Petty <field> Officer",
            "Independent <field> Auditor",
            "Dependant <field> Auditor",
            "Dreadnought <field> Officer",
            "Trainee <field> Mastermind",
            "Head of Petty <field> Arguments",
            "Backup <role>",
            "Reliable <field> Lacky",
            "Theoretical <field> Advisor",
            "Reliable <field> Lackey",
            "Head of <field> operations",
            "Wild Card <role>",
            "Head of <field> Relations",
            "Last-Minute <role>",
            "Expert in <field> Diplomacy",
            "<field> Innovation Manager",
            "Loose Cannon <role>",
            "Regional <field> Director",
            "Private <field> Investigator",
            "Temporal <field> Surveyor",
            "Radical <field> Innovator",
            "Independent Head of <field> Operations",
            "Just your average <role>",
            "Hobbyist <role>",
            "Master of <field> Matters",
            "Alternative <field> Advisory Representative",
            "Runner-Up <field> Officer",
            "Emergency <field> Officer",
            "First Mate's Second-Cousin's Third <role>",
            "Unpaid <field> Intern",
            "<field> Student",
            "<field> Forum Moderator",
            "Rogue <field> Profiteer",
            "Neutral Third Party <role>",
            "Low Quality <field> Negotiations",
            "Armchair <field> Expert"
    You'd want a rather large table where the indexes are strings made from all the combinations. Probably stored as a separate .config file somewhere and loaded with root.assetJson. And you'd want probably want a default in case the combination doesn't have a key in your big table, probably along these lines
    just like vanilla does. That's important, because you have to account for crew mods.

    But so you understand how large your table will be, just to cover the last item
    "Armchair <field> Expert"
    Note that <field> is swappable text for the NPC's actual field - different for every job. You're talking one key for every entry in "roles" x the number of crew types. By my quick count that's 598 individual string keys just to cover vanilla. Each key accesses a table with the gear for that rank. That's going to be a huge table you'll need to generate.

    If you stopped there, you'd break the tailors ability. So you probably also want to also clone the vanilla function under a different nameSpace, hook recruitable.init at the end to replace the message handler so that it goes to your cloned/renamed function. That way tailors won't be interfered with.

    But... I image after reading this, you'll probably loose interest in the idea. Varying the default uniform isn't a terrible idea, but you might want to use another criteria besides rank. It seems to serve as a flavor text generator rather than anything meaningful.
    Last edited: Mar 29, 2017
  3. Uacher

    Uacher Scruffy Nerf-Herder

    Yes, you are correct in assuming my loss of interest. That being said it only means that one possible avenue is closed; many more await consideration. I have decided to simply add more crew member types as variants of the already existing ones and give them their own ranks.

    Thanks much for the time amd help given.

    Sent from my SM-G570M using Tapatalk
  4. Uacher

    Uacher Scruffy Nerf-Herder

    I see that you know a lot more about LUA than I do. Perhaps you could help me with a doubt I have. Do you know where in the function that stores the crew's uniform data? I'd like to be able to add their weapons besides their clothes.
  5. bk3k

    bk3k Oxygen Tank

    I believe the answer you seek is in
    line 315

    You might have assumed that all the scripts for this are in /scripts/companions besides /scripts/util.lua as loaded by requires(). That would be a fair assumption considering that's all you'd see a reference to in files loaded by requires(), but remember I mentioned above
    and /npc/base.npctype has this.
      "scripts" : [
    So you have part of the script's environment coming from player.config:companionsConfig.scripts and even more from a file that's 2 levels of inheritance later. I think... that could have been handled in a more clear manor. I myself didn't notice til just now, except for wanting to find functions I saw referenced elsewhere.

    Chances are the answers to many of your questions lie in this other script.

Share This Page