Jump to content
Sign in to follow this  
dbun30

Some save game ideas...

Recommended Posts

Hi all.

 

Does anyone have any idea how to make a script to save the game after specific number of enemy kills? For example..
after 10 enemies killed automatically save the game.
Or maybe this...after some random time that has passed, save the game.
For example...between 1 and 10 minutes randomly save the game.
Thanks.

Share this post


Link to post
Share on other sites

@dbun30,
Like this,

Spoiler

after 10 enemies killed automatically,


YOU_fnc_killCount=
{ params [["_caller]];
private _count = _caller getVariable ["you_killCount", 0];
if (_count> 10) then {_caller setVariable ["you_killCount", 0]; savegame;};
_caller setVariable ["you_killCount", _count +1];
};

Make sure the bad guys have a killed EH,

this addEventHandler ["Killed", {
	params ["_unit", "_killer", "_instigator", "_useEffects"];
_killer call you_fnc_killCount;
}];

After random time,


YOU_fnc_saveTimer=
{
private _rNumber = random 600;
private _time = time + _rNumber;
	[_time] spawn {
		waitUntil {sleep 1; time> (_this select 0)}; 
	savegame;
	};
};


[] spawn you_fnc_saveTimer;

Will save at maximum 10 minutes

 

Have fun!

  • Like 1

Share this post


Link to post
Share on other sites

Thanks guys, i did some testing...but nothing works. :huh2:
Can you explain where to put this code:
YOU_fnc_killCount=
{ params [["_caller]];
private _count = _caller getVariable ["you_killCount", 0];
if (_count> 10) then {_caller setVariable ["you_killCount", 0]; savegame;};
_caller setVariable ["you_killCount", _count +1];
};

And where to put this code:
this addEventHandler ["Killed", {
    params ["_unit", "_killer", "_instigator", "_useEffects"];
_killer call you_fnc_killCount;
}];

 

Im playing a mission where units are spawned randomly after mission start, so i can't put any code into individual units in editor.

Share this post


Link to post
Share on other sites

@dbun30,

Spoiler

YOU_fnc_killCount=
{ params [["_caller]];
private _count = _caller getVariable ["you_killCount", 0];
if (_count> 10) then {_caller setVariable ["you_killCount", 0]; savegame;};
_caller setVariable ["you_killCount", _count +1];
};

You can paste this in init.sqf, Attributes init dialog, a units init-- pretty much anywhere code will stick; it just has to be loaded.

Quote

 ... units are spawned randomly after mission start, so i can't put any code into individual units in editor.

You can add the event handler in the summon unit script or just apply it to the group after they are spawned.

Spoiler

{
_x addEventHandler ["Killed", {
	params ["_unit", "_killer", "_instigator", "_useEffects"];
_killer call you_fnc_killCount;
}];
} forEach units _grp;

 


Have fun!

  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×