ExampleGameMode.tscript 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. if(!isObject(ExampleGameMode))
  2. new GameMode(ExampleGameMode){};
  3. //-----------------------------------------------------------------------------
  4. // The server has started up so do some game start up
  5. //-----------------------------------------------------------------------------
  6. function ExampleGameMode::onMissionStart(%this)
  7. {
  8. //set up the game and game variables
  9. %this.initGameVars();
  10. if (%this.Running)
  11. {
  12. error("onMissionStart: End the game first!");
  13. return;
  14. }
  15. // Inform the client we're starting up
  16. for (%clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++)
  17. {
  18. %cl = ClientGroup.getObject(%clientIndex);
  19. commandToClient(%cl, 'GameStart');
  20. }
  21. %this.Running = true;
  22. }
  23. function ExampleGameMode::onMissionEnded(%this)
  24. {
  25. if (!%this.Running)
  26. {
  27. error("onMissionEnded: No game running!");
  28. return;
  29. }
  30. for (%clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++)
  31. {
  32. %cl = ClientGroup.getObject(%clientIndex);
  33. commandToClient(%cl, 'GameEnd', %this.EndGamePause);
  34. }
  35. %this.Running = false;
  36. }
  37. function ExampleGameMode::onMissionReset(%this)
  38. {
  39. // Called by resetMission(), after all the temporary mission objects
  40. // have been deleted.
  41. %this.initGameVars();
  42. }
  43. function ExampleGameMode::initGameVars(%this)
  44. {
  45. }
  46. function ExampleGameMode::onGameDurationEnd(%this)
  47. {
  48. }
  49. function ExampleGameMode::onClientEnterGame(%this, %client)
  50. {
  51. // This function currently relies on some helper functions defined in
  52. // core/scripts/spawn.cs. For custom spawn behaviors one can either
  53. // override the properties on the SpawnSphere's or directly override the
  54. // functions themselves.
  55. //echo (%game @"\c4 -> "@ %game.class @" -> GameCore::onClientEntergame");
  56. // Sync the client's clocks to the server's
  57. commandToClient(%client, 'SyncClock', $Sim::Time - %this.StartTime);
  58. //Set the player name based on the client's connection data
  59. %client.setPlayerName(%client.connectData);
  60. // Inform the client of all the other clients
  61. %count = ClientGroup.getCount();
  62. for (%cl = 0; %cl < %count; %cl++)
  63. {
  64. %other = ClientGroup.getObject(%cl);
  65. if ((%other != %client))
  66. {
  67. // These should be "silent" versions of these messages...
  68. messageClient(%client, 'MsgClientJoin', "",
  69. %other.playerName,
  70. %other,
  71. %other.sendGuid,
  72. %other.team,
  73. %other.score,
  74. %other.kills,
  75. %other.deaths,
  76. %other.isAIControlled(),
  77. %other.isAdmin,
  78. %other.isSuperAdmin);
  79. }
  80. }
  81. // Inform the client we've joined up
  82. messageClient(%client,
  83. 'MsgClientJoin', '\c2Welcome to the Torque demo app %1.',
  84. %client.playerName,
  85. %client,
  86. %client.sendGuid,
  87. %client.team,
  88. %client.score,
  89. %client.kills,
  90. %client.deaths,
  91. %client.isAiControlled(),
  92. %client.isAdmin,
  93. %client.isSuperAdmin);
  94. // Inform all the other clients of the new guy
  95. messageAllExcept(%client, -1, 'MsgClientJoin', '\c1%1 joined the game.',
  96. %client.playerName,
  97. %client,
  98. %client.sendGuid,
  99. %client.team,
  100. %client.score,
  101. %client.kills,
  102. %client.deaths,
  103. %client.isAiControlled(),
  104. %client.isAdmin,
  105. %client.isSuperAdmin);
  106. }
  107. function ExampleGameMode::onClientLeaveGame(%this, %client)
  108. {
  109. // Cleanup the camera
  110. if (isObject(%client.camera))
  111. %client.camera.delete();
  112. }
  113. function ExampleGameMode::onInitialControlSet(%this)
  114. {
  115. }
  116. function ExampleGameMode::onSceneLoaded(%this)
  117. {
  118. echo("===================================");
  119. echo("ExampleGameMode - Scene is loaded");
  120. }
  121. function ExampleGameMode::onSceneUnloaded(%this)
  122. {
  123. echo("===================================");
  124. echo("ExampleGameMode - Scene is unloaded");
  125. }
  126. function ExampleGameMode::onSubsceneLoaded(%this)
  127. {
  128. echo("===================================");
  129. echo("ExampleGameMode - Subscene is loaded");
  130. }
  131. function ExampleGameMode::onSubsceneUnloaded(%this)
  132. {
  133. echo("===================================");
  134. echo("ExampleGameMode - Subscene is unloaded");
  135. }