Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.IO;
- using System.Runtime.InteropServices;
- using System.Threading;
- using InfServer.Logic;
- using InfServer.Game;
- using InfServer.Scripting;
- using InfServer.Bots;
- using InfServer.Protocol;
- using Assets;
- namespace InfServer.Script.GameType_CR_Chaos
- { // Script Class
- /// Provides the interface between the script and arena
- ///////////////////////////////////////////////////////
- class Script_CR_Chaos : Scripts.IScript
- { ///////////////////////////////////////////////////
- // Member Variables
- ///////////////////////////////////////////////////
- private Arena _arena; //Pointer to our arena class
- private CfgInfo _config; //The zone config
- private Team _victoryTeam; //The team currently winning!
- private int _tickGameLastTickerUpdate;
- private int _lastGameCheck; //The tick at which we last checked for game viability
- private int _tickGameStarting; //The tick at which the game began starting (0 == not initiated)
- private int _tickGameStart; //The tick at which the game started (0 == stopped)
- //Settings
- private int _minPlayers; //The minimum amount of players
- ///////////////////////////////////////////////////
- // Member Functions
- ///////////////////////////////////////////////////
- /// <summary>
- /// Performs script initialization
- /// </summary>
- public bool init(IEventObject invoker)
- { //Populate our variables
- _arena = invoker as Arena;
- _config = _arena._server._zoneConfig;
- _minPlayers = 1;
- return true;
- }
- /// <summary>
- /// Allows the script to maintain itself
- /// </summary>
- public bool poll()
- { //Should we check game state yet?
- int now = Environment.TickCount;
- if (now - _lastGameCheck <= Arena.gameCheckInterval)
- return true;
- _lastGameCheck = now;
- //Do we have enough players ingame?
- int playing = _arena.PlayerCount;
- if ((_tickGameStart == 0 || _tickGameStarting == 0) && playing < _minPlayers)
- { //Stop the game!
- _arena.setTicker(1, 1, 0, "");
- _arena.gameReset();
- }
- //Do we have enough players to start a game?
- else if (_tickGameStart == 0 && _tickGameStarting == 0 && playing >= _minPlayers)
- { //Trigger the game start
- _arena.gameStart();
- }
- return true;
- }
- #region Events
- /// <summary>
- /// Called when a player enters the game
- /// </summary>
- [Scripts.Event("Player.Enter")]
- public void playerEnter(Player player)
- {
- }
- /// <summary>
- /// Called when a player leaves the game
- /// </summary>
- [Scripts.Event("Player.Leave")]
- public void playerLeave(Player player)
- {
- }
- /// <summary>
- /// Called when the game begins
- /// </summary>
- [Scripts.Event("Game.Start")]
- public bool gameStart()
- { //We've started!
- _tickGameStart = Environment.TickCount;
- _tickGameStarting = 0;
- return true;
- }
- /// <summary>
- /// Called when the game ends
- /// </summary>
- [Scripts.Event("Game.End")]
- public bool gameEnd()
- { //Game finished, perhaps start a new one
- _arena.sendArenaMessage("Game Over");
- _arena.breakdown(false);
- _tickGameStart = 0;
- _tickGameStarting = 0;
- _victoryTeam = null;
- return true;
- }
- /// <summary>
- /// Handles the spawn of a player
- /// </summary>
- [Scripts.Event("Player.Spawn")]
- public bool playerSpawn(Player player, bool bDeath)
- {
- return true;
- }
- /// <summary>
- /// Triggered when a player wants to unspec and join the game
- /// </summary>
- [Scripts.Event("Player.JoinGame")]
- public bool playerJoinGame(Player player)
- {
- return true;
- }
- /// <summary>
- /// Triggered when a player wants to spec and leave the game
- /// </summary>
- [Scripts.Event("Player.LeaveGame")]
- public bool playerLeaveGame(Player player)
- {
- return true;
- }
- #endregion
- }
- }
Add Comment
Please, Sign In to add comment