Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Don't change anything!!!!!!!
- local Shop = {
- ["Items"] = {
- {{276, 1}, 10000, "1", "^BDiamond Sword"};
- {{268, 1}, 150, "3", "^6Wooden Sword"};
- {{272, 1}, 1000, "4", "^7Stone Sword"};
- {{267, 1}, 5000, "5", "^8Iron Sword"};
- {{298, 1}, 300, "6", "^6Leather Helmet"};
- {{299, 1}, 300, "7", "^6Leather Chestplate"};
- {{300, 1}, 300, "8", "^6Leather Leggings"};
- {{301, 1}, 300, "9", "^6Leather Boots"};
- {{306, 1}, 500, "10", "^8Iron Helmet"};
- {{307, 1}, 500, "11", "^8Iron Chestplate"};
- {{308, 1}, 500, "12", "^8Iron Leggings"};
- {{309, 1}, 500, "13", "^8Iron Boots"};
- {{310, 1}, 6000, "14", "^bDiamond Helmet"};
- {{311, 1}, 6000, "15", "^bDiamond Chestplate"};
- {{312, 1}, 6000, "16", "^bDiamond Leggings"};
- {{313, 1}, 6000, "17", "^bDiamond Boots"};
- };
- ["Effects"] = {
- {{"Speed", 9999, 1}, 350, "2", "^bSpeed I"};
- };
- }
- local Maps = {
- ["Prex"] = {
- ZombiePosition = {2047, 11, 1513};
- PlayerPosition = {2047, 4, 1513};
- ZombieItems = {
- {268, 1};
- {298, 1};
- {299, 1};
- {300, 1};
- {301, 1};
- };
- PlayerItems = {
- {261, 1};
- {262, 64};
- {262, 64};
- };
- };
- ["Psy Town"] = {
- ZombiePosition = {2131, 4, 1480};
- PlayerPosition = {2117, 8, 1500};
- ZombieItems = {
- {268, 1};
- {298, 1};
- {299, 1};
- {300, 1};
- {301, 1};
- };
- PlayerItems = {
- {261, 1};
- {262, 64};
- {262, 64};
- }
- }
- }
- local PlayerItems = {}
- local PlayerEffects = {}
- local Points = {}
- local AMI = peripheral.wrap("right")
- os.loadAPI("/textutils")
- local CMD = peripheral.wrap("left")
- local World = AMI.getWorld(AMI.getPeripheralWorldID())
- math.randomseed(os.clock() * os.time())
- if fs.exists("/shop") then
- local ShopF = fs.open("/shop", "r")
- Shop = textutils.unserialize(ShopF.readAll())
- ShopF.close()
- else
- local ShopF = fs.open("/shop", "w")
- local ToWrite = "{\n [\"Items\"] = {"
- for _,Item in pairs(Shop["Items"]) do
- ToWrite = ToWrite .. "\n {{" .. Item[1][1] .. ", " .. Item[1][2] .. "}, " .. Item[2] .. ", \"" .. Item[3] .. "\", \"" .. Item[4] .. "\"};"
- end
- ToWrite = ToWrite .. "\n };\n [\"Effects\"] = {"
- for _,Effect in pairs(Shop["Effects"]) do
- ToWrite = ToWrite .. "\n {{" .. Effect[1][1] .. ", " .. Effect[1][2] .. "}, " .. Effect[2] .. ", \"" .. Effect[3] .. "\", \"" .. Effect[4] .. "\"};"
- end
- ToWrite = ToWrite .. "\n };\n"
- ToWrite = ToWrite .. "}"
- ShopF.write(ToWrite)
- ShopF.close()
- end
- if fs.exists("/maps") then
- local MapsF = fs.open("/maps", "r")
- Maps = textutils.unserialize(MapsF.readAll())
- MapsF.close()
- else
- local MapsF = fs.open("/maps", "w")
- local ToWrite = "{"
- for _,Map in pairs(Maps) do
- ToWrite = ToWrite .. "\n [\"" .. _ .. "\"] = {\n ZombiePosition = {" .. Map.ZombiePosition[1] .. ", " .. Map.ZombiePosition[2] .. ", " .. Map.ZombiePosition[3] .. "};\n PlayerPosition = {" .. Map.PlayerPosition[1] .. ", " .. Map.PlayerPosition[2] .. ", " .. Map.PlayerPosition[3] .. "};\n\n ZombieItems = {"
- for _,Item in pairs(Map.ZombieItems) do
- ToWrite = ToWrite .. "\n {" .. Item[1] .. ", " .. Item[2] .. "};"
- end
- ToWrite = ToWrite .. "\n };\n PlayerItems = {"
- for _,Item in pairs(Map.PlayerItems) do
- ToWrite = ToWrite .. "\n {" .. Item[1] .. ", " .. Item[2] .. "};"
- end
- ToWrite = ToWrite .. "\n };"
- ToWrite = ToWrite .. "\n };"
- end
- ToWrite = ToWrite .. "}"
- MapsF.write(ToWrite)
- MapsF.close()
- end
- if fs.exists("/points") then
- local File = fs.open("/points", "r")
- Points = textutils.unserialize(File.readAll())
- File.close()
- end
- if fs.exists("/playerEffects") then
- local File = fs.open("/playeritems", "r")
- PlayerItems = textutils.unserialize(File.readAll())
- File.close()
- end
- if fs.exists("/playereffects") then
- local File = fs.open("/playereffects", "r")
- PlayerEffects = textutils.unserialize(File.readAll())
- File.close()
- end
- local function SavePoints()
- local File = fs.open("/points", "w")
- File.write(textutils.serialize(Points))
- File.close()
- end
- local function SavePlayerItems()
- local File = fs.open("/playeritems", "w")
- File.write(textutils.serialize(PlayerItems))
- File.close()
- end
- local function SavePlayerEffects()
- local File = fs.open("/playereffects", "w")
- File.write(textutils.serialize(PlayerEffects))
- File.close()
- end
- local function GTable(Table, Prefix, Suffix)
- Prefix = Prefix or ""
- Suffix = Suffix or ""
- local New = ""
- for _,String in pairs(Table) do
- if _ == 1 then
- New = Prefix .. String .. Suffix
- elseif _ == #Table then
- New = New .. " and " .. Prefix .. String .. Suffix
- else
- New = New .. ", " .. Prefix .. String .. Suffix
- end
- end
- return New
- end
- local function AddPoints(Player, Count)
- if not Points[Player] then
- Points[Player] = Count
- else
- Points[Player] = Points[Player] + Count
- end
- SavePoints()
- end
- local function GetPlayerNames()
- return AMI.getPlayerUsernames()
- end
- local function GetPlayers()
- local Players = {}
- for _,Name in pairs(GetPlayerNames()) do
- table.insert(Players, AMI.getPlayerByName(Name))
- end
- return Players
- end
- local function Broadcast(Message, Header)
- if Header then
- Message = "^r[^4^lZombieGame^r] " .. Message
- end
- Message = Message:gsub("%^", string.char(0xc2) .. string.char(0xa7))
- for _,Player in pairs(GetPlayers()) do
- Player.sendChat(Message)
- end
- end
- local function SendMessage(Player, Message, Header)
- if Header then
- Message = "^r[^4^lZombieGame^r] " .. Message
- end
- Message = Message:gsub("%^", string.char(0xc2) .. string.char(0xa7))
- AMI.getPlayerByName(Player).sendChat(Message)
- end
- local function RunCommand(Command)
- CMD.setCommand(Command)
- CMD.runCommand()
- end
- local function GameThread()
- while true do
- --[[Broadcast("Starting game in 1 minute.", true)
- sleep(50)
- Broadcast("Starting game in 10 seconds.", true)
- sleep(5)]]
- Broadcast("Starting game in 5 seconds.", true)
- sleep(5)
- Broadcast("Starting game.", true)
- local Players = GetPlayers()
- local Zombies = {}
- local FZombies = {}
- local ZombieCount = 1
- local OZombie = Players[math.random(1, #Players)]
- Broadcast("^c" .. OZombie.getUsername() .. "^r is the zombie.", true)
- Zombies[OZombie.getUsername()] = true
- RunCommand("clear @a")
- local MapCount = 0
- for _,__ in pairs(Maps) do
- MapCount = MapCount + 1
- end
- local MapN = math.random(1, MapCount)
- local Map
- local MOn = 0
- local MapName
- for _,MapO in pairs(Maps) do
- MOn = MOn + 1
- if MOn == MapN then
- Map = MapO
- MapName = _
- end
- end
- Broadcast(MapName .. " is the map.", true)
- for _,Player in pairs(Players) do
- RunCommand("gamemode 0 " .. Player.getUsername())
- if not Zombies[Player.getUsername()] then
- for _,Item in pairs(Map.PlayerItems) do
- RunCommand("give " .. Player.getUsername() .. " " .. Item[1] .. " " .. Item[2])
- end
- Player.asEntity().setPosition(unpack(Map.PlayerPosition))
- -- Player.setHealth(0)
- RunCommand("spawnpoint " .. Player.getUsername() .. " " .. Map.PlayerPosition[1] .. " " .. Map.PlayerPosition[2] .. " " .. Map.PlayerPosition[3])
- else
- for _,Item in pairs(Map.ZombieItems) do
- RunCommand("give " .. Player.getUsername() .. " " .. Item[1] .. " " .. Item[2])
- end
- Player.asEntity().setPosition(unpack(Map.ZombiePosition))
- RunCommand("spawnpoint " .. Player.getUsername() .. " " .. Map.ZombiePosition[1] .. " " .. Map.ZombiePosition[2] .. " " .. Map.ZombiePosition[3])
- end
- if PlayerItems[Player.getUsername()] then
- for _,Item in pairs(PlayerItems[Player.getUsername()]) do
- RunCommand("give " .. Player.getUsername() .. " " .. Item[1] .. " " .. Item[2])
- end
- end
- if PlayerEffects[Player.getUsername()] then
- for _,Effect in pairs(PlayerEffects[Player.getUsername()]) do
- RunCommand("effect " .. Player.getUsername() .. " " .. Effect[1] .. " " .. Effect[2] .. " " .. Effect[3])
- end
- end
- end
- local Timer1 = os.startTimer(180)
- local Timer2 = os.startTimer(230)
- local Timer3 = os.startTimer(235)
- local Timer4 = os.startTimer(240)
- Broadcast("4 minutes left!", true)
- local function PlayerDead(P1)
- if not Zombies[P1] then
- Zombies[P1] = true
- RunCommand("clear " .. P1)
- Broadcast("^2" .. P1 .. "^r has been infected!", true)
- World.playSound("ambient.weather.thunder", Map.ZombiePosition[1], Map.ZombiePosition[2], Map.ZombiePosition[3], 100, 1)
- ZombieCount = ZombieCount + 1
- FZombies[P1] = true
- if #Players == ZombieCount then
- RunCommand("spawnpoint @a 2088 4 1545")
- RunCommand("tp @a 2088 4 1545")
- RunCommand("clear @a")
- for _,Player in pairs(GetPlayerNames()) do
- if PlayerEffects[Player] then
- for _,Effect in pairs(PlayerEffects[Player]) do
- RunCommand("effect " .. Player .. " " .. Effect[1] .. " 0")
- end
- end
- end
- Broadcast("^cZombies^r win!", true)
- AddPoints(OZombie.getUsername(), 30)
- Broadcast("^c" .. OZombie.getUsername() .. "^r has been awarded 30 points!", true)
- return true
- end
- end
- end
- while true do
- local Event, P1 = os.pullEvent()
- if Event == "chat_death" then
- local Ret = PlayerDead(P1)
- if Ret == true then
- break
- end
- elseif Event == "player_respawn" then
- if not Zombies[P1] then
- local Ret = PlayerDead(P1)
- if Ret == true then
- break
- end
- end
- -- AMI.getPlayerByName(P1).asEntity().setPosition(unpack(Map.ZombiePosition))
- if FZombies[P1] == true then
- FZombies[P1] = nil
- RunCommand("clear " .. P1)
- for _,Item in pairs(Map.ZombieItems) do
- RunCommand("give " .. P1 .. " " .. Item[1] .. " " .. Item[2])
- end
- if PlayerItems[P1] then
- for _,Item in pairs(PlayerItems[P1]) do
- RunCommand("give " .. P1 .. " " .. Item[1] .. " " .. Item[2])
- end
- end
- end
- if PlayerEffects[P1] then
- for _,Effect in pairs(PlayerEffects[P1]) do
- RunCommand("effect " .. P1 .. " " .. Effect[1] .. " " .. Effect[2] .. " " .. Effect[3])
- end
- end
- -- World.setBlock(Map.ZombiePosition[1], Map.ZombiePosition[2], Map.ZombiePosition[3], 1, 0)
- -- sleep(0.5)
- -- World.setBlock(Map.ZombiePosition[1], Map.ZombiePosition[2], Map.ZombiePosition[3], 0, 0)
- elseif Event == "timer" then
- if P1 == Timer1 then
- Broadcast("1 minute left!", true)
- elseif P1 == Timer2 then
- Broadcast("10 seconds left!", true)
- elseif P1 == Timer3 then
- Broadcast("5 seconds left!", true)
- elseif P1 == Timer4 then
- RunCommand("spawnpoint @a 2088 4 1545")
- RunCommand("tp @a 2088 4 1545")
- RunCommand("clear @a")
- for _,Player in pairs(GetPlayerNames()) do
- if PlayerEffects[Player] then
- for _,Effect in pairs(PlayerEffects[Player]) do
- RunCommand("effect " .. Player .. " " .. Effect[1] .. " 0")
- end
- end
- end
- Broadcast("^2Survivors^r win!", true)
- local Survivors = {}
- for _,Player in pairs(Players) do
- if not Zombies[Player.getUsername()] then
- AddPoints(Player.getUsername(), 50)
- table.insert(Survivors, Player.getUsername())
- end
- end
- Broadcast(GTable(Survivors, "^2", "^r") .. " have been awarded 50 points!", true)
- break
- end
- end
- end
- end
- end
- local function GetPlayer(Name)
- local List = {}
- for _,Player in pairs(GetPlayerNames()) do
- if Player:lower():sub(1, #Name) == Name:lower() then
- table.insert(List, AMI.getPlayerByName(Player))
- end
- end
- return List
- end
- local function LobbyThread()
- while true do
- local Event, P1, P2 = os.pullEvent()
- if Event == "chat_message" then
- local Args = {}
- for Arg in P2:gmatch("([^ ]+)") do
- table.insert(Args, Arg)
- end
- if Args[1] == "/buy" then
- Args[3] = Args[2]
- Args[1] = "/shop"
- Args[2] = "buy"
- end
- if Args[1] == "/shop" then
- if not Args[2] then
- SendMessage(P1, "Usage: /shop <list;buy>", true)
- else
- if Args[2] == "list" then
- if not Args[3] then
- SendMessage(P1, "Usage: /shop list <items;effects>", true)
- else
- if Args[3] == "items" then
- SendMessage(P1, "Listing shop items", true)
- for _,Item in pairs(Shop["Items"]) do
- SendMessage(P1, Item[3] .. ": " .. Item[4] .. "^r: Price: " .. Item[2])
- end
- elseif Args[3] == "effects" then
- SendMessage(P1, "Listing shop effects", true)
- for _,Effect in pairs(Shop["Effects"]) do
- SendMessage(P1, Effect[3] .. ": " .. Effect[4] .. "^r: Price: " .. Effect[2])
- end
- end
- end
- elseif Args[2] == "buy" then
- if not Args[3] then
- SendMessage(P1, "Usage: /shop buy <shopid>")
- else
- local Item
- local IsItem = false
- local ItemName
- for _,TItem in pairs(Shop["Items"]) do
- if TItem[3] == Args[3] then
- Item = TItem
- ItemName = TItem[4]
- IsItem = true
- end
- end
- for _,TEffect in pairs(Shop["Effects"]) do
- if TEffect[3] == Args[3] then
- Item = TEffect
- ItemName = TEffect[4]
- end
- end
- if Item then
- if not PlayerItems[P1] then
- PlayerItems[P1] = {}
- end
- if not PlayerEffects[P1] then
- PlayerEffects[P1] = {}
- end
- if (Points[P1] or 0) >= Item[2] then
- Points[P1] = Points[P1] - Item[2]
- SavePoints()
- if IsItem == true then
- table.insert(PlayerItems[P1], Item[1])
- SavePlayerItems()
- else
- table.insert(PlayerEffects[P1], Item[1])
- SavePlayerEffects()
- end
- SendMessage(P1, "Bought " .. ItemName .. "^r for " .. Item[2] .. " points", true)
- if IsItem == true then
- RunCommand("give " .. P1 .. " " .. Item[1][1] .. " " .. Item[1][2])
- else
- RunCommand("effect " .. P1 .. " " .. Item[1][1] .. " " .. Item[1][2] .. " " .. Item[1][3])
- end
- else
- SendMessage(P1, "You need " .. ((Points[P1] or 0) - Item[2]) * -1 .. " more points for that", true)
- end
- else
- SendMessage(P1, "Item not found", true)
- end
- end
- end
- end
- elseif Args[1] == "/points" then
- if not Args[2] then
- SendMessage(P1, "You have " .. (Points[P1] or 0) .. " points", true)
- else
- local Players = GetPlayer(Args[2])
- if #Players == 0 then
- SendMessage(P1, Args[2] .. " has " .. (Points[Args[2]] or 0) .. " points" , true)
- else
- for _,Player in pairs(Players) do
- SendMessage(P1, Player.getUsername() .. " has " .. (Points[Player.getUsername()] or 0) .. " points", true)
- end
- end
- end
- end
- end
- end
- end
- local function AdminThread()
- end
- parallel.waitForAll(LobbyThread, GameThread, AdminThread)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement