Custom Maps & Logic
  • Custom Map Tutorial
    • Custom Map Introduction
    • Your first map
    • Map Navigation
    • Object Selection
    • Object Positioning
    • Object Attributes
    • Shortcuts and Macros
    • Editor Settings
    • Built-in Components Common Errors
    • Map Performance
    • Custom Assets
      • Your first Asset Bundle
      • Asset Bundles in Map Editor
      • Asset Bundles in Game
      • Adding to Asset Bundles
      • Asset Bundle naming
  • Custom Logic Tutorial
    • Custom Logic Introduction
    • Your first script
    • Variables
    • Types
    • Variable Inspector
    • Expressions
    • Conditionals
    • Loops
    • Functions
    • Coroutines
    • Classes
    • Static Classes
    • Components
    • Extensions
    • Cutscenes
    • Static Objects
    • Networking
    • Commenting
  • Reference
    • Static Classes
      • Game
      • Network
      • Map
      • UI
      • Time
      • Convert
      • String
      • Input
      • Math
      • Random
      • Cutscene
      • Camera
      • RoomData
      • PersistentData
      • Json
      • Physics
    • Objects
      • Component
      • Object
      • Character
      • Human
      • Titan
      • Shifter
      • MapObject
      • Transform
      • Player
      • NetworkView
      • Color
      • Vector3
      • Quaternion
      • Dict
      • List
      • Range
      • LineCastHitResult
      • MapTargetable
      • Random
    • Callbacks
      • Main
      • Components
  • Examples
    • Gamemodes
      • Survive
      • Waves
      • Endless
      • Racing
      • Blade PVP
      • Thunderspear PVP
      • Titan Explode
      • Cranked
      • More Examples
    • Components
      • SupplyStation
      • Daylight
      • PointLight
      • Rigidbody
      • NavMeshObstacle
      • Cannon
      • Dummy
      • Wagon
      • Tag
      • KillRegion
      • DamageRegion
      • MovePingPong
      • RacingCheckpointRegion
      • RacingFinishRegion
      • TeleportRegion
      • Animal
      • SignalMover
      • SignalSender
      • More Examples
Powered by GitBook
On this page
  1. Examples
  2. Gamemodes

Cranked

The cranked gamemode has players die after a certain time limit, but killing titans increases the time remaining.

Created by Player2.

class Main
{   
    Description = "Survive as long as possible under a time limit. Killing titans adds time. Created by p2.";
    MaxTitans = 15;
    TitanSpawnEvery = 3.0;
    StartTimeLimit = 45.0;
    TitanAddTime = 6.0;
    _CrankedTimeDangerZone = 10.0;
    _hasSpawned = false;
    _hasMyPlayerSpawned = false;
    _spawnTimeLeft = 0.0;
    _startTime = -1.0;
    _endTime = -1.0;

    function OnGameStart()
    {
        if (Network.IsMasterClient)
        {
            Game.SpawnTitans("Default", self.MaxTitans);
        }
    }

    function OnCharacterDie(victim, killer, killerName)
    {
        if (victim.Type == "Titan" && killer.IsMainCharacter)
        {
            self.StartTimeLimit = self.StartTimeLimit + self.TitanAddTime;
        }
        if (victim.IsMainCharacter)
        {
            self._endTime = Time.GameTime;
            self.StartTimeLimit = 0.0;
            self._hasMyPlayerSpawned = false;
        }
    }

    function OnPlayerSpawn(player, character)
    {
        if (player == Network.MyPlayer)
        {
            self._startTime = Time.GameTime;
            self._hasMyPlayerSpawned = true;
        }
    }

    function OutOfTime()
    {
        character = Network.MyPlayer.Character;
        if (character != null && (character.Type == "Human" || character.Type == "Shifter"))
        {
            character.GetKilled("Out of time");
            position = character.Position;
            if (character.Type == "Shifter")
            {
                position = character.NapePosition;
            }
            Game.SpawnEffect("ThunderspearExplode", position, Vector3.Zero, 50.0, Color(255, 255, 255, 255), "Air");
        }
    }

    function OnTick()
    {
        titans = Game.Titans.Count;
        if (!Game.IsEnding && Network.IsMasterClient)
        {
            humans = Game.Humans.Count;
            playerShifters = Game.PlayerShifters.Count;
            if (humans > 0 || playerShifters > 0)
            {
                self._hasSpawned = true;
            }
            if (titans < self.MaxTitans)
            {
                self._spawnTimeLeft = self._spawnTimeLeft - Time.TickTime;
                if (self._spawnTimeLeft <= 0.0)
                {
                    Game.SpawnTitans("Default", 1);
                    self._spawnTimeLeft = self.TitanSpawnEvery;
                }
            }
            else
            {
                self._spawnTimeLeft = self.TitanSpawnEvery;
            }
            if (humans == 0 && playerShifters == 0 && self._hasSpawned)
            {
                UI.SetLabelAll("MiddleCenter", "Humanity failed!");
                Game.End(10.0);
                return;
            }
        }
        if (!self._hasMyPlayerSpawned)
        {
            return;
        }

        self.StartTimeLimit = self.StartTimeLimit - Time.TickTime;
        if (Game.IsEnding)
        {
            self.StartTimeLimit = 0.0;
        }
        if (self.StartTimeLimit <= self._CrankedTimeDangerZone)
        {
            CrankedTimeDisplay = "Cranked Time: <color=#ff0000>" + String.FormatFloat(self.StartTimeLimit, 2) + "</color>"; 
        }
        else
        {
            CrankedTimeDisplay = "Cranked Time: " + Convert.ToString(Convert.ToInt(self.StartTimeLimit)); 
        }
        if (self.StartTimeLimit <= 0)
        {
            self.OutOfTime();
            CrankedTimeDisplay = "Cranked Time: <color=#ff0000>0.00!</color>";
            if (self._endTime != -1.0 && self._startTime != -1.0)
            {
                self._startTime = Math.Min(self._startTime, self._endTime);
                surviveTime = self._endTime - self._startTime;
                CrankedTimeDisplay = CrankedTimeDisplay + String.Newline + "You survived <color=#ffd700>" + String.FormatFloat(surviveTime, 2) + "</color> seconds";
            }
        }
        UI.SetLabel("TopCenter", "Titans Left: " + Convert.ToString(titans) + String.Newline + CrankedTimeDisplay);
    }
}
PreviousTitan ExplodeNextMore Examples

Last updated 9 months ago