Game Development Community

Mission autosave script

by Krzysztof Szaton · 03/06/2009 (7:01 pm) · 7 comments

Hello.

File: missionAutoSave.zip

or Code:

/*======================
missionAutoSave.cs

Autobackup mission in /scriptsAndAssets/data/missions/backup/

$autosaveDelay - time delay in minutes
$autosaveEnabled - variable for reduce process(torque could run two processes.. one when you push button and another then you let go it)

=======================*/

$autosaveDelay= 10;
$autosaveEnabled = false;

function saveBackupMission()
{

	if($autosaveEnabled==true){
		MissionGroup.save("./scriptsAndAssets/data/missions/backup/missionBackup"@getRealTime()@".BAK");
		echo("Saved backup mission file - missionBackup"@getRealTime()@".BAK");
		schedule($autosaveDelay*60*1000,0,saveBackupMission); 
	}

}

function scheduleAutoSave(){

	if($autosaveEnabled!=true){
	$autosaveEnabled = true;
		schedule($autosaveDelay,0,saveBackupMission); 
		echo("Autosave is ENABLED.");
		
	}

}

Installation:
- copy file to folder game/scriptsAndAssets/server/scripts
- add exec("./missionAutoSave.cs"); in game.cs(same folder as above)
- add for example moveMap.bind(keyboard, "f2", scheduleAutoSave); in config.cs(gamescriptsAndAssetsclient)

Push F2 button in your mission editor. You should see 'Autosave is ENABLED' text in console. Your backup files will be in folder mission/backup. Make sure you have permission to write files on hard drive;)

Customization:
$autosaveDelay - you can change this variable and set your own delay. This value is in minutes and default is set to 10 minutes.


Enjoy and please share with us your improvement of this script:)

Best regards,
Chris from Artifex Mundi

About the author

Recent Blogs


#1
03/06/2009 (7:58 pm)
there seems to be a problem with the download......
#2
03/06/2009 (8:17 pm)
Rapidshare says the file is 0 KB
#3
03/06/2009 (8:35 pm)
Sorry for this. Now you can download it. Thanks for info.
#4
03/06/2009 (9:16 pm)
nice, works as advertized.
now to implement loading saved file from a "saved games" menu....
#5
03/07/2009 (7:09 am)
I added it and it worked! Thanks!
#6
03/09/2009 (8:41 am)
Link is broken
#7
03/09/2009 (12:38 pm)
I don't have luck to file host sites... thank you for info. Now it's works.