Author Topic: ship save/load script v2.0  (Read 2007 times)

0 Members and 1 Guest are viewing this topic.

Offline Goober5000

  • HLP Loremaster
  • 214
    • Goober5000 Productions
ship save/load script v2.0
This is an updated version of Admiral MS's ship save/load script.

shipsaveloadv2-sct.tbm
shipsaveloadv2-sexp.tbm

This is an optimization and upgrading rewrite.  It works largely the same as the original, and in fact savefiles from both scripts are compatible with each other.  The main differences are:

  • Now uses the dynamic sexp system, so you can call it without fiddling with script-eval.
  • Includes the deferred file access upgrade, speeding up reading and writing by only doing it once.
  • Removes some esoteric options.  Ships now always reproduce their exited status (destroyed/departed/vanished) exactly as it was saved.  The script always behaves as if the old stat parameter is set to 3.
  • Because of the previous point, ships are no longer created only to be immediately destroyed or warped out.  Consequently, the script no longer requires a custom "Shipsave" ship entry.
  • The Lua was cleaned up, with appropriate use of local variables and other efficiency enhancements.  The script no longer iterates through a table on every frame.

The script can coexist with Admiral MS's script, because it uses a different namespace for all its functions.  You can use both in your mod if you want.  I do recommend eventually converting all missions to use the new script because of the efficiency improvements, and in particular the every-frame performance hit of the old script.

The script requires a somewhat recent build due to the "shipname" parameter type.  Aside from this it should work in 19.0.  You would have to change the "shipname" parameter to "string" in the sexp.tbm, and you would have to type the ship names instead of selecting them from a menu.
« Last Edit: October 01, 2020, 09:18:37 am by Goober5000 »

 
Re: ship save/load script v2.0
Thank you for rewriting the script and making it into something less messy and more up to date. This is something I should have done 3 years ago but I always thought "going to do that later" and then forgot about it anyway. I still feel bad about my beginner level programming skills back then and that the save files have this horrible data structure...  ;)

I modified the first post of my own thread to link here as well.

« Last Edit: October 21, 2020, 06:57:47 am by Admiral MS »
Here goes scripting and copy paste coding
Freespace RTS Mod
Checkpoint/Shipsaveload script

  

Offline Mobius

  • Back where he started
  • 213
  • Porto l'azzurro Dolce Stil Novo nella fantascienza
    • Skype
    • Twitter
    • The Lightblue Ribbon | Cultural Project
Re: ship save/load script v2.0
Judging from what I read, this script is rather straightforward and requires a very limited number of SEXPs to trigger. I see it also activates ship-vanish automatically should a given ship be destroyed.

Are there any tutorials lurking around?
The Lightblue Ribbon

Inferno: Nostos - Alliance
Series Resurrecta: {{FS Wiki Portal}} -  Gehenna's Gate - The Spirit of Ptah - Serendipity (WIP) - <REDACTED> (WIP)
FreeSpace Campaign Restoration Project
A tribute to FreeSpace in my book: Riflessioni dall'Infinito
My interviews: [ 1 ] - [ 2 ] - [ 3 ]

 

Offline Goober5000

  • HLP Loremaster
  • 214
    • Goober5000 Productions
Re: ship save/load script v2.0
Axem wrote a pretty good tutorial on checkpoints.  Of course, if you're using the new script, you would have to use the new sexps instead of the script functions.
https://wiki.hard-light.net/index.php/Tutorial_-_Mission_Infrastructure

 

Offline Goober5000

  • HLP Loremaster
  • 214
    • Goober5000 Productions
Re: ship save/load script v2.0
Dilmah G discovered a bug in the loadout code that affects both this script as well as Admiral MS's original.  In brief, AmmoMax uses incompatible methods for reading and writing the value.  Mathematically speaking, set(get(x)) for AmmoMax is not idempotent.

Anyway, the bug was easy to fix once Dilmah G did the hard work of figuring it out.  I've updated the file in the first post.