Advertisement
Sudz

Gun Game Wave

Mar 10th, 2013
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.36 KB | None | 0 0
  1. /*
  2.  
  3. Zombie Grinder
  4. Copyright (C) 2012 Binary Phoenix
  5.  
  6. This software is provided 'as-is' with no warrenty, either expressed
  7. Or implied. Any problems Or errors resulting from the use of this
  8. software is entirely at your risk. You assume all neccessary costs
  9. of repairs, servicing Or correction.
  10.  
  11. This game mode is scripted by Sudz and is by no means an official
  12. game mode. Usage of this script is completely at your own risk.
  13.  
  14. */
  15.  
  16. // ------------------------------------------------------------
  17. // Game Mode Properties.
  18. // ------------------------------------------------------------
  19. var Name = "Gun Game Wave";
  20. var Description = "Hold out as long as you can with a given weapon!";
  21.  
  22. // ------------------------------------------------------------
  23. // Resources
  24. // ------------------------------------------------------------
  25. var RoundStartSound = LoadSound("pak::Bin\\Audio\\SFX\\HUD\\round_start.wav", 0);
  26. var RoundEndSound = LoadSound("pak::Bin\\Audio\\SFX\\HUD\\round_end.wav", 0);
  27.  
  28. // ------------------------------------------------------------
  29. // Variables!
  30. // ------------------------------------------------------------
  31. const WAVE_COUNTER_ALPHA_INCREMENT = 0.1;
  32.  
  33. const START_DIFFICULTY_CURVE = 1.0;
  34. const DIFFICULTY_CURVE_INCREMENT = 0.35;
  35.  
  36. const START_MAXIMUM_ZOMBIES_AT_ONCE = 5;
  37. const TOTAL_MAXIMUM_ZOMBIES_AT_ONCE = 30;
  38.  
  39. const START_MAXIMUM_FODDER_ZOMBIES_AT_ONCE = 5;
  40. const TOTAL_MAXIMUM_FODDER_ZOMBIES_AT_ONCE = 20;
  41.  
  42. const ZOMBIES_PER_ROUND = 10;
  43.  
  44. const HALF_TIME_DURATION_MIN = 5000;
  45. const HALF_TIME_DURATION = 10000;
  46.  
  47. // Network syncronized variables.
  48. var sync WaveInHalfTime;
  49. var sync WaveIndex = 0;
  50.  
  51.  
  52. // Zombie spawning variables.
  53. var sync WaveZombiesRemainingSynced;
  54. var sync WaveZombiesLeftToSpawn;
  55. var WaveDifficultyCurve;
  56.  
  57. var WaveMaximumZombies;
  58. var WaveMaximumFodderZombies;
  59.  
  60. // Half-time variables.
  61. var WaveHalfTimer;
  62. var WaveCounterAlpha;
  63. var OldWaveInHalfTime;
  64. var WaveHalfTimeDuration;
  65.  
  66. var originalGroundSpawnState = -1;
  67. var originalFodderSpawnState = -1;
  68.  
  69. // ------------------------------------------------------------
  70. // This function updates the difficulty curve and sets
  71. // when zombies should be spawning or not!
  72. // ------------------------------------------------------------
  73.  
  74. //This is to ensure players get a random weapon per wave
  75. var MAX_WEAPON_INDEX = 14;
  76. function GetWeaponName(index)
  77. {
  78. var weaponname = "UNKNOWN";
  79. switch (index)
  80. {
  81. case 0: weaponname = "Baseball Bat";
  82. case 1: weaponname = "Double Barrel Shotgun";
  83. case 2: weaponname = "Magnum";
  84. case 3: weaponname = "Grenade Launcher";
  85. case 4: weaponname = "RPC";
  86. case 5: weaponname = "Scatter Gun";
  87. case 6: weaponname = "Shotgun";
  88. case 7: weaponname = "Sticky Launcher";
  89. case 8: weaponname = "Fight Saber";
  90. case 9: weaponname = "AK47";
  91. case 10: weaponname = "Spaz";
  92. case 11: weaponname = "Assault Rifle";
  93. case 12: weaponname = "Flamethrower";
  94. case 13: weaponname = "Laser Cannon";
  95. //case 14: weaponname = "Flare Gun";
  96. //case 15: weaponname = "Freeze Ray";
  97. //case 16: weaponname = "Rocket Launcher";
  98. default: weaponname = "Uzi";
  99. }
  100. return weaponname;
  101. }
  102.  
  103. //Removes Client weapon and replaces it with a new one
  104. function ReplaceClientWeapon()
  105. {
  106. var client;
  107. var i;
  108. var weapon_name = GetWeaponName(Rand(0, MAX_WEAPON_INDEX)); //Gives the player a weapon name
  109. for (i = 0; i < GetClientCount(); i++)
  110. {
  111. client = GetClientByIndex(i); //Grabs Client info
  112. SetClientStartingWeapon(client, weapon_name); //Ensures that players spawn with weapon name
  113. RemoveClientWeapons(client); //Removes all weapons from the players
  114. AddClientWeapon(client, weapon_name); //Adds random weapon into players system
  115. }
  116. }
  117.  
  118.  
  119. function UpdateWave()
  120. {
  121. var slowCurve = START_DIFFICULTY_CURVE + ((WaveDifficultyCurve - START_DIFFICULTY_CURVE) * 0.5);
  122. var halfTimeCurve = slowCurve / 20.0;
  123.  
  124. WaveDifficultyCurve = START_DIFFICULTY_CURVE + (WaveIndex * DIFFICULTY_CURVE_INCREMENT);
  125. //WaveMaximumZombies = Min(TOTAL_MAXIMUM_ZOMBIES_AT_ONCE, START_MAXIMUM_ZOMBIES_AT_ONCE * slowCurve);
  126. //WaveMaximumFodderZombies = Min(TOTAL_MAXIMUM_FODDER_ZOMBIES_AT_ONCE, START_MAXIMUM_FODDER_ZOMBIES_AT_ONCE * slowCurve);
  127. WaveHalfTimeDuration = Max(HALF_TIME_DURATION_MIN , HALF_TIME_DURATION - (HALF_TIME_DURATION * halfTimeCurve));
  128.  
  129. if (IsServer())
  130. {
  131. //WaveZombiesRemaining = int(ZOMBIES_PER_ROUND * WaveDifficultyCurve);
  132. WaveZombiesRemainingSynced = int(ZOMBIES_PER_ROUND * WaveDifficultyCurve);//int(WaveZombiesRemaining);
  133. WaveZombiesLeftToSpawn = WaveZombiesRemainingSynced;
  134.  
  135. SetDifficultyCurve (WaveDifficultyCurve);
  136. UpdateSpawning();
  137. }
  138.  
  139. if (!IsServer())
  140. {
  141. if (WaveInHalfTime == true)
  142. {
  143. if (WaveHalfTimer == 0)
  144. {
  145. WaveHalfTimer = Millisecs() + WaveHalfTimeDuration;
  146. }
  147.  
  148. var timeRemaining = int((WaveHalfTimer - Millisecs()) / 1000);
  149. if (WaveIndex == 0)
  150. {
  151. SetObjectiveHUDText ("Starting in " + timeRemaining, WaveCounterAlpha);
  152. }
  153. else
  154. {
  155. SetObjectiveHUDText ("Next wave in " + timeRemaining, WaveCounterAlpha);
  156. }
  157. }
  158. else
  159. {
  160. WaveHalfTimer = 0;
  161.  
  162. var num = int(max(float(CountAliveZombies()), float(WaveZombiesRemainingSynced)));
  163. SetObjectiveHUDText ("Wave " + int(WaveIndex) + " - " + num + " Remaining", WaveCounterAlpha);
  164. }
  165. }
  166.  
  167. StoreMaxStat("map::"+GetMapName()+"::max_wave", WaveIndex);
  168. StoreMaxStat("game::max_wave", WaveIndex);
  169. }
  170.  
  171. function UpdateSpawning()
  172. {
  173. if (originalGroundSpawnState == -1)
  174. {
  175. originalGroundSpawnState = GetSpawnGroundZombies();
  176. }
  177. if (originalFodderSpawnState == -1)
  178. {
  179. originalFodderSpawnState = GetSpawnFodderZombies();
  180. }
  181.  
  182. if (originalFodderSpawnState != false)
  183. {
  184. SetSpawnFodderZombies(true);
  185. }
  186.  
  187. if (WaveInHalfTime == false && (WaveZombiesLeftToSpawn > 0 || (CountAliveZombies() <= 0 && WaveZombiesRemainingSynced > 0)))
  188. {
  189. SetSpawnZombies(true);
  190. if (originalGroundSpawnState != false)
  191. {
  192. SetSpawnGroundZombies(true);
  193. }
  194. }
  195. else
  196. {
  197. if (originalGroundSpawnState != false)
  198. {
  199. SetSpawnGroundZombies(false);
  200. }
  201. SetSpawnZombies(false);
  202. }
  203. }
  204.  
  205. // ------------------------------------------------------------
  206. // Events to track when zombies are spawned, killed etc
  207. // ------------------------------------------------------------
  208. event OnZombieSpawned(zombie)
  209. {
  210. if (IsServer() && GetType(zombie) != "TFodderZombie")
  211. {
  212. WaveZombiesLeftToSpawn -= 1;
  213. UpdateSpawning();
  214. }
  215. }
  216.  
  217. event OnZombieKilled(weapon, zombie, headshot)
  218. {
  219. if (IsServer() && GetType(zombie) != "TFodderZombie")
  220. {
  221. WaveZombiesRemainingSynced -= 1;
  222. UpdateSpawning();
  223. }
  224. }
  225.  
  226. event OnDisposeZombie(zombie)
  227. {
  228. if (IsServer() && GetType(zombie) != "TFodderZombie" && GetZombieHealth(zombie) > 0)
  229. {
  230. //WaveZombiesRemainingSynced += 1;
  231. WaveZombiesLeftToSpawn += 1;
  232. UpdateSpawning();
  233. }
  234. }
  235.  
  236. /*
  237. event OnZombieSpawned(zombie)
  238. {
  239. if (IsServer() && GetType(zombie) != "TFodderZombie")
  240. {
  241. WaveZombiesRemaining -= 1;
  242. UpdateSpawning();
  243. }
  244. }
  245. event OnDisposeOffscreenZombie(zombie)
  246. {
  247. if (IsServer() && GetType(zombie) != "TFodderZombie")
  248. {
  249. WaveZombiesRemaining += 1;
  250. UpdateSpawning();
  251. }
  252. }
  253. event OnZombieDisposed(zombie)
  254. {
  255. if (IsServer() && GetType(zombie) != "TFodderZombie")
  256. {
  257. WaveZombiesRemaining -= 1;
  258. UpdateSpawning();
  259. }
  260. }
  261. */
  262.  
  263.  
  264. // ------------------------------------------------------------
  265. // Start of game mode. Disable all zombies until our waves start!
  266. // ------------------------------------------------------------
  267. event OnInit()
  268. {
  269. // Start in half time.
  270. WaveIndex = 0;
  271. SetProfileSlotEnabled (1, false); // Disable starting weapons.
  272. WaveInHalfTime = true;
  273. OldWaveInHalfTime = true;
  274. WaveHalfTimer = Millisecs() + HALF_TIME_DURATION;
  275.  
  276. SetAllowRevives(true);
  277. SetAlwaysRespawn(false);
  278. SetLooseWeaponsAfterFirstSpawn(true);
  279. DisableRoomGrid();
  280.  
  281. UpdateWave();
  282. SetStartingWeapon(GetWeaponName(Rand(0, MAX_WEAPON_INDEX)));
  283. }
  284.  
  285. // Counts how many zombies are alive.
  286. function CountAliveZombies()
  287. {
  288. var zombieCount = 0;
  289.  
  290. var entityList = GetDerivedEntities("TZombie");
  291. for (var i = 0; i < CountList(entityList); i++)
  292. {
  293. var e = ListAtIndex(entityList, i);
  294. if (GetType(e) != "TFodderZombie")
  295. zombieCount += 1;
  296. }
  297.  
  298. return zombieCount;
  299. }
  300.  
  301.  
  302. // ------------------------------------------------------------
  303. // Update wave each frame :3
  304. // ------------------------------------------------------------
  305. event OnTick()
  306. {
  307. // Server is responsible for sorting out the spawning of all the zombies.
  308. if (IsServer())
  309. {
  310. if (WaveInHalfTime == false)
  311. {
  312. // Start of half-time?
  313. if (CountAliveZombies() <= 0 && WaveZombiesRemainingSynced <= 0 && WaveHalfTimer < Millisecs())
  314. {
  315. WaveHalfTimer = Millisecs() + WaveHalfTimeDuration;
  316. WaveInHalfTime = true;
  317.  
  318. UpdateWave();
  319.  
  320. // Respawn all the players!
  321. for (var i = 0; i < GetClientCount(); i++)
  322. {
  323. var client = GetClientByIndex(i);
  324. if (IsClientDead(client))
  325. {
  326. RespawnClient(client);
  327. }
  328. }
  329. ReplaceClientWeapon(); //Changes the Client's weapon
  330. }
  331. }
  332.  
  333. // If we are in half-time, just count down until we are not.
  334. else
  335. {
  336. if (Millisecs() > WaveHalfTimer)
  337. {
  338. WaveIndex += 1;
  339. WaveInHalfTime = false;
  340.  
  341. UpdateWave();
  342. }
  343. }
  344.  
  345. // Make sure we don't get stuck, though this should never happen D:
  346. if (WaveZombiesLeftToSpawn + CountAliveZombies() < WaveZombiesRemainingSynced)
  347. {
  348. WaveZombiesLeftToSpawn = WaveZombiesRemainingSynced - CountAliveZombies();
  349. }
  350. }
  351.  
  352. // Client just updates the pretty wave counter, thats about it lol.
  353. else
  354. {
  355. if (WaveInHalfTime == false)
  356. {
  357. WaveCounterAlpha = Min(WaveCounterAlpha + WAVE_COUNTER_ALPHA_INCREMENT, 1.0);
  358. if (OldWaveInHalfTime == true)
  359. {
  360. PlaySound(RoundStartSound);
  361. InvokeScriptEvent("OnWaveStart", WaveIndex);
  362. }
  363. }
  364. else
  365. {
  366. WaveCounterAlpha = Max(WaveCounterAlpha - WAVE_COUNTER_ALPHA_INCREMENT, 0.0);
  367. if (OldWaveInHalfTime == false)
  368. {
  369. PlaySound(RoundEndSound);
  370. }
  371. }
  372.  
  373. UpdateWave();
  374.  
  375. OldWaveInHalfTime = WaveInHalfTime;
  376. }
  377.  
  378. // Everyone dead.
  379. var anyoneAlive = false;
  380. for (i = 0; i < GetClientCount(); i++)
  381. {
  382. client = GetClientByIndex(i);
  383. if (IsClientDead(client))
  384. {
  385. anyoneAlive = true;
  386. }
  387. }
  388.  
  389. if (anyoneAlive == false)
  390. {
  391. SetGameOver(true);
  392. }
  393. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement