Jump to content
sarogahtyp

[solved] detect saving in singleplayer

Recommended Posts

Short question:

In a Singleplayer mission I need to detect if a save is initiated by player or automatically by mission and I want to execute a script (by mod) just before the saving occurs.

I would be very grateful for any ideas that could lead the way.

Share this post


Link to post
Share on other sites

EDIT: Just now noticed that it doesn't matter if it is manual or automatic, so you can use the OnSaveGame scripted EH https://community.bistudio.com/wiki/Arma_3:_Scripted_Event_Handlers

 

Old answer (only detects manual saving):

since the game is saved via a button click you could add an eventhandler to the button, so something like:

#include "\a3\ui_f\hpp\defineResincl.inc"
[missionNamespace, "OnGameInterrupt", {
	params ["_display"];
	private _btnSave = _display displayCtrl IDC_INT_SAVE;
	_btnSave ctrlAddEventHandler ["ButtonClick",{
		params ["_btnSave"];
		// Do stuff
	}];
}] call BIS_fnc_addScriptedEventHandler;

 

  • Thanks 1

Share this post


Link to post
Share on other sites
15 minutes ago, 7erra said:

EDIT: Just now noticed that it doesn't matter if it is manual or automatic, so you can use the OnSaveGame scripted EH https://community.bistudio.com/wiki/Arma_3:_Scripted_Event_Handlers

 

Old answer (only detects manual saving):

since the game is saved via a button click you could add an eventhandler to the button, so something like:


#include "\a3\ui_f\hpp\defineResincl.inc"
[missionNamespace, "OnGameInterrupt", {
	params ["_display"];
	private _btnSave = _display displayCtrl IDC_INT_SAVE;
	_btnSave ctrlAddEventHandler ["ButtonClick",{
		params ["_btnSave"];
		// Do stuff
	}];
}] call BIS_fnc_addScriptedEventHandler;

 

 

great answer, thx a lot.

just remains the question if the save occurs during the code executing in EH or if the EH-code is executed before the saving occurs (as I need it). But that I need to test I guess...

Share this post


Link to post
Share on other sites

@sarogahtyp: I like where this is going. 😉 

I'm going to investigate this too, but somehow I doubt the save EH will be useful... I'm wondering if it's possible to have the default "save" button point to a custom function, anyone?

It would then be easy to revert script-induced changes before saving so that they don't clutter the saved file...

  • Like 1

Share this post


Link to post
Share on other sites

EDIT : this where the save ctrl display is :

((findDisplay 49) displayCtrl 103)

IDC for the load button : 119

 

Let's have some fun!

 

EDIT² : list of all controls with CBA loaded for the pause menu :

Spoiler

IDC: 114998, className: Vignette
IDC: 115099, className: TileGroup
IDC: 114999, className: TileFrame
IDC: 115000, className: Tile_0_0
IDC: 115001, className: Tile_0_1
IDC: 115002, className: Tile_0_2
IDC: 115003, className: Tile_0_3
IDC: 115004, className: Tile_0_4
IDC: 115005, className: Tile_0_5
IDC: 115010, className: Tile_1_0
IDC: 115011, className: Tile_1_1
IDC: 115012, className: Tile_1_2
IDC: 115013, className: Tile_1_3
IDC: 115014, className: Tile_1_4
IDC: 115015, className: Tile_1_5
IDC: 115020, className: Tile_2_0
IDC: 115021, className: Tile_2_1
IDC: 115022, className: Tile_2_2
IDC: 115023, className: Tile_2_3
IDC: 115024, className: Tile_2_4
IDC: 115025, className: Tile_2_5
IDC: 115030, className: Tile_3_0
IDC: 115031, className: Tile_3_1
IDC: 115032, className: Tile_3_2
IDC: 115033, className: Tile_3_3
IDC: 115034, className: Tile_3_4
IDC: 115035, className: Tile_3_5
IDC: 115040, className: Tile_4_0
IDC: 115041, className: Tile_4_1
IDC: 115042, className: Tile_4_2
IDC: 115043, className: Tile_4_3
IDC: 115044, className: Tile_4_4
IDC: 115045, className: Tile_4_5
IDC: 115050, className: Tile_5_0
IDC: 115051, className: Tile_5_1
IDC: 115052, className: Tile_5_2
IDC: 115053, className: Tile_5_3
IDC: 115054, className: Tile_5_4
IDC: 115055, className: Tile_5_5
IDC: 1050, className: TitleBackground
IDC: -1, className: MissionNameBackground
IDC: 1000, className: Pause1
IDC: 1001, className: Pause2
IDC: 523, className: Title
IDC: 120, className: MissionTitle
IDC: 109, className: PlayersName
IDC: 2, className: ButtonCancel
IDC: 103, className: ButtonSave
IDC: 119, className: ButtonRevert
IDC: 101, className: ButtonOptions
IDC: 301, className: ButtonVideo
IDC: 302, className: ButtonAudio
IDC: 303, className: ButtonControls
IDC: 307, className: ButtonGame
IDC: 122, className: ButtonTutorialHints
IDC: 2408, className: ButtonReturnToHub
IDC: 104, className: ButtonAbort
IDC: 1002, className: ButtonSkip
IDC: 1003, className: ButtonAgain
IDC: 13184, className: DebugConsole
IDC: 11884, className: Title
IDC: 11891, className: Link
IDC: 11885, className: ExpressionBackground
IDC: 11892, className: ExpressionText
IDC: 12284, className: Expression
IDC: 13191, className: ExpressionOutputBackground
IDC: 13190, className: ExpressionOutput
IDC: 13284, className: ButtonCodePerformance
IDC: -1, className: ButtonExecuteServerBackground
IDC: 13286, className: ButtonExecuteServer
IDC: -1, className: ButtonExecuteAllBackground
IDC: 13285, className: ButtonExecuteAll
IDC: -1, className: ButtonExecuteLocalBackground
IDC: 13484, className: ButtonExecuteLocal
IDC: 11886, className: WatchBackground
IDC: 11893, className: WatchText
IDC: 12285, className: WatchInput1
IDC: 12286, className: WatchOutput1
IDC: 12287, className: WatchInput2
IDC: 12288, className: WatchOutput2
IDC: 12289, className: WatchInput3
IDC: 12290, className: WatchOutput3
IDC: 12291, className: WatchInput4
IDC: 12293, className: WatchOutput4
IDC: 13287, className: ButtonSpectatorCamera
IDC: -1, className: ButtonFunctions
IDC: 13291, className: ButtonAnimations
IDC: 13288, className: ButtonSplendidCamera
IDC: 13290, className: ButtonConfig
IDC: 13292, className: ButtonGUI
IDC: 90110, className: RscButtonMenu
IDC: 90111, className: RscButtonMenu
IDC: 1005, className: Version
IDC: 121, className: TraffLight
IDC: 6455, className: Feedback
IDC: -1, className: RscButtonMenu

 

  • Thanks 1

Share this post


Link to post
Share on other sites
40 minutes ago, haleks said:

I'm wondering if it's possible to have the default "save" button point to a custom function, anyone?

You can remove the default behavior by removing all events from the button and then making your own event:

#include "\a3\ui_f\hpp\defineResincl.inc"
[missionNamespace, "OnGameInterrupt", {
	params ["_display"];
	private _btnSave = _display displayCtrl IDC_INT_SAVE;
	_btnSave ctrlRemoveAllEventHandlers "ButtonClick";
	_btnSave ctrlAddEventHandler ["ButtonClick",{
		params ["_btnSave"];
		// Do stuff
	}];
}] call BIS_fnc_addScriptedEventHandler;

IDC_INT_SAVE is 119 btw. I am not sure if it is possible to create manual save games though. According to the BIKI https://community.bistudio.com/wiki/saveGame saves are auto saves.

  • Like 1
  • Thanks 2

Share this post


Link to post
Share on other sites

okay, that scripted EH works very well

// Add scripted EH to unhide everything before saving occurs in Singleplayer
if !( isMultiplayer ) then
{
 [missionNamespace, "OnSaveGame", 
 {
  [] call saroTweakMapFPS_fnc_unhide_map_objects;
 }] call BIS_fnc_addScriptedEventHandler;
};

It executes the code right before saving the game. That saves my ass 😉

 

Now the next problem is around the corner. I'd like to execute next piece of code right after saving is finished. So the question is how can I detect this?

Is it possible to detect this saving message which is shown during saving:

Spoiler

savegame.jpg

 

I guess there is a Display solution but I m really a noob when its about displays ...

 

Edit: Okay seems not to be as hard as I thought. Biki gives a display ID:

Quote

IDD_SAVE                                      13

 

*SaroGetsIntoTestingMode* ...

Share this post


Link to post
Share on other sites

displays ... I hate em.

 

Not working:

if !( isMultiplayer ) then
{
 [missionNamespace, "OnSaveGame", 
 {
  [] call saroTweakMapFPS_fnc_unhide_map_objects;
  
  _dummy = [] spawn
  {
   waitUntil {diag_log "waiting 4 save display"; sleep 0.5; !isNull findDisplay 13 };
   waitUntil {diag_log "waiting 4 end of save display"; sleep 0.5; isNull findDisplay 13 };
  
   [] call saroTweakMapFPS_fnc_hide_map_objects;
  };
	
 }] call BIS_fnc_addScriptedEventHandler;
};

 

gives me an endless loop logging "waiting 4 save display"

 

I guess I could use some help again...

Share this post


Link to post
Share on other sites

what I did not notice was that the endless loop was started after the saving was finished already.

Therefore the solution is as easy as it can be:

 

// Add scripted EH to unhide everything before saving occurs in Singleplayer
if !( isMultiplayer ) then
{
 [missionNamespace, "OnSaveGame", 
 {
  // unhide before saving starts
  [] call saroTweakMapFPS_fnc_unhide_map_objects;
   
  // hide again after saving is finished
  [] spawn saroTweakMapFPS_fnc_hide_map_objects;
  	
 }] call BIS_fnc_addScriptedEventHandler;
};

Its simple. Code you call in that EH is executed before saving occurs. Code you spawn is just executed after saving is finished. Problem solved, Im happy.

  • Like 3

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

×