Jump to content
david-grylls

Spawning a Scene Through Trigger (BIS_fnc_saveScene)

Recommended Posts

G'day forum people!

 

Currently I am developing a mission that is quiet extensive and long (campaign style missions). Now I have already started my mission and it has A LOT of objects and as a result it can become quiet laggy and sometimes the objects just dont need to be there. However I found Bohemia found a way around this however the way they did it is in no way documented on any website on the internet. 

It's called BIS_fnc_saveScene and I know it exists cause it is in the functions viewer under missionConfigFile.

Whenever I search this it redirects me to pages on BIS_fnc_MP.

 

Warning, I may spoil a part of the Boot-camp Mission 'Damage Control' here.

During the 5th Boot-camp mission, Damage Control, you drive past the hospital. At the hospital you drive past what appears to be the aftermath of a bloody massacre. Interestingly however, upon opening the mission in the editor, I noticed that no units or anything had been placed. Simply a trigger with the On Act.: containing:

[thisTrigger, "BIS_hospital"] call BIS_fnc_saveScene;

 

I'm assuming this. BIS_fnc_saveScene calls on a predefined script that is similar to a mission.sqm file to place objects and entities within the world. I know this because a 'hospital.sqf' (setup\comps\hospital.sqf) file exists and it contains what looks like a script to spawn objects at the hospital. 

 

So how does one use this BIS_fnc_saveScene and on top of that set it up? I have no idea how it works and the fact the wiki doesn't even document concerns me. I could well be completely wrong and it's something else. 

 

Thanks in advance,

David-Grylls

Share this post


Link to post
Share on other sites

Scenes is basically a caching script for all entities, vehicles within a trigger.
Hospital.sqf basically spawns a set of objects, some of which have a variable placed on them called "BIS_fnc_saveScene_init".
There is then a trigger that at mission start looks at all entities/vehicles within its area, saves their information and deletes itself via saveScene.
Then when ever needed this set of object can be loaded back in via loadScene OR deleted via deleteScene.

These are not 'vanilla' scripts, as in they do not exists in the configfile CfgFunctions but are instead loaded per mission.
Due to this you cannot use BIS_fnc_# as BIS is a protected tag name, instead you need to load the functions under your own tag for your mission. e.g
Description.ext

class CfgFunctions
{
	class MyScenes
	{
		tag = "MyTag";
		class Scenes
		{
			file = "A3\Missions_F_Bootcamp\Campaign\Functions\Scenes";

			class deleteScene	{};
			class loadScene		{};
			class saveScene		{};
			class setSceneInit	{};
		};
	};
};

HERE is a quick example mission.
The trigger initScene saves the objects at mission load and is deleted by the scene function.
The trigger sceneloader looks after loading/deleting the scene dependant on whether the player is present.

Some variables that you can store on objects to effect their behaviour in relation to scenes.
"BIS_fnc_saveScene_init" //code run on the object when loaded by a scene, can be CODE, STRING or an ARRAY of either
"BIS_fnc_saveScene_exclude" //This object is ignored by scene functions if true, BOOL

 

Some global variables for tracking scenes

"BIS_fnc_saveScene_scenes" //all currently saved scenes
"BIS_scenes_#_savedVehicles" //saved vehicles info for scene #
"BIS_scenes_#_savedGroups" //saved groups info for scene #
"BIS_scenes_#_vehicles" //all currently active vehicles of scene #
"BIS_scenes_#_groups" //all currently active groups of scene #
"BIS_scenes_#_WPs" //all currently active WPs of scene #

 

A loaded scene will always start at its saved position e.g in the test mission the soldier will always start at the begining of his route no matter where he was when you last exit the trigger.

As saveScene needs a trigger to to work, if you needed to save positions of objects every time you left an area you would need to spawn a trigger of the areas size and call saveScene passing the trigger and the scene name. Although saveScene does not allow overwriting of an existing scene name so the scene name would first need removing from BIS_fnc_saveScene_scenes.

Note that for groups that have waypoints the whole waypoint list is saved and no reference to their current actual waypoint is saved, on scene load their current waypoint is set to the first in their list. It is likely possible that if needed you could override this behaviour by updating the units init "BIS_fnc_saveScene_init" with some code to set their current waypoint but i have not test this.

 

Heres a proof of concept for saving group waypoint positions, replace the sceneloader triggers OnDeact with this....

 

_nul = [] spawn {
    
    _scenes = BIS_fnc_saveScene_scenes;
    _scenes = _scenes - [ "MyScene" ];
    BIS_fnc_saveScene_scenes = _scenes;
    
    
    {
        _leader = leader _x;
        _inits = _leader getVariable [ "BIS_fnc_saveScene_init", [] ];
        if !( _inits isEqualType [] ) then { _inits = [_inits] };
        _nul = _inits pushBack format[ "
            this setpos %1;
            _nul = this spawn {
                waituntil { count waypoints group _this >= %2 };
                group _this setCurrentWaypoint [ group _this, %2 ];
            };
        ", getPos _leader, ( currentWaypoint group _leader ) ];
        _leader setVariable [ "BIS_fnc_saveScene_init", _inits ];
    }forEach BIS_scenes_myscene_groups;
    
        
    _trg = createVehicle [ "EmptyDetector", getPos sceneloader, [], 0, "CAN_COLLIDE" ];
    _trg setTriggerArea triggerArea sceneloader;
    
    
    [ _trg, "MyScene", false ] call mytag_fnc_saveScene;
    [ "MyScene", false ] call MyTag_fnc_deleteScene;
};

 

 

Also note you can not use the extended usage of some of the functions, like saveScene can also delete the scene when saved by setting param 2 to true, because the script calls BIS_fnc_# and due to BIS beinig a protected function tag the function does not exist.

  • Like 2

Share this post


Link to post
Share on other sites

Scenes is basically a caching script for all entities, vehicles within a trigger.

Hospital.sqf basically spawns a set of objects, some of which have a variable placed on them called "BIS_fnc_saveScene_init".

There is then a trigger that at mission start looks at all entities/vehicles within its area, saves their information and deletes itself via saveScene.

Then when ever needed this set of object can be loaded back in via loadScene OR deleted via deleteScene.

 

Ahh thank you for breaking this down and giving a clear well defined example. Considering it's Christmas I've had a very busy day but I'll be sure to download your example mission and also try out what you said sometime tomorrow.

 

Thanks very much regardless larrow!

 

EDIT:

Ah looking at the mission example I have a very good understanding now! Thank you very much Larrow for your help! Much appreciated!

 

-David-Grylls

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

×