Advertisement
jonas13362

events.lua

Jan 26th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.46 KB | None | 0 0
  1. /*---------------------------------------------------------
  2. Variables
  3. ---------------------------------------------------------*/
  4. local timeLeft = 10
  5. local timeLeft2 = 10
  6. local stormOn = false
  7. local zombieOn = false
  8. local maxZombie = 10
  9.  
  10. /*---------------------------------------------------------
  11. Zombie
  12. ---------------------------------------------------------*/
  13. local ZombieStart, ZombieEnd
  14. local function ControlZombie()
  15. timeLeft2 = timeLeft2 - 1
  16.  
  17. if timeLeft2 < 1 then
  18. if zombieOn then
  19. timeLeft2 = math.random(300,500)
  20. zombieOn = false
  21. timer.Stop("start2")
  22. ZombieEnd()
  23. else
  24. timeLeft2 = math.random(150,300)
  25. zombieOn = true
  26. timer.Start("start2")
  27. DB.RetrieveZombies(function()
  28. ZombieStart()
  29. end)
  30. end
  31. end
  32. end
  33.  
  34. ZombieStart = function()
  35. for k, v in pairs(player.GetAll()) do
  36. if v:Alive() then
  37. v:PrintMessage(HUD_PRINTCENTER, LANGUAGE.zombie_approaching)
  38. v:PrintMessage(HUD_PRINTTALK, LANGUAGE.zombie_approaching)
  39. end
  40. end
  41. end
  42.  
  43. ZombieEnd = function()
  44. for k, v in pairs(player.GetAll()) do
  45. if v:Alive() then
  46. v:PrintMessage(HUD_PRINTCENTER, LANGUAGE.zombie_leaving)
  47. v:PrintMessage(HUD_PRINTTALK, LANGUAGE.zombie_leaving)
  48. end
  49. end
  50. end
  51.  
  52. local function LoadTable(ply)
  53. ply:SetSelfDarkRPVar("numPoints", table.getn(zombieSpawns))
  54.  
  55. for k, v in pairs(zombieSpawns) do
  56. ply:SetSelfDarkRPVar("zPoints" .. k, v)
  57. end
  58. end
  59.  
  60. local function ReMoveZombie(ply, index)
  61. if ply:HasPriv("rp_commands") then
  62. if not index or zombieSpawns[tonumber(index)] == nil then
  63. GAMEMODE:Notify(ply, 1, 4, string.format(LANGUAGE.zombie_spawn_not_exist, tostring(index)))
  64. else
  65. DB.RetrieveZombies(function()
  66. GAMEMODE:Notify(ply, 0, 4, LANGUAGE.zombie_spawn_removed)
  67. table.remove(zombieSpawns, index)
  68. DB.StoreZombies()
  69. if ply:getDarkRPVar("zombieToggle") then
  70. LoadTable(ply)
  71. end
  72. end)
  73. end
  74. else
  75. GAMEMODE:Notify(ply, 1, 4, string.format(LANGUAGE.need_admin, "/removezombie"))
  76. end
  77. return ""
  78. end
  79. AddChatCommand("/removezombie", ReMoveZombie)
  80.  
  81. local function AddZombie(ply)
  82. if ply:HasPriv("rp_commands") then
  83. DB.RetrieveZombies(function()
  84. table.insert(zombieSpawns, ply:GetPos())
  85. DB.StoreZombies()
  86. if ply:getDarkRPVar("zombieToggle") then LoadTable(ply) end
  87. GAMEMODE:Notify(ply, 0, 4, LANGUAGE.zombie_spawn_added)
  88. end)
  89. else
  90. GAMEMODE:Notify(ply, 1, 6, string.format(LANGUAGE.need_admin, "/addzombie"))
  91. end
  92. return ""
  93. end
  94. AddChatCommand("/addzombie", AddZombie)
  95.  
  96. local function ToggleZombie(ply)
  97. if ply:HasPriv("rp_commands") then
  98. if not ply:getDarkRPVar("zombieToggle") then
  99. DB.RetrieveZombies(function()
  100. ply:SetSelfDarkRPVar("zombieToggle", true)
  101. LoadTable(ply)
  102. end)
  103. else
  104. ply:SetSelfDarkRPVar("zombieToggle", false)
  105. end
  106. else
  107. GAMEMODE:Notify(ply, 1, 6, LANGUAGE.string.format(LANGUAGE.need_admin, "/showzombie"))
  108. end
  109. return ""
  110. end
  111. AddChatCommand("/showzombie", ToggleZombie)
  112.  
  113. local function GetAliveZombie()
  114. local zombieCount = 0
  115.  
  116. local ZombieTypes = {"npc_zombie", "npc_fastzombie", "npc_antlion", "npc_headcrab_fast"}
  117. for _, Type in pairs(ZombieTypes) do
  118. zombieCount = zombieCount + #ents.FindByClass(Type)
  119. end
  120.  
  121. return zombieCount
  122. end
  123.  
  124. local function SpawnZombie()
  125. timer.Start("move")
  126. if GetAliveZombie() >= maxZombie then return end
  127. if table.getn(zombieSpawns) <= 0 then return end
  128.  
  129. local ZombieTypes = {"npc_zombie", "npc_fastzombie", "npc_antlion", "npc_headcrab_fast"}
  130. local zombieType = math.random(1, #ZombieTypes)
  131.  
  132. local Zombie = ents.Create(ZombieTypes[zombieType])
  133. Zombie.nodupe = true
  134. Zombie:Spawn()
  135. Zombie:Activate()
  136. Zombie:SetPos(DB.RetrieveRandomZombieSpawnPos())
  137. end
  138.  
  139. local function ZombieMax(ply, args)
  140. if ply:HasPriv("rp_commands") then
  141. if not tonumber(args) then
  142. GAMEMODE:Notify(ply, 1, 4, string.format(LANGUAGE.invalid_x, "argument", ""))
  143. return ""
  144. end
  145. maxZombie = tonumber(args)
  146. GAMEMODE:Notify(ply, 0, 4, string.format(LANGUAGE.zombie_maxset, args))
  147. end
  148.  
  149. return ""
  150. end
  151. AddChatCommand("/zombiemax", ZombieMax)
  152. AddChatCommand("/maxzombie", ZombieMax)
  153. AddChatCommand("/maxzombies", ZombieMax)
  154.  
  155. local function StartZombie(ply)
  156. if ply:HasPriv("rp_commands") then
  157. timer.Start("zombieControl")
  158. GAMEMODE:Notify(ply, 0, 4, LANGUAGE.zombie_enabled)
  159. end
  160. return ""
  161. end
  162. AddChatCommand("/enablezombie", StartZombie)
  163.  
  164. local function StopZombie(ply)
  165. if ply:HasPriv("rp_commands") then
  166. timer.Stop("zombieControl")
  167. zombieOn = false
  168. timer.Stop("start2")
  169. ZombieEnd()
  170. GAMEMODE:Notify(ply, 0, 4, LANGUAGE.zombie_disabled)
  171. end
  172. return ""
  173. end
  174. AddChatCommand("/disablezombie", StopZombie)
  175.  
  176. timer.Create("start2", 1, 0, SpawnZombie)
  177. timer.Create("zombieControl", 1, 0, ControlZombie)
  178. timer.Stop("start2")
  179. timer.Stop("zombieControl")
  180.  
  181. /*---------------------------------------------------------
  182. Meteor storm
  183. ---------------------------------------------------------*/
  184. local function StormStart()
  185. for k, v in pairs(player.GetAll()) do
  186. if v:Alive() then
  187. v:PrintMessage(HUD_PRINTCENTER, LANGUAGE.meteor_approaching)
  188. v:PrintMessage(HUD_PRINTTALK, LANGUAGE.meteor_approaching)
  189. end
  190. end
  191. end
  192.  
  193. local function StormEnd()
  194. for k, v in pairs(player.GetAll()) do
  195. if v:Alive() then
  196. v:PrintMessage(HUD_PRINTCENTER, LANGUAGE.meteor_passing)
  197. v:PrintMessage(HUD_PRINTTALK, LANGUAGE.meteor_passing)
  198. end
  199. end
  200. end
  201.  
  202. local function ControlStorm()
  203. timeLeft = timeLeft - 1
  204.  
  205. if timeLeft < 1 then
  206. if stormOn then
  207. timeLeft = math.random(300,500)
  208. stormOn = false
  209. timer.Stop("start")
  210. StormEnd()
  211. else
  212. timeLeft = math.random(60,90)
  213. stormOn = true
  214. timer.Start("start")
  215. StormStart()
  216. end
  217. end
  218. end
  219.  
  220. local function AttackEnt(ent)
  221. meteor = ents.Create("meteor")
  222. meteor.nodupe = true
  223. meteor:Spawn()
  224. meteor:SetMeteorTarget(ent)
  225. end
  226.  
  227. local function StartShower()
  228. timer.Adjust("start", math.random(.1,1), 0, StartShower)
  229. for k, v in pairs(player.GetAll()) do
  230. if math.random(0, 2) == 0 and v:Alive() then
  231. AttackEnt(v)
  232. end
  233. end
  234. end
  235.  
  236. local function StartStorm(ply)
  237. if ply:HasPriv("rp_commands") then
  238. timer.Start("stormControl")
  239. GAMEMODE:Notify(ply, 0, 4, LANGUAGE.meteor_enabled)
  240. end
  241. return ""
  242. end
  243. AddChatCommand("/enablestorm", StartStorm)
  244.  
  245. local function StopStorm(ply)
  246. if ply:HasPriv("rp_commands") then
  247. timer.Stop("stormControl")
  248. stormOn = false
  249. timer.Stop("start")
  250. StormEnd()
  251. GAMEMODE:Notify(ply, 0, 4, LANGUAGE.meteor_disabled)
  252. end
  253. return ""
  254. end
  255. AddChatCommand("/disablestorm", StopStorm)
  256.  
  257. timer.Create("start", 1, 0, StartShower)
  258. timer.Create("stormControl", 1, 0, ControlStorm)
  259.  
  260. timer.Stop("start")
  261. timer.Stop("stormControl")
  262.  
  263. /*---------------------------------------------------------
  264. Earthquake
  265. ---------------------------------------------------------*/
  266. local lastmagnitudes = {} -- The magnitudes of the last tremors
  267.  
  268. local tremor = ents.Create("env_physexplosion")
  269. tremor:SetPos(Vector(0,0,0))
  270. tremor:SetKeyValue("radius",9999999999)
  271. tremor:SetKeyValue("spawnflags", 7)
  272. tremor.nodupe = true
  273. tremor:Spawn()
  274.  
  275. local function TremorReport(mag)
  276. local mag = table.remove(lastmagnitudes, 1)
  277. if mag then
  278. if mag < 6.5 then
  279. GAMEMODE:NotifyAll(0, 3, string.format(LANGUAGE.earthtremor_report, tostring(mag)))
  280. return
  281. end
  282. GAMEMODE:NotifyAll(0, 3, string.format(LANGUAGE.earthquake_report, tostring(mag)))
  283. end
  284. end
  285.  
  286. local function EarthQuakeTest()
  287. if not GAMEMODE.Config.earthquakes then return end
  288.  
  289. if GAMEMODE.Config.quakechance and math.random(0, GAMEMODE.Config.quakechance) < 1 then
  290. local en = ents.FindByClass("prop_physics")
  291. local plys = player.GetAll()
  292.  
  293. local force = math.random(10,1000)
  294. tremor:SetKeyValue("magnitude",force/6)
  295. for k,v in pairs(plys) do
  296. v:EmitSound("earthquake.mp3", force/6, 100)
  297. end
  298. tremor:Fire("explode","",0.5)
  299. util.ScreenShake(Vector(0,0,0), force, math.random(25,50), math.random(5,12), 9999999999)
  300. table.insert(lastmagnitudes, math.floor((force / 10) + .5) / 10)
  301. timer.Simple(10, function() TremorReport(alert) end)
  302. for k,e in pairs(en) do
  303. local rand = math.random(650,1000)
  304. if rand < force and rand % 2 == 0 then
  305. e:Fire("enablemotion","",0)
  306. constraint.RemoveAll(e)
  307. end
  308. if e:IsOnGround() then
  309. e:TakeDamage((force / 100) + 15, game.GetWorld())
  310. end
  311. end
  312. end
  313. end
  314. timer.Create("EarthquakeTest", 1, 0, EarthQuakeTest)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement