Jump to content

Basic Persistence Kit


Recommended Posts

Basic (Ground Unit) Persistence Kit by Jinx / ChrisofSweden

 

Download

 

Purpose:
This is and is very much intended to be a Basic persistence kit that is as easy to use as possible. Demographically aimed at those that want to easily build a mission in the editor, populate it with lots of units, and be able to fly it one day, kill some stuff, log off, and keep going where they left off another day, perhaps with a friend, giving the sense of an ongoing ground war campaign. 

How it works:
It works by storing information on what ground units the gets destroyed in a file. This can be done manually or automatically at an interval you choose. On mission start/restart, loads this file and removes all previously destroyed units the mission.

What this does NOT:
It does not save unit positions or routes so any units that moved during the mission will be back at initial position at mission start/restart.
It does not save destroyed static objects or scenery/buildnings.
It does not work with dynamically spawned ground units.

 

FILE CONTENTS

 

readme.txt
This text.

Mission.lua
Contains mission configuration variables, an event handler for logging destroyed units and calls to save and load file functions.

File_IO_functions.lua
Contains the actual file IO functions that creates/saves and loads dead units table to/from file.

Persistence_demo.miz
Example DCS mission file


PREREQUISITES:


To allow DCS Scripting Environment to create the save state file in your file system you also need to modify file:
"DCS World\Scripts\MissionScripting.lua"

Change:

do
    sanitizeModule('os')
    sanitizeModule('io')
    sanitizeModule('lfs')
    require = nil
    loadlib = nil
end

--To:

do
    --sanitizeModule('os')
    --sanitizeModule('io')
    --sanitizeModule('lfs')
    require = nil
    loadlib = nil
end

 

USAGE:

Put the unzipped folder "Basic Persistance Kit" into your Saved Games\DCS\Missions\ folder

Open file Mission.lua and configure the few variables in the USER CONFIG section, they are all explained and examples supplied.
Save and close Mission.lua.

Open DCS Mission Editor.
Create a mission and populate it how you want, or open an existing mission you would like to add persistence to.
Give the mission the same name you put in Mission.lua and save it.
Add a trigger TYPE "ONCE" with CONDITION "TIME MORE" set to 3, and add two ACTIONS:
    DO SCRIPT FILE and load the "File_IO_functions.lua" script.
    DO SCRIPT FILE and load the "Mission.lua" script.

Save your mission and play.

Enjoy!

 

Download

 


Edited by chrisofsweden
Added info
  • Like 1

GPU: PALIT NVIDIA RTX 3080 10GB | CPU: Intel Core i7-9700K 4,9GHz | RAM: 64GB DDR4 3000MHz
VR: HP Reverb G2 | HOTAS: TM Warthog Throttle and Stick
OS: Windows 10 22H2

Link to comment
Share on other sites

  • Wizard1393 changed the title to Basic Persistence Kit

Thanks for a nice addition to any mission builder's arsenal of tools. 

If you don't mind, some comments to perhaps improve your great contribution:

 

in msn.loadState() on line 121 your code is 

Unit.getByName(v.name):destroy()

This will break if the mission spawns a unit by script and such a unit is subsequently killed. It would be better if you nil-trapped the result of getByName() before destroying it.

Then again, any unit that is not placed with ME (i.e. any dynamically spawned ground unit) will not be persisted either (which is the root cause of above issue because it's death is persisted and will conflict on load). Perhaps a better approach could be to persist all *living* units/groups, and restore their states (and positions) upon load and remove all others? That could also help with dynamically spawned units. It would be a major change, though, and not backwards-compatible with previous saves.

Oh, and a tiny (really tiny) clarification you may want to add (it's implicitly stated): in "red" or "blue" tracked mode, the other side AND neutral kills aren't tracked. 

In any event - thank you for sharing your work!

-ch


Edited by cfrag
  • Thanks 1
Link to comment
Share on other sites

Firstly, thanks for your input, cfrag.

This is and is very much intended to be a Basic persistence kit. It's sole purpose is aimed at those that want to easily build a mission in the editor, populate it with lots of units, and be able to fly it one day, kill some stuff, log off, and keep going where they left off another day, perhaps with a friend, like an ongoing ground war campaign. It's really the opposite of "forever-missions" that rely on complicated scripts to keep the mission dynamic and alive all the time. I'm sure there are other persistence script libraries out there that can do all that you mention and more, but perhaps also a little more difficult for a beginner mission creator to set up and configure.

I could clarify this bit further in the info I guess, "Not compatible with scripts dynamically spawning units". EDIT: Updated info
Also, sure I can fix the function you mention so it won't break the script if it tries to remove a unit that doesn't exist.

Also good point about the all/red/blue tracked coalition options. I'll see if I can update the info a bit, and/or update the code to be all, red/neutral or blue/neutral tracking.

 

EDIT2: Made some changes to saveFilePath options and also made adjustments to coalition tracking and documentation and the destroy-bit you were on about:

			if Unit.getByName(v.name) then
				Unit.getByName(v.name):destroy()
			end

 


Edited by chrisofsweden
  • Thanks 1

GPU: PALIT NVIDIA RTX 3080 10GB | CPU: Intel Core i7-9700K 4,9GHz | RAM: 64GB DDR4 3000MHz
VR: HP Reverb G2 | HOTAS: TM Warthog Throttle and Stick
OS: Windows 10 22H2

Link to comment
Share on other sites

  • 11 months later...
  • 1 year later...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...