Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Zombie Grinder
- Copyright (C) 2012 Binary Phoenix
- This software is provided 'as-is' with no warrenty, either expressed
- Or implied. Any problems Or errors resulting from the use of this
- software is entirely at your risk. You assume all neccessary costs
- of repairs, servicing Or correction.
- This game mode is scripted by Sudz and is by no means an official
- game mode. Usage of this script is completely at your own risk.
- */
- // ------------------------------------------------------------
- // Game Mode Properties.
- // ------------------------------------------------------------
- var Name = "Gun Game Wave";
- var Description = "Hold out as long as you can with a given weapon!";
- // ------------------------------------------------------------
- // Resources
- // ------------------------------------------------------------
- var RoundStartSound = LoadSound("pak::Bin\\Audio\\SFX\\HUD\\round_start.wav", 0);
- var RoundEndSound = LoadSound("pak::Bin\\Audio\\SFX\\HUD\\round_end.wav", 0);
- // ------------------------------------------------------------
- // Variables!
- // ------------------------------------------------------------
- const WAVE_COUNTER_ALPHA_INCREMENT = 0.1;
- const START_DIFFICULTY_CURVE = 1.0;
- const DIFFICULTY_CURVE_INCREMENT = 0.35;
- const START_MAXIMUM_ZOMBIES_AT_ONCE = 5;
- const TOTAL_MAXIMUM_ZOMBIES_AT_ONCE = 30;
- const START_MAXIMUM_FODDER_ZOMBIES_AT_ONCE = 5;
- const TOTAL_MAXIMUM_FODDER_ZOMBIES_AT_ONCE = 20;
- const ZOMBIES_PER_ROUND = 10;
- const HALF_TIME_DURATION_MIN = 5000;
- const HALF_TIME_DURATION = 10000;
- // Network syncronized variables.
- var sync WaveInHalfTime;
- var sync WaveIndex = 0;
- // Zombie spawning variables.
- var sync WaveZombiesRemainingSynced;
- var sync WaveZombiesLeftToSpawn;
- var WaveDifficultyCurve;
- var WaveMaximumZombies;
- var WaveMaximumFodderZombies;
- // Half-time variables.
- var WaveHalfTimer;
- var WaveCounterAlpha;
- var OldWaveInHalfTime;
- var WaveHalfTimeDuration;
- var originalGroundSpawnState = -1;
- var originalFodderSpawnState = -1;
- // ------------------------------------------------------------
- // This function updates the difficulty curve and sets
- // when zombies should be spawning or not!
- // ------------------------------------------------------------
- //This is to ensure players get a random weapon per wave
- var MAX_WEAPON_INDEX = 14;
- function GetWeaponName(index)
- {
- var weaponname = "UNKNOWN";
- switch (index)
- {
- case 0: weaponname = "Baseball Bat";
- case 1: weaponname = "Double Barrel Shotgun";
- case 2: weaponname = "Magnum";
- case 3: weaponname = "Grenade Launcher";
- case 4: weaponname = "RPC";
- case 5: weaponname = "Scatter Gun";
- case 6: weaponname = "Shotgun";
- case 7: weaponname = "Sticky Launcher";
- case 8: weaponname = "Fight Saber";
- case 9: weaponname = "AK47";
- case 10: weaponname = "Spaz";
- case 11: weaponname = "Assault Rifle";
- case 12: weaponname = "Flamethrower";
- case 13: weaponname = "Laser Cannon";
- //case 14: weaponname = "Flare Gun";
- //case 15: weaponname = "Freeze Ray";
- //case 16: weaponname = "Rocket Launcher";
- default: weaponname = "Uzi";
- }
- return weaponname;
- }
- //Removes Client weapon and replaces it with a new one
- function ReplaceClientWeapon()
- {
- var client;
- var i;
- var weapon_name = GetWeaponName(Rand(0, MAX_WEAPON_INDEX)); //Gives the player a weapon name
- for (i = 0; i < GetClientCount(); i++)
- {
- client = GetClientByIndex(i); //Grabs Client info
- SetClientStartingWeapon(client, weapon_name); //Ensures that players spawn with weapon name
- RemoveClientWeapons(client); //Removes all weapons from the players
- AddClientWeapon(client, weapon_name); //Adds random weapon into players system
- }
- }
- function UpdateWave()
- {
- var slowCurve = START_DIFFICULTY_CURVE + ((WaveDifficultyCurve - START_DIFFICULTY_CURVE) * 0.5);
- var halfTimeCurve = slowCurve / 20.0;
- WaveDifficultyCurve = START_DIFFICULTY_CURVE + (WaveIndex * DIFFICULTY_CURVE_INCREMENT);
- //WaveMaximumZombies = Min(TOTAL_MAXIMUM_ZOMBIES_AT_ONCE, START_MAXIMUM_ZOMBIES_AT_ONCE * slowCurve);
- //WaveMaximumFodderZombies = Min(TOTAL_MAXIMUM_FODDER_ZOMBIES_AT_ONCE, START_MAXIMUM_FODDER_ZOMBIES_AT_ONCE * slowCurve);
- WaveHalfTimeDuration = Max(HALF_TIME_DURATION_MIN , HALF_TIME_DURATION - (HALF_TIME_DURATION * halfTimeCurve));
- if (IsServer())
- {
- //WaveZombiesRemaining = int(ZOMBIES_PER_ROUND * WaveDifficultyCurve);
- WaveZombiesRemainingSynced = int(ZOMBIES_PER_ROUND * WaveDifficultyCurve);//int(WaveZombiesRemaining);
- WaveZombiesLeftToSpawn = WaveZombiesRemainingSynced;
- SetDifficultyCurve (WaveDifficultyCurve);
- UpdateSpawning();
- }
- if (!IsServer())
- {
- if (WaveInHalfTime == true)
- {
- if (WaveHalfTimer == 0)
- {
- WaveHalfTimer = Millisecs() + WaveHalfTimeDuration;
- }
- var timeRemaining = int((WaveHalfTimer - Millisecs()) / 1000);
- if (WaveIndex == 0)
- {
- SetObjectiveHUDText ("Starting in " + timeRemaining, WaveCounterAlpha);
- }
- else
- {
- SetObjectiveHUDText ("Next wave in " + timeRemaining, WaveCounterAlpha);
- }
- }
- else
- {
- WaveHalfTimer = 0;
- var num = int(max(float(CountAliveZombies()), float(WaveZombiesRemainingSynced)));
- SetObjectiveHUDText ("Wave " + int(WaveIndex) + " - " + num + " Remaining", WaveCounterAlpha);
- }
- }
- StoreMaxStat("map::"+GetMapName()+"::max_wave", WaveIndex);
- StoreMaxStat("game::max_wave", WaveIndex);
- }
- function UpdateSpawning()
- {
- if (originalGroundSpawnState == -1)
- {
- originalGroundSpawnState = GetSpawnGroundZombies();
- }
- if (originalFodderSpawnState == -1)
- {
- originalFodderSpawnState = GetSpawnFodderZombies();
- }
- if (originalFodderSpawnState != false)
- {
- SetSpawnFodderZombies(true);
- }
- if (WaveInHalfTime == false && (WaveZombiesLeftToSpawn > 0 || (CountAliveZombies() <= 0 && WaveZombiesRemainingSynced > 0)))
- {
- SetSpawnZombies(true);
- if (originalGroundSpawnState != false)
- {
- SetSpawnGroundZombies(true);
- }
- }
- else
- {
- if (originalGroundSpawnState != false)
- {
- SetSpawnGroundZombies(false);
- }
- SetSpawnZombies(false);
- }
- }
- // ------------------------------------------------------------
- // Events to track when zombies are spawned, killed etc
- // ------------------------------------------------------------
- event OnZombieSpawned(zombie)
- {
- if (IsServer() && GetType(zombie) != "TFodderZombie")
- {
- WaveZombiesLeftToSpawn -= 1;
- UpdateSpawning();
- }
- }
- event OnZombieKilled(weapon, zombie, headshot)
- {
- if (IsServer() && GetType(zombie) != "TFodderZombie")
- {
- WaveZombiesRemainingSynced -= 1;
- UpdateSpawning();
- }
- }
- event OnDisposeZombie(zombie)
- {
- if (IsServer() && GetType(zombie) != "TFodderZombie" && GetZombieHealth(zombie) > 0)
- {
- //WaveZombiesRemainingSynced += 1;
- WaveZombiesLeftToSpawn += 1;
- UpdateSpawning();
- }
- }
- /*
- event OnZombieSpawned(zombie)
- {
- if (IsServer() && GetType(zombie) != "TFodderZombie")
- {
- WaveZombiesRemaining -= 1;
- UpdateSpawning();
- }
- }
- event OnDisposeOffscreenZombie(zombie)
- {
- if (IsServer() && GetType(zombie) != "TFodderZombie")
- {
- WaveZombiesRemaining += 1;
- UpdateSpawning();
- }
- }
- event OnZombieDisposed(zombie)
- {
- if (IsServer() && GetType(zombie) != "TFodderZombie")
- {
- WaveZombiesRemaining -= 1;
- UpdateSpawning();
- }
- }
- */
- // ------------------------------------------------------------
- // Start of game mode. Disable all zombies until our waves start!
- // ------------------------------------------------------------
- event OnInit()
- {
- // Start in half time.
- WaveIndex = 0;
- SetProfileSlotEnabled (1, false); // Disable starting weapons.
- WaveInHalfTime = true;
- OldWaveInHalfTime = true;
- WaveHalfTimer = Millisecs() + HALF_TIME_DURATION;
- SetAllowRevives(true);
- SetAlwaysRespawn(false);
- SetLooseWeaponsAfterFirstSpawn(true);
- DisableRoomGrid();
- UpdateWave();
- SetStartingWeapon(GetWeaponName(Rand(0, MAX_WEAPON_INDEX)));
- }
- // Counts how many zombies are alive.
- function CountAliveZombies()
- {
- var zombieCount = 0;
- var entityList = GetDerivedEntities("TZombie");
- for (var i = 0; i < CountList(entityList); i++)
- {
- var e = ListAtIndex(entityList, i);
- if (GetType(e) != "TFodderZombie")
- zombieCount += 1;
- }
- return zombieCount;
- }
- // ------------------------------------------------------------
- // Update wave each frame :3
- // ------------------------------------------------------------
- event OnTick()
- {
- // Server is responsible for sorting out the spawning of all the zombies.
- if (IsServer())
- {
- if (WaveInHalfTime == false)
- {
- // Start of half-time?
- if (CountAliveZombies() <= 0 && WaveZombiesRemainingSynced <= 0 && WaveHalfTimer < Millisecs())
- {
- WaveHalfTimer = Millisecs() + WaveHalfTimeDuration;
- WaveInHalfTime = true;
- UpdateWave();
- // Respawn all the players!
- for (var i = 0; i < GetClientCount(); i++)
- {
- var client = GetClientByIndex(i);
- if (IsClientDead(client))
- {
- RespawnClient(client);
- }
- }
- ReplaceClientWeapon(); //Changes the Client's weapon
- }
- }
- // If we are in half-time, just count down until we are not.
- else
- {
- if (Millisecs() > WaveHalfTimer)
- {
- WaveIndex += 1;
- WaveInHalfTime = false;
- UpdateWave();
- }
- }
- // Make sure we don't get stuck, though this should never happen D:
- if (WaveZombiesLeftToSpawn + CountAliveZombies() < WaveZombiesRemainingSynced)
- {
- WaveZombiesLeftToSpawn = WaveZombiesRemainingSynced - CountAliveZombies();
- }
- }
- // Client just updates the pretty wave counter, thats about it lol.
- else
- {
- if (WaveInHalfTime == false)
- {
- WaveCounterAlpha = Min(WaveCounterAlpha + WAVE_COUNTER_ALPHA_INCREMENT, 1.0);
- if (OldWaveInHalfTime == true)
- {
- PlaySound(RoundStartSound);
- InvokeScriptEvent("OnWaveStart", WaveIndex);
- }
- }
- else
- {
- WaveCounterAlpha = Max(WaveCounterAlpha - WAVE_COUNTER_ALPHA_INCREMENT, 0.0);
- if (OldWaveInHalfTime == false)
- {
- PlaySound(RoundEndSound);
- }
- }
- UpdateWave();
- OldWaveInHalfTime = WaveInHalfTime;
- }
- // Everyone dead.
- var anyoneAlive = false;
- for (i = 0; i < GetClientCount(); i++)
- {
- client = GetClientByIndex(i);
- if (IsClientDead(client))
- {
- anyoneAlive = true;
- }
- }
- if (anyoneAlive == false)
- {
- SetGameOver(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement