Jump to content
Sign in to follow this  
celery

Detect load game or ESC menu?

Recommended Posts

Is there a way of detecting loading a savegame or going to the ESC menu and back other than comparing time and diag_tickTime?

Share this post


Link to post
Share on other sites

There is no "official" way to do this as far as I know, but you could take advantage of the fact that animated objects (e.g., a door in a house) get reset when loading a game. At the beginning of your mission, open some door away from the mission area with the animate command. Then, create a trigger that checks to see if the door closes (use the animationPhase command to do this). If it does, you know that the game has been loaded (and thus, all object animations reset).

Share this post


Link to post
Share on other sites

pauseOnLoad.sqf

This script is executed every time pause menu is opened, with _this select 0 being display. It works like onPlayerKilled.sqf, just create file with that name in mission directory.

However, this solution works only in single-player. For MP, you can set path to script in description.ext using following param:

onPauseScript = "myScript.sqf";

As for detecting load:

_loadSpawn = [] spawn {disableSerialization; waituntil {false};}
waituntil {scriptDone _loadSpawn};
hint "Game loaded";

You execute spawn with uncompletable condition, but disableSerialization command prevents it from continuing after load, which you can easily detect.

Edited by Moricky
  • Like 1

Share this post


Link to post
Share on other sites
You execute spawn with uncompletable condition, but disableSerialization command prevents it from continuing after load, which you can easily detect.

Nice.

or going to the ESC menu and back

You can also use displayEvent handlers to capture the key press:

 (findDisplay 46) displayAddEventHandler ["KeyDown","if ((_this select 1)==1) then {player sidechat 'Esc key pressed!'}"];

Although the event handler method is more for addon based scripts.

Share this post


Link to post
Share on other sites

Awesome! Thanks Gaia!

This will allow me to make a script that resumes music tracks where they were when the game was paused or saved (normally pausing causes the track to skip and saves don't remember the track at all). But I hope that it will be fixed officially since the previous games didn't have the skipping bug at least. :)

---------- Post added at 01:07 ---------- Previous post was at 00:25 ----------

Is it normal that the pauseOnLoad script doesn't take kindly to variables? I wanted to set a variable as true but I get this kind of error:

Error in expression <private ['_dummy']; _dummy = _this call compile preprocessFile 'pau>

Error position: <= _this call compile preprocessFile 'pau>

Error Generic error in expression

Doesn't give me that when I put just a normal command like hint in the script.

Share this post


Link to post
Share on other sites

How are you doing it Celery? I found that if I define a custom script through description.ext:

onPauseScript = "pause.sqf";

then I can set a variable without an error message. The pauseOnLoad script seemed to work with "setVariable" but would toss an error otherwise.

Share this post


Link to post
Share on other sites

Error in expression <private ['_dummy']; _dummy = _this call compile preprocessFile 'pau>

Error position: <= _this call compile preprocessFile 'pau>

Error Generic error in expression

As you can see, script is called, which requires it to return some value. Just put simple true to the last line and it should be fine.

Share this post


Link to post
Share on other sites
pauseOnLoad.sqf

This script is executed every time pause menu is opened, with _this select 0 being display. It works like onPlayerKilled.sqf, just create file with that name in mission directory.

However, this solution works only in single-player.

It didn't work for me in Arma2 single-player :( I was trying to sum a global variable.

---------- Post added at 06:01 ---------- Previous post was at 05:41 ----------

Nice.

You can also use displayEvent handlers to capture the key press:

 (findDisplay 46) displayAddEventHandler ["KeyDown","if ((_this select 1)==1) then {player sidechat 'Esc key pressed!'}"];

Although the event handler method is more for addon based scripts.

I pretended to assign diag_tickTime to a variable but if I press ESC again to exit the menu, would it assign the variable again?

Why is it more addon oriented?

Edited by scifer

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  

×