Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- 1Ridav Hexagon control program
- --Special for computercraft.ru
- --Created by Netins
- teams=
- {
- ["red"]=
- {
- ["name"]="",
- ["pcount"]=0
- },
- ["yellow"]=
- {
- ["name"]="",
- ["pcount"]=0
- },
- ["blue"]=
- {
- ["name"]="",
- ["pcount"]=0
- },
- ["green"]=
- {
- ["name"]="",
- ["pcount"]=0
- }
- }
- coords=
- {
- ["red"]=" -253 21 1040", --red base
- ["yellow"]=" -253 21 1040", --yellow base
- ["blue"]=" -326 21 975", --blue base
- ["green"]=" 326 21 1105" --green base
- }
- tools=
- {
- " 301 1 66", -- infinite leather boots
- " 300 1 76", -- infinite leather pants
- " 299 1 81", -- infinite leather tunic
- " 298 1 56", -- infinite leather cap
- " 267 1 251", -- infinite iron sword
- " 400 64" -- pumpkin pie(64)
- --"" for something
- }
- teamsList={"red","yellow","blue","green"}
- cb=peripheral.wrap("back")
- p=peripheral.wrap("bottom")
- m=peripheral.wrap("top")
- local gameIsOn=false
- local var=1
- function checkNumber()
- local function getNumber()
- return read()+0
- end
- while true do
- e, mes =pcall(getNumber)
- if type(mes) ~= "number"
- then print("<number> expected, got <string>")
- else break
- end
- end
- return mes
- end
- function getTableLenght(a)
- local b=0
- for i,_ in pairs(a) do
- b=b+1
- end
- return b
- end
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colours.red)
- print("WARNING! WHEN BATTLE WILL START, YOUR INVENTORY WILL BE CLEARED!\n\n")
- term.setTextColor(colours.white)
- print("Welcome to 1Ridav Hexagon!\n")
- write("Enter count of teams - ")
- while true do
- teamCount=checkNumber()
- if teamCount<=1 then
- print("You need at least 2 teams to start a battle")
- else if teamCount >=5 then
- print("Maxium count of teams is 4")
- else break
- end
- end
- end
- --teams settings
- for i=1, teamCount do
- print("\nThere are settings for ",i," team")
- write("Choose your team's colour (blue, yellow, red, green) - ")
- --checking color
- while true do
- while true do
- color = read()
- if (color ~= "red") and (color ~= "blue") and (color ~= "green") and (color ~= "yellow") then
- print("Invalid color")
- else break
- end
- end
- if getTableLenght(teams[color]) >2 then
- print("Color is occupied")
- else break
- end
- end
- currentTeam=teams[color]
- write("Choose the name for your team - ")
- while true do
- currentTeam.name=read() -- names of teams can be same
- if currentTeam.name == "" then
- print("Invalid name")
- else break
- end
- end
- write("Enter count of players in the team - ")
- currentTeam.pcount=checkNumber()
- if currentTeam.pcount>=10 then
- print("Wow. Much players.") --xD
- end
- --put some sensor methods here
- write("Enter players' nicknames - ")
- for i=1,currentTeam.pcount do
- local player = read()
- currentTeam[player]=1
- end
- color,player=nil
- end
- --[[for i,v in pairs(teams) do
- print("in ",i)
- for c,m in pairs(v) do
- print("index - ",c)
- print("inside - ",m)
- end
- end]]
- cb.setCommand("/say Match started")
- cb.runCommand()
- for i,v in pairs(teams) do
- for a,_ in pairs(v) do
- if a~= "name" then
- cb.setCommand("/tp "..a..coords[i])
- cb.runCommand()
- end
- for n=1,#tools do
- cb.setCommand("/clear "..a)
- cb.runCommand()
- cb.setCommand("/give "..a..tools[n])
- cb.runCommand()
- end
- end
- end
- for _,v in pairs(teams) do
- for player,_ in pairs(v) do
- cb.setCommand("/effect "..player.." 15 1000000 10")
- cb.runCommand()
- end
- end
- gameIsOn=true
- while gameIsOn do
- for teamColor, tab in pairs(teams) do
- for player, lifestat in pairs(tab) do
- if getTableLenght(teams[teamColor]) > 2 and (player ~= "name") and (player ~= "pcount") and teams[teamColor].pcount>0 then
- pl=p.getPlayerByName(player)
- health=pl.getHealth()
- if (health==0) and (teams[teamColor][player]==1) then
- cb.setCommand("/say Member of "..teamColor.." team - ".."[".. teams[teamColor].name .."]"..player.." - died.")
- cb.runCommand()
- teams[teamColor][player]=0
- teams[teamColor].pcount=teams[teamColor].pcount-1
- end
- if teams[teamColor].pcount == 0 then
- cb.setCommand("/say All players of "..teams[teamColor].name.."["..teamColor.."]" .." team destroyed!")
- cb.runCommand()
- end
- end
- end
- -- i'm so sorry for the code below
- if (teams.red.pcount>0) and (teams.yellow.pcount==0) and (teams.blue.pcount==0) and (teams.green.pcount==0) then
- cb.setCommand("/say Red team ("..teams.red.name..") wins!")
- cb.runCommand()
- gameIsOn=false
- winner="red"
- break
- elseif teams.red.pcount==0 and teams.yellow.pcount>0 and teams.blue.pcount==0 and teams.green.pcount==0 then
- cb.setCommand("/say Yellow team ("..teams.yellow.name.. ") wins!")
- cb.runCommand()
- gameIsOn=false
- winner="yellow"
- break
- elseif teams.red.pcount==0 and teams.yellow.pcount==0 and teams.blue.pcount>0 and teams.green.pcount==0 then
- cb.setCommand("/say Blue team ("..teams.blue.name.. ") wins!")
- cb.runCommand()
- gameIsOn=false
- winner="blue"
- break
- elseif teams.red.pcount==0 and teams.yellow.pcount==0 and teams.blue.pcount==0 and teams.green.pcount>0 then
- cb.setCommand("/say Green team ("..teams.green.name.. ") wins!")
- cb.runCommand()
- gameIsOn=false
- winner="green"
- break
- end
- end
- sleep(0.01) -- i'm not sure about this number
- end
- for _,v in pairs(teams) do
- for i,_ in pairs(v) do
- if i ~= "name" and i~="pcount" then
- cb.setCommand("/effect "..i.." clear")
- cb.runCommand()
- cb.setCommand("/clear "..i)
- cb.runCommand()
- sleep(3) -- waits for the last player
- cb.setCommand("/tp "..i.." -326 39 1040") -- telports to the center of hub
- cb.runCommand()
- end
- end
- end
- for win,_ in pairs(teams[winner]) do
- cb.setCommand("/give "..win.." 397 1 4") -- gives creeper head
- cb.runCommand()
- end
- os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement