Modding Help Ship downgrade system

Discussion in 'Starbound Modding' started by captainrumbarrels, May 24, 2018.

  1. captainrumbarrels

    captainrumbarrels Phantasmal Quasar

    Hey all

    This might be a lengthy post so bare with me while I explain my research, then I'll ask my questions.
    So I'm designing a ship upgrade system where each "upgrade level" is basically a different ship.

    My Observations:
    • Deleting the .shipworld file only resets the world. All objects and ship crew disappear and a new ship pet gets generated. All hazard blocks reappear. The ship retains its .structure file.
    • Spawning an upgrade module using the command "/spawnitem shipT#", where # is the upgrade level, works fine.
    • Using the command /upgradeship '{\"shipLevel\" : #}' where # is upgrade level. This also works fine.
    • The shipT# item and /upgradeship command only work with upgrading ships. The game chat states that the upgrade is successfully applied but when I choose to go to a lower level this becomes a problem.
    • The ship upgrade level relative to what license is found in the licences.config. No problem here.
    • I can change what races use what ships in the universe_server.config. No problem here either.
    • The ship .structure file seems linked to the upgradelevel number, so keep the format and everything works fine, which it does - I looked at the T9 ship mod to see how its done.
    I can do a lua workaround in the ship.lua and player.lua conditions like so:

    function shipLevelCondition:conditionMet()
        return player.shipUpgrades().shipLevel >= self.level

    Here we notice that upgrade conditions by obtaining a license or item that offers an upgrade that the player will only upgrade the ship when the specified upgrade is greater than the current upgrade. we can change to any level we want theoretically by changing the code so that it reads:

    function shipLevelCondition:conditionMet()
        return player.shipUpgrades().shipLevel ~= self.level

    In this case the logic here is as long as the upgrade is not the same value as the current upgrade, we can, erm "upgrade", to any level we want. Great! This also works as I have a custom vendor offering me all available illegal licenses.

    There is also the issue of crew size which I've dealt with in the .structure files. That is, only offer an upgrade when you have a specified crew size. In my case I did a little bit of wizardry and offer the upgrade if the number of crew members is less than or equal to the specified crew size on the .structure files. Great! I get one license after the other.

    The Issue:
    So my issue here is I cannot get the game to apply a .structure map. I would like to keep this within game if possible because that is the basis of my mod that I am currently developing.

    I have come across this outdated thread where I see users able to switch to lower upgrade levels.

    More importantly I would like to know how the game applies a .structure upgrade. One idea I came up with was forcing an upgrade if it is a specific ship tier, say T4 then apply the upgrade. I made custom ship licenses that offer a lower tier upgrade and I still can't get the player's shipworld to change to a lower level .structure file.

    Any advice regarding this matter would be greatly appreciated!
  2. bk3k

    bk3k Oxygen Tank

    Here's the problem.
    1. The upgrade level you've achieved is stored in player data rather than the .shipworld.
    2. Last time I checked, it won't drop even if you do something like use a "shipT2" item when you're on tier 4.
    3. The game will automatically apply all your upgrades sequentially per the player data.

    That means even if you remove your .shipworld file, you can't normally downgrade. Only by swapping the .structure files (or editing them to use a lower tier's blockKey files and images) can you "downgrade". Only that isn't a real downgrade because it still considers you to be at 'X' tier.

    And that's the thing. You think it isn't applying your .structure file, but it probably did apply it... and after doing so applied some subsequent ones to get you back to the tier it thinks you should be at. Also note the game doesn't even look at your .structure files except initial generation and upgrade time. It won't reflect any changes without a shipworld delete or upgrade. For this reason I went through many disposable characters working on ship mods.

    So your only option is to have a blockImage/blockKey pair on T0 that places almost nothing except an object. Well it also MUST have an object with the "playerstart" flag too or you get an error. Anyhow your object can spawn other things like metamaterials(static collisions or dynamic placed by LUA similar to how doors work), other objects that have attached images (so you can replicated what the ship appearance) and you probably want to use "renderLayer" options too. That allows you to remove anything you placed prior.

    Well beyond that, maybe you could make ship "dungeons" and place the dungeon thus over-writing what was there. But I think you'd still need to make objects that replicate the ship either way.

    One other thing I made a crew size override already for my shipyard mod. It has a crew size of 200(because it is huge so why not) but you can still upgrade legitimately by reaching the vanilla crew level which would ordinarily enable this.

    from player.config.patch
        "op" : "add",
        "path" : "/companionsConfig/scripts/-",
        "value" :  "/scripts/companions/bk3k_crewCount_fix.lua"
    and the script I use to hook this -
    local sr_init = init
    local sr_update = update
    --I'm hooking init and update
    --The purpose of doing so is to make the ship upgradable at shipLevel * 2 crew
    --instead of forcing the player to max out the crew first.  Especially since I have set a maximum crew of 200!
    --This is necessary to enable non-illegal upgrading again
    function init(args)
      storage.sr_upgradeTimer = 20.5
      storage.upgradeUnlockCount = (math.max( (player.shipUpgrades().shipLevel - 2), 1) * 2) - 1
        --The ship has 2 crew threw level 3, therefore treat 0-3 as 1
        --the -1 offset so I can use > instead of >= just to be cheap
      storage.ownShipWorldId = player.ownShipWorldId()
    function update(dt)
      if storage.sr_upgradeTimer > 0 then
        storage.sr_upgradeTimer = storage.sr_upgradeTimer - dt
        if player.worldId() == storage.ownShipWorldId and recruitSpawner:crewSize() > storage.upgradeUnlockCount then
        storage.sr_upgradeTimer = 62
    Last edited: May 24, 2018
  3. captainrumbarrels

    captainrumbarrels Phantasmal Quasar

    I had my suspicions. The chat log was showing that the upgrade was being applied. So I know SOMETHING was happening. I have a feeling this can be solved with logic. I'm no expert in coding but I know enough to get by.

    I do like this line of thinking. What if, and I'm not saying this will work, BUT... Perhaps say I have a vendor that gives "licenses", (like the illegal ship upgrades for instance). The Ship level remains the same and you have a blank canvas like the BYOS mod except it places an invisible block at specific coordinates. These blocks cannot be harvested and are indestructible, the ship .png is rendered in the appropriate layer etc.

    and when you buy a "new" ship, all you are really doing is wiping everything clean and having a new block that is spawned from a unique license that gives the appearance of a new ship like you say. The ship still behaves the same, you're not changing the level and afaik, if it looks like a ship, behaves like a ship and warps like a ship, then I'm in business. though not sure about the block spawning from consuming an item in the player shipworld...


    And thanks again bk3k for the inspiration!

Share This Page