--- [[[ Zombie Zone Script ]]] --- --- [[ Map Of User Stats ]] --- -- 0 - Zombie kills - The amount of zombies that the player has killed as a marine -- 1 - Marine kills - The amount of marines player has killed as a zombie -- 2 - Zombie Deaths - The amount of deaths that the player has suffered as a zombie -- 3 - Ammo Used - The amount of ammo the player has used up -- 4 - Teamkills - The amount of teamkills the marine has 'achieved' :) -- 5 - Corsplosions - The amount of corpses the zombie has nuked -- 6 - Medicated - How many medikits has the marine had? --- [[ Constants ]] ------ gc_startingammo = 250 -- The amount of ammo the marine starts with gc_mapcenterx = 2400 -- The center of the map along the x axis gc_mapcentery = 2608 -- The center of the map along the y axis --- [[ Globals ]] -------- g_arena = nil -- The global arena class, to avoid having to pass it around functions g_bGameRunning = false -- Is the game running? g_winner = nil -- The player who won g_winnerevent = 0 -- The eventid for the repeating winner event g_supplyevent = 0 -- The eventid for dropping supplies g_roundnum = 0 -- The round we are currently on (Defined by supply drops) --- [[ Other Functions ]] --- -- SupplySpawn = For creating a supply drop at a random location on the map function SupplySpawn(ev) -- Increase the round g_roundnum = g_roundnum + 1 -- Calculate the random coordinates to spawn the supplies local randx = gc_mapcenterx + math.random(-gc_mapcenterx, gc_mapcenterx) local randy = gc_mapcentery + math.random(-gc_mapcentery, gc_mapcentery) -- Create some ammo based on how many marines are left local ammoamount = (team_fromname(g_arena, "Marines"):num() + 1) * gc_startingammo -- Spawn it at the location g_arena:item_create("Ammo", ammoamount, randx, randy) -- Create a medikit for each marine local medikitamount = team_fromname(g_arena, "Marines"):num() g_arena:item_create("Medikit", medikitamount, randx + 50, randy) -- Give 'em a plasma turret and some walls too g_arena:item_create("Plasma Turret Kit", 1, randx + 100, randy) g_arena:item_create("Wall Kit", 10, randx + 150, randy) -- Convert the coordinates local lettercoord = "A" randx = math.floor((randx / 80) / 16) randy = ((randy / 80) / 16) + 1 if (randx == 0) then lettercoord = "A" elseif (randx == 1) then lettercoord = "B" elseif (randx == 2) then lettercoord = "C" elseif (randx == 3) then lettercoord = "D" elseif (randx == 4) then lettercoord = "E" else lettercoord = "F" end -- Inform the players g_arena:message("!There has been a supply drop at " .. lettercoord .. math.floor(randy) .. "!") end -- ChooseZombie = For randomly choosing a zombie type function ChooseZombie(zombie) -- We want to randomly choose a zombie type to use local rand = math.random(1, 100) if (rand < 32) then zombie:setVehicle(100) -- Normal Zombie elseif (rand < 54) then zombie:setVehicle(103) -- Alien Zombie elseif (rand < 75) then zombie:setVehicle(102) -- Flesh Zombie elseif (rand < 87) then zombie:setVehicle(101) -- Assassin Zombie elseif (rand < 95) then zombie:setVehicle(105) -- Devourer Zombie else -- Tell arena! Tough zombie g_arena:message(zombie.m_name .. " has spawned as a super-zombie!") zombie:setVehicle(104) -- Tough Zombie end end -- Fireworks = For creating celebration explosions around the player :D function Fireworks(eventid) -- Create an explosion randomly around the player local c = g_winner:coords() g_arena:explosion_create("GG Explode", c.x + math.random(-60, 60), c.y + math.random(-60, 60), c.rotation) end -- ReportStats = For reporting the end-game statistics function ReportStats() -- Gather and report statistics if (g_winner == nil or g_winner:valid() == true) then g_arena:message("!Victory: " .. g_winner.m_name) else g_arena:message("!Victory: Nobody!") end -- Award local variables local stubplayer = g_arena:get(1) -- Grab the first player for initial comparisons if (stubplayer:spectator() == true) then -- If he's in spec, we don't want him to win anything for x = 0, 6 do stubplayer:setstat(x, 0) end else -- Calculate the player's ammo/medication used stubplayer:setstat(3, stubplayer:getstat(3) - stubplayer:inventory_find("Ammo")) stubplayer:setstat(6, stubplayer:getstat(6) - stubplayer:inventory_find("Medikit")) end local awd_zombiekills = stubplayer local awd_marinekills = stubplayer local awd_zombiedeaths = stubplayer local awd_ammoused = stubplayer local awd_teamkills = stubplayer local awd_corsplosions = stubplayer local awd_medicated = stubplayer -- Iterate through players and report personal statistics for x = 2, g_arena:num() do local plyr = g_arena:get(x) -- Only take into account players that aren't spectating if (plyr:spectator() == false) then -- Compare zombie kills if (plyr:getstat(0) > awd_zombiekills:getstat(0)) then awd_zombiekills = plyr end -- Compare marine kills if (plyr:getstat(1) > awd_marinekills:getstat(1)) then awd_marinekills = plyr end -- Compare zombie deaths if (plyr:getstat(2) > awd_zombiedeaths:getstat(2)) then awd_zombiedeaths = plyr end -- Calculate ammo used plyr:setstat(3, plyr:getstat(3) - plyr:inventory_find("Ammo")) if (plyr:getstat(3) > awd_ammoused:getstat(3)) then awd_ammoused = plyr end -- Compare teamkills if (plyr:getstat(4) > awd_teamkills:getstat(4)) then awd_teamkills = plyr end -- Compare corsplosions! :D if (plyr:getstat(5) > awd_corsplosions:getstat(5)) then awd_corsplosions = plyr end -- Calculate/Compare medication plyr:setstat(6, plyr:getstat(6) - plyr:inventory_find("Medikit")) if (plyr:getstat(6) > awd_corsplosions:getstat(6)) then awd_medicated = plyr end -- Show player his personal stats plyr:message("@PERSONAL STATS: Zombie Kills=" .. plyr:getstat(0) .. " Marine Kills=" .. plyr:getstat(1) .. " Zombie Deaths=" .. plyr:getstat(2)) plyr:message("@PERSONAL STATS: Ammo Spent=" .. plyr:getstat(3) .. " Teamkills=" .. plyr:getstat(4) .. " Corsplosions!=" .. plyr:getstat(5)) plyr:message("@PERSONAL STATS: Medication Used=" .. plyr:getstat(6)) --plyr:message("@PERSONAL REWARD: Points=0 Cash=0 Experience=0") <- Fix this! end end -- Then report the awards g_arena:message("~Most Zombie Kills (" .. awd_zombiekills:getstat(0) .. "): " .. awd_zombiekills.m_name) g_arena:message("~Most Marine Kills (" .. awd_marinekills:getstat(1) .. "): " .. awd_marinekills.m_name) g_arena:message("~Most Suicidal Zombie (" .. awd_zombiedeaths:getstat(2) .. "): " .. awd_zombiedeaths.m_name) g_arena:message("~Most Trigger Happy (" .. awd_ammoused:getstat(3) .. "): " .. awd_ammoused.m_name) g_arena:message("~Most Teamkills (" .. awd_teamkills:getstat(4) .. "): " .. awd_teamkills.m_name) g_arena:message("~Most Corsplosions (" .. awd_corsplosions:getstat(5) .. "): " .. awd_corsplosions.m_name) g_arena:message("~Most Medicated Marine (" .. awd_medicated:getstat(6) .. "): " .. awd_medicated.m_name) end --- [[ Event Functions ]] --- function Vehicle_OnCreate(born) end function Vehicle_OnDeath(victim, killer) -- Check if the dead vehicle is a corpse if (victim:vehicletypeid() == 300) then -- Reward the killer with a corsplosion! if (killer:valid() == true) then killer:setstat(5, killer:getstat(5) + 1) end end end function Item_OnPickUp(looter, loot, loot_type, amounttopickup) -- If he picked up an engineer kit if (loot_type.m_name == "Engineer Kit") then -- Player needs to be a marine, and only picking up one kit if (amounttopickup > 1) then looter:message("You are only allowed one engineer kit.") return false elseif (looter:getVehicle():vehicletypeid() >= 15) then looter:message("You need to be a marine to become an engineer.") return false end -- Otherwise, we want to make him an engineer. :) g_arena:message(looter.m_name .. " has become an engineer.") looter:setVehicle(15) -- ..and give him a few turrets to place local stopabuse = looter:inventory_find("Plasma Turret Kit") looter:inventory_modify("Plasma Turret Kit", 2 - stopabuse) local stopabuse = looter:inventory_find("Wall Kit") looter:inventory_modify("Wall Kit", 10 - stopabuse) -- Now we want to destroy the item local itmstruct = loot:get_struct() if (itmstruct.amount == 1) then loot:destroy() else itmstruct.amount = itmstruct.amount - 1 loot:update() end return false elseif (loot_type.m_name == "Ammo") then -- Don't let zombies pick up ammo if (looter:getVehicle():vehicletypeid() >= 100) then looter:message("Zombies have no use for ammo.") return false end -- Add to the player's ammo count looter:setstat(3, looter:getstat(3) + amounttopickup) elseif (loot_type.m_name == "Medikit") then -- Don't let zombies pick up medikits if (looter:getVehicle():vehicletypeid() >= 100) then looter:message("Thief. That's for the marines.") return false end -- Has the player had enough medication for now? if (looter:getstat(6) < g_roundnum + 1) then -- Give this man his kit! -- .. if he's not being greedy if (amounttopickup > 1) then -- Tell him and refuse the request looter:message("You can only grab one medikit at a time.") return false end -- Increase his medication looter:setstat(6, looter:getstat(6) + 1) return true else -- He's not allowed anymore until the next supply drop looter:message("You've had your medication for this drop!") return false end elseif (loot_type.m_name == "Plasma Turret Kit" or loot_type.m_name == "Wall Kit") then -- Check to see if he's an engineer if (looter:getVehicle():vehicletypeid() ~= 15) then looter:message("You can't use that.") return false end end return true end function Arena_OnCreate(arena) -- Set our global value g_arena = arena -- Initialize random math.randomseed(os.time()) end function Arena_OnGameStart() -- Destroy the celebration event event_destroy(g_winnerevent) -- Set the supply event in motion g_supplyevent = event_create(SupplySpawn, -60000) -- Every minute -- Ensure the player that the game has started g_arena:message("Game started, you cannot unspec until the game is finished.") -- Lock the arena g_arena:lock(true) g_bGameRunning = true g_roundnum = 0 -- Calculate the random coordinates to spawn the marine team local randx = gc_mapcenterx + math.random(-gc_mapcenterx, gc_mapcenterx) local randy = gc_mapcentery + math.random(-gc_mapcentery, gc_mapcentery) -- Create the initial defensive turret g_arena:vehicle_create(200, randx, randy, 0) -- Spawn some engineer kits (with always one engineer) local numengys = g_arena:num() / 10 if (numengys < 1) then numengys = 1 end for x = 1, numengys do -- Randomize the spawn local itemrandx = math.random(-100, 100) local itemrandy = math.random(-100, 100) -- Spawn a kit somewhere around the spawn point g_arena:item_create("Engineer Kit", 1, randx + itemrandx, randy + itemrandy) end -- Calculate the number of zombies we need local amount = g_arena:num() / 5 -- Turn everyone into marines for x = 1, g_arena:num() do local marine = g_arena:get(x) -- Reset their stats marine:setstat(0, 0) marine:setstat(1, 0) marine:setstat(2, 0) marine:setstat(3, gc_startingammo) marine:setstat(4, 0) marine:setstat(5, 0) marine:setstat(6, 1) -- Start off with 1 medikit -- Remove any engineer items and reset their ammo marine:inventory_modify("Plasma Turret Kit", -1000) marine:inventory_modify("Wall Kit", -1000) marine:inventory_modify("Ammo", -30000) marine:inventory_modify("Ammo", gc_startingammo) marine:inventory_modify("Medikit", -30000) marine:inventory_modify("Medikit", 1) -- If they're not in spec if marine:spectator() == false then -- Make him a marine marine:team_change("Marines", "") marine:setVehicle(10) -- Warp all marines to the spawn point marine:warp(randx, randy, 150) end end -- Locate the player ids which we will turn to zombies local numplayers = g_arena:num() for x = 0, amount do local zombie = g_arena:get(math.random(1, numplayers)) -- If he's not in spec and not already a zombie if (zombie:spectator() == false) and (zombie:getVehicle():vehicletypeid() < 100) then -- Turn him zombie:team_change("Zombie Horde", "") ChooseZombie(zombie) -- Warp zombies anywhere zombie:warp(gc_mapcenterx, gc_mapcentery, gc_mapcenterx*2) else -- We'll have to try again x = x - 1 end end end function Arena_OnGameEnd() -- Show endgame stats ReportStats() -- Kill the supply event event_destroy(g_supplyevent) -- Unlock the arena g_arena:lock(false) g_arena:message("Game is about to start... enter the game now to play.") g_bGameRunning = false end function Player_OnDeath(killer, victim) -- If the game isn't running, we don't want to do any of the other dynamics if g_bGameRunning == false then return end -- Check if the victim is a marine (isn't a zombie) if (victim:getVehicle():vehicletypeid() < 20) then -- Has there been a teamkill!? if (killer:getVehicle():vehicletypeid() < 20) then -- The killer is a marine too! Teamkill! killer:setstat(4, killer:getstat(4) + 1) elseif (killer:getVehicle():vehicletypeid() >= 100) then -- Otherwise, the killer is a zombie and we need to up his marine kills killer:setstat(1, killer:getstat(1) + 1) end -- First, we'll stick a corpse on top of him local pos = victim:coords() g_arena:vehicle_create(300, pos.x, pos.y, pos.rotation) -- Remove any engineer items victim:inventory_modify("Plasma Turret Kit", -1000) victim:inventory_modify("Wall Kit", -1000) -- We want to turn the player into a zombie victim:team_change("Zombie Horde", "") ChooseZombie(victim) -- Give him his crown back victim:setcrown(true, 0) -- Are we down to one marine yet? local marineteam = team_fromname(g_arena, "Marines") if (marineteam:exists() == true) then -- Look to see how many players are actually left playing local nummarines = 0 local winner= nil for x = 1, marineteam:num() do if marineteam:get(x):spectator() == false then nummarines = nummarines + 1 winner = marineteam:get(x) end end -- If there is only one surviving marine if (nummarines == 1) then -- Break the news! g_winner = winner g_arena:message(winner.m_name .. " was the last marine standing! Celebrate!") -- Let him celebrate :) winner:setVehicle(50) g_winnerevent = event_create(Fireworks, -750) local zombieteam = team_fromname(g_arena, "Zombie Horde") -- Take the crowns from all the zombies if zombieteam:exists() then for x = 1, zombieteam:num() do zombieteam:get(x):setcrown(false, 0) end end end end -- If the victim is a zombie elseif (victim:getVehicle():vehicletypeid() >= 100) then -- Give him his crown back victim:setcrown(true, 0) -- Make him a random class ChooseZombie(victim) -- Add one to his zombie deaths victim:setstat(2, victim:getstat(2) + 1) -- If the killer is a marine.. if (killer:getVehicle():vehicletypeid() < 15) then -- Get his zombie kills local zombiekills = killer:getstat(0) zombiekills = zombiekills + 1 -- Is he ready for an upgrade? if (zombiekills == 2) then killer:setVehicle(11) elseif (zombiekills == 4) then killer:setVehicle(12) elseif (zombiekills == 6) then killer:setVehicle(13) end killer:setstat(0, zombiekills) end end end