FreeSpace Releases > Scripting Releases

ship save/load script

(1/18) > >>

Admiral MS:
Goober5000 made a much improved (and backwards compatible) version of the script:

https://www.hard-light.net/forums/index.php?topic=96939

----------------

Ship save/load script for checkpoints and red-alert like missions.
Instructions how to use it can be found in the readme.

Download:
http://www.mediafire.com/file/6dclueqkc4yxuol/Ship_SaveLoad_script.zip

Use 3.7.2 or newer (probably works on 3.6.16 upwards).

----------------

While working on a campaign I remembered reading that red-alert is not always doing what it should, especially with branching missions and several red-alert missions in a row. So I thought that a script might be a solution and because I wanted to learn how scripting works (haven't done much programming up to now, nothing object oriented) I started creating a script that saves all important (shipclass, hitpoints, ammo left,...) and some not so important (energy, shields, ...) shipdata into a file and loads the data into the game from the file.

The script is working as it should and gets called via script-eval with the shipname in FRED. It manages data for several ships in one file and does ship-vanish when a ship that was dead or absent while saving gets loaded. That way it can be used for red-alert like missions while playing them in the simulator or when a ship is not present in the next mission but is used again in the mission afterwards without repairs.

That said I have a few questions:

Does a script like this already exist and I just didn't find it?
Does it make sense at all to make a script for something the game engine should be able to do?

Is anyone interested in such a script and wants to see some feature in it? I'm still thinking about what else can be added or what options for loading may be of use...

The script needs a place to save shipdata and possibly a configuration file. Do you know what filetype may be the best choice and where to save it?

At the moment everything is in one file and all functions are in

--- Code: ---#Global Hooks
$Global:
[
...
]
#end

--- End code ---
I'm not exactly sure if this is the right place or if the functions should be better somewhere else.

So if there is any interest in the script I'll put in some changes, clean it, try to follow some of the advise in http://www.hard-light.net/forums/index.php?topic=72312.0 and release it. At the moment it's more or less the result of me learning lua the hard way with a target and without starting with easy examples like 'Hello World'  :D

Nuke:
the thing i like about scripting is its not fred. im not really sure what can and cant be pulled off with existing features in the mission editor, im not sure what bugs affect red alert missions. but having a way to log stats for ships and reload them in the next mission with exactly the same stats sounds impressive. not sure if that is out of fred's capabilities or not.

it sounds like your'e using fred to call functions defined globally with scripting. of course i would use the $game_init: hook because i dont think global hooks work with modular tables, so if you stacked your script onto another mod wih scripting, only one of those mods would get its global hook scripts used which could lead to things you defined being nil when you go to use them. instead use:

--- Code: ---#Conditional Hooks
$Application: FS2_Open
$On Game Init:
[
--script goes here
]
#end

--- End code ---
you should also kind of keep the use of globals to the minimum. using locals in functions is sufficient so long as you use descriptive enough names on your functions. you can further reduce the number of globals by sticking functions in tables such as:

--- Code: ---pongFuncs = {}
function pongFuncs.initPong()

--- End code ---
of course this kinda thing is somewhat overkill in most cases and even i dont do this. you could also make things easier and just use a prefix specific to your script on all your global names. this is also somewhat overkill because there just arent enough people using scripting for people to have clashing variables.

i probibly dont have much use for such a script, of course im not really a mission designer so i wouldnt know. getting non-scripters (especially moders who are primarily graphics people, and to a lesser degree freders) to use scripts no matter how well packaged and well written scripts are is all but impossible. there are exceptions, such as mega-mods and tcs who would jump at the possibility to have a full time scripter on their team. my scripting interest pretty much revolves around graphics, game play and physics. i do have a concept for a mod which revolves around being able to "collect" supplies from one mission add them to an inventory of sorts and use them to "collect" more supplies in the next mission, and where failing to "collect" them results in a very hard game, and will end the game for you when the inventory reaches zero. but its a bridge i cross if i ever get there.

Admiral MS:

--- Quote ---the thing i like about scripting is its not fred. im not really sure what can and cant be pulled off with existing features in the mission editor, im not sure what bugs affect red alert missions. but having a way to log stats for ships and reload them in the next mission with exactly the same stats sounds impressive. not sure if that is out of fred's capabilities or not.
--- End quote ---
You can do some saving in fred using player-persistent variables but for a lot of ships you need tons of variables and so on. I think changing the class of a ship to something else and loading all other stats is impossible in fred.


--- Quote ---it sounds like your'e using fred to call functions defined globally with scripting. of course i would use the $game_init: hook because i dont think global hooks work with modular tables, so if you stacked your script onto another mod wih scripting, only one of those mods would get its global hook scripts used which could lead to things you defined being nil when you go to use them. instead use:

--- Code: ---#Conditional Hooks
$Application: FS2_Open
$On Game Init:
[
--script goes here
]
#end

--- End code ---

--- End quote ---
The script is used in fred like a sexp with the shipname as argument. For a number of uses you should be able to call it everytime (so save and load in the same mission). $On Game Init: doesn't seem to enable this.


--- Quote ---you should also kind of keep the use of globals to the minimum. using locals in functions is sufficient so long as you use descriptive enough names on your functions. you can further reduce the number of globals by sticking functions in tables such as:

--- Code: ---pongFuncs = {}
function pongFuncs.initPong()

--- End code ---
of course this kinda thing is somewhat overkill in most cases and even i dont do this. you could also make things easier and just use a prefix specific to your script on all your global names. this is also somewhat overkill because there just arent enough people using scripting for people to have clashing variables.
--- End quote ---
I already did most of this because i got a number of problems when using globals. There are only local variables and the complete shipdata is stored in one table with a lot of integrated tables. The data is transferred via function calls anyway.


I expected that only a few people will ever look into the scripting section but I'll finish the script for use in my campaign and propably release it in a few days. Some campaigns already have in-mission savepoints and i may try to extend the script to be used at reloading to a given point in a mission or you can do quite some funny things with it in a parody campaign.
Scripting really needs some advertising outside this part of forum...

General Battuta:
This would be a much better way to do this stuff than the system used in War in Heaven. If I can figure out how to use it I'd definitely consider it as a replacement. Nice job.

Admiral MS:
While trying to implement the last feature into the script i sort of hit a wall.
I tried to use

--- Code: --- if (mn.evaluateSEXP("is-destroyed-delay !0! !"..shipname.."!")) then
--- End code ---
and the game dumps me to desktop with a stupid error message:

Can't find operator s-destroyed-delay in operator list
.
ntdll.dll! KiFastSystemCallRet
kernel32.dll! WaitForSingleObjectEx + 67 bytes
kernel32.dll! WaitForSingleObject + 18 bytes
fs2_open_3_6_12r_INF_SSE2.exe! <no symbol>
fs2_open_3_6_12r_INF_SSE2.exe! <no symbol>
fs2_open_3_6_12r_INF_SSE2.exe! <no symbol>

Debug gives an assertion at that point :confused::

Assert: *Mp == '('
File: sexp.cpp
Line: 18613

It does this with the same error message no matter what is actually written inside evaluateSEXP(" ... ") and the debug log doesn't contain any more information with the standart settings.

Am i using it the wrong way or what's the problem with it?

Navigation

[0] Message Index

[#] Next page

Go to full version