60 sec end mission function
by Simon Kilroy · in Torque Game Engine · 04/30/2007 (5:23 am) · 12 replies
Is there a simple function you can create in your game file that will end the mission and quit Torque after 60 seconds. I presume I could just insert the quit() function after some kind of wait function but Im not sure exactly how or where Id put it. Does anyone know how Id do this?
#2
04/30/2007 (5:59 am)
Aye, at the start of game.cs:// Game duration in secs, no limit if the duration is set to 0 $Game::Duration = 20 * 60;
#3
Just wondering, but why would want to close your game ofter 60 seconds?
04/30/2007 (6:22 am)
function waitToClose()
{
schedule(60000, 0, quit);
}Just wondering, but why would want to close your game ofter 60 seconds?
#4
04/30/2007 (6:43 am)
Maybe it's like a "bonus" round where you have 60 seconds to collect as many widgets as you can for extra-points and at the end of the round the total is calculated and the next "stage" begins.
#5
@Corey: Yeah you got it, the player only gets 60 seconds to fly around the mission and collect as much as possible.
04/30/2007 (6:48 am)
@Caleb: Where do I put this, I put it into game.cs after the startgame function. Nothing happened, so I put it waitToClose(); after the start game function too but then it closes right away after it loads.@Corey: Yeah you got it, the player only gets 60 seconds to fly around the mission and collect as much as possible.
#6
04/30/2007 (7:00 am)
Question, i found that the $game::Duration function in the game.cs also effects every board, how do i specifically indicate certain missions get longer durations and how do i set the duration to infinity, for onlineplay for example
#7
04/30/2007 (7:26 am)
Quote:Store the variable in the mission file.
how do i specifically indicate certain missions get longer durations
Quote:
how do i set the duration to infinity
[b]// Game duration in secs, no limit if the duration is set to 0[/b] $Game::Duration = 20 * 60;Read the comment.
#8
04/30/2007 (10:37 am)
Simon, you should have a file in your client/scripts folder called "missionDownload.cs". In there is a function called "onMissionDownloadComplete", put "waitToQuit();" in there.
#9
05/01/2007 (3:58 am)
I put the function in game.cs, and I put in the waittoQuit(); command Caleb, but still no luck. Should the function go somewhere specific in game.cs, I just put it in with the other functions. Also, is the 6000 equal to 60 seconds, so its measured in milliseconds right? thanks
#10
common/client/missionDownload.cs
That will disconnect from the mission after 10 seconds and return you to the main menu. I think that's more what you're after as opposed to quiting the engine entirely. I've put comments in so you should be able to follow the code and change the timer to suit your needs. I've even included a basic count down that will display in the chatHud.
05/01/2007 (5:06 am)
Here's a head start:common/client/missionDownload.cs
//----------------------------------------------------------------------------
// Phase 3
//----------------------------------------------------------------------------
new ScriptObject(MissionTimer)
{
class = MissionTimer;
};
function MissionTimer::startCountdown(%this, %timer)
{
// Display the time remaining in the message HUD
messageAll("","Mission Timer: " @ %timer);
// Deincrement the timer
%timer--;
// Call the function every second until the timer runs out
if(%timer)
%this.schedule(1000, startCountdown, %timer);
}
function MissionTimer::start(%this)
{
// Enter time before mission ends in seconds
%timer = 10;
// Start the countdown timer
%this.startCountdown(%timer);
// End the mission after time is up and return to main menu
schedule(%timer * 1000, 0, disconnect);
}
function clientCmdMissionStartPhase3(%seq,%missionName)
{
onPhase2Complete();
StartClientReplication();
StartFoliageReplication();
echo ("*** Phase 3: Mission Lighting");
$MSeq = %seq;
$Client::MissionFile = %missionName;
// Need to light the mission before we are ready.
// The sceneLightingComplete function will complete the handshake
// once the scene lighting is done.
if (lightScene("sceneLightingComplete", ""))
{
error("Lighting mission....");
schedule(1, 0, "updateLightingProgress");
onMissionDownloadPhase3(%missionName);
$lightingMission = true;
}
[b]MissionTimer.start();[/b]
}That will disconnect from the mission after 10 seconds and return you to the main menu. I think that's more what you're after as opposed to quiting the engine entirely. I've put comments in so you should be able to follow the code and change the timer to suit your needs. I've even included a basic count down that will display in the chatHud.
#11
P.S.- It does work, I tried it.
05/01/2007 (6:02 am)
Instead of putting in the client side, just put:function waitToClose()
{
schedule(60000, 0, quit);
}In your server/scripts folder, inside your game.cs file, and put the following inside the "onMissionLoaded" function:waitToClose();About the amount of time, 6000 would be six seconds and 60000 would be sixty seconds.
P.S.- It does work, I tried it.
#12
@Tim: Thanks for taking the time for doing out the code. I actually do need the quit function for what Im doing as the Torque part will be preceeded and proceeded (and loaded from) with content(video) in Macromedia Director.
05/01/2007 (8:36 am)
@Caleb: Cheers Caleb, I just had the waitgame function in the wrong place. All good now. @Tim: Thanks for taking the time for doing out the code. I actually do need the quit function for what Im doing as the Torque part will be preceeded and proceeded (and loaded from) with content(video) in Macromedia Director.
Torque Owner Aaron E
Default Studio Name
Hopefully, I'm not misunderstanding your question.