gameMode.tscript.template 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. //This file implements game mode logic for an Example gamemode. The primary functions:
  2. //@@::onMissionStart
  3. //@@::onMissionReset
  4. //@@::onMissionEnd
  5. //Are the primary hooks for the server to start, restart and end any active gamemodes
  6. //onMissionStart, for example is called from core/clientServer/scripts/server/levelLoad.cs
  7. //It's called once the server has successfully loaded the level, and has parsed
  8. //through any active scenes to get GameModeNames defined by them. It then iterates
  9. //over them and calls these callbacks to envoke gamemode behaviors. This allows multiple
  10. //gamemodes to be in effect at one time. Modules can implement as many gamemodes as you want.
  11. //
  12. //For levels that can be reused for multiple gammodes, the general setup would be a primary level file
  13. //with the Scene in it having the main geometry, weapons, terrain, etc. You would then have subScenes that
  14. //each contain what's necessary for the given gamemode, such as a subScene that just adds the flags and capture
  15. //triggers for a CTF mode. The subscene would then have it's GameModeName defined to run the CTF gamemode logic
  16. //and the levelLoad code will execute it.
  17. if(!isObject(@@))
  18. {
  19. new GameMode(@@){};
  20. }
  21. //This function is called when the level finishes loading. It sets up the initial configuration, variables and
  22. //spawning and dynamic objects, timers or rules needed for the gamemode to run
  23. function @@::onMissionStart(%this)
  24. {
  25. //set up the game and game variables
  26. %this.initGameVars();
  27. if (%this.isActive())
  28. {
  29. error("@@::onMissionStart: End the game first!");
  30. return;
  31. }
  32. %this.setActive(true);
  33. }
  34. //This function is called when the level ends. It can be envoked due to the gamemode ending
  35. //but is also kicked off when the game server is shut down as a form of cleanup for anything the gamemode
  36. //created or is managing like the above mentioned dynamic objects or timers
  37. function @@::onMissionEnded(%this)
  38. {
  39. if (!%this.isActive())
  40. {
  41. error("@@::onMissionEnded: No game running!");
  42. return;
  43. }
  44. %this.setActive(false);
  45. }
  46. //This function is called in the event the server resets and is used to re-initialize the gamemode
  47. function @@::onMissionReset(%this)
  48. {
  49. // Called by resetMission(), after all the temporary mission objects
  50. // have been deleted.
  51. %this.initGameVars();
  52. }
  53. //This sets up our gamemode's duration time
  54. function @@::initGameVars(%this)
  55. {
  56. // Set the gameplay parameters
  57. %this.duration = 30 * 60;
  58. }
  59. //This is called when the timer runs out, allowing the gamemode to end
  60. function @@::onGameDurationEnd(%this)
  61. {
  62. //we don't end if we're currently editing the level
  63. if (%this.duration && !(EditorIsActive() && GuiEditorIsActive()))
  64. %this.onMissionEnded();
  65. }
  66. //This is called to actually spawn a control object for the player to utilize
  67. //A player character, spectator camera, etc.
  68. function @@::spawnControlObject(%this, %client)
  69. {
  70. //In this example, we just spawn a camera
  71. /*if (!isObject(%client.camera))
  72. {
  73. if(!isObject(Observer))
  74. {
  75. datablock CameraData(Observer)
  76. {
  77. mode = "Observer";
  78. };
  79. }
  80. %client.camera = spawnObject("Camera", Observer);
  81. }
  82. // If we have a camera then set up some properties
  83. if (isObject(%client.camera))
  84. {
  85. MissionCleanup.add( %this.camera );
  86. %client.camera.scopeToClient(%client);
  87. %client.setControlObject(%client.camera);
  88. %client.camera.setTransform("0 0 1 0 0 0 0");
  89. }*/
  90. }
  91. //This is called when the client has finished loading the mission, but aren't "in" it yet
  92. //allowing for some last-second prepwork
  93. function @@::onClientMissionLoaded(%this)
  94. {
  95. $clientLoaded++;
  96. if ($clientLoaded == $clientConneted)
  97. $gameReady = true;
  98. }
  99. //This is called when the client has initially established a connection to the game server
  100. //It's used for setting up anything ahead of time for the client, such as loading in client-passed
  101. //config stuffs, saved data or the like that should be handled BEFORE the client has actually entered
  102. //the game itself
  103. function @@::onClientConnect(%this, %client)
  104. {
  105. $clientConneted++;
  106. getPlayer(%client);
  107. }
  108. //This is called when a client enters the game server. It's used to spawn a player object
  109. //set up any client-specific properties such as saved configs, values, their name, etc
  110. //These callbacks are activated in core/clientServer/scripts/server/levelDownload.cs
  111. function @@::onClientEnterGame(%this, %client)
  112. {
  113. $Game::DefaultPlayerClass = "Player";
  114. $Game::DefaultPlayerDataBlock = "DefaultPlayerData";
  115. $Game::DefaultPlayerSpawnGroups = "spawn_player CameraSpawnPoints PlayerSpawnPoints PlayerDropPoints";
  116. $Game::DefaultCameraClass = "Camera";
  117. $Game::DefaultCameraDataBlock = "Observer";
  118. $Game::DefaultCameraSpawnGroups = "spawn_player CameraSpawnPoints PlayerSpawnPoints PlayerDropPoints";
  119. //Spawn NPCs for the map and stuff here?
  120. // This function currently relies on some helper functions defined in
  121. // core/scripts/spawn.cs. For custom spawn behaviors one can either
  122. // override the properties on the SpawnSphere's or directly override the
  123. // functions themselves.
  124. }
  125. function @@::onSceneLoaded(%this)
  126. {
  127. }
  128. function @@::onSceneUnloaded(%this)
  129. {
  130. }
  131. function @@::onSubsceneLoaded(%this)
  132. {
  133. }
  134. function @@::onSubsceneUnloaded(%this)
  135. {
  136. }
  137. //This is called when the player leaves the game server. It's used to clean up anything that
  138. //was spawned or setup for the client when it connected, in onClientEnterGame
  139. //These callbacks are activated in core/clientServer/scripts/server/levelDownload.cs
  140. function @@::onClientLeaveGame(%this, %client)
  141. {
  142. // Cleanup the camera
  143. if (isObject(%this.camera))
  144. %this.camera.delete();
  145. // Cleanup the player
  146. if (isObject(%this.player))
  147. %this.player.delete();
  148. }