King0fGamesYami

Capture The Flag

Jun 1st, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.82 KB | None | 0 0
  1. --[[
  2. Capture the flag - with Command Computers!
  3. redTeamPlayers and blueTeamPlayers are tables,
  4. the names of the players on each team should be entered into them, like so:
  5.  
  6. local redTeamPlayers = {
  7.   ["ilikepie"] = true,
  8.   ["demhydraz"] = true,
  9. }
  10.  
  11. local blueTeamPlayers = {
  12.   ["KingofGamesYami"] = true,
  13.   ["BombBloke"] = true,
  14. }
  15. ]]--
  16.  
  17.  
  18.  
  19.  
  20. local redTeamPlayers = {
  21.  
  22.  
  23. }
  24. local blueTeamPlayers = {
  25.  
  26.  
  27. }
  28.  
  29.  
  30.  
  31. --[[DO NOT EDIT BEYOND THIS POINT!!]]--
  32.  
  33. os.loadAPI( "commandsPlus" )
  34. os.loadAPI( "partTerm" )
  35. local x, y, z = commands.getBlockPosition()
  36.  
  37. local blueTeamFlag = partTerm.createWindow( x, y, z + 100, 25, 10 )
  38. local redTeamFlag = partTerm.createWindow( x, y, z - 100, 25, 10 )
  39. blueTeamFlag.setBackgroundColor( colors.blue )
  40. blueTeamFlag.clear()
  41. blueTeamFlag.setParticle( "mobSpell" )
  42. redTeamFlag.setBackgroundColor( colors.red )
  43. redTeamFlag.clear()
  44. redTeamFlag.setParticle( "mobSpell" )
  45.  
  46.  
  47. local redFlagHolder, blueFlagHolder
  48.  
  49. local function blueFlagCheck()
  50.   while true do
  51.     if blueFlagHolder then
  52.       local a, b = commandsPlus.getPlayerRotation( blueFlagHolder )
  53.       local x, y, z = commandsPlus.getPlayerPosition( blueFlagHolder )
  54.       blueTeamFlag.reposition( x, y + 2, z )
  55.       blueTeamFlag.setAngles( a + 90 )
  56.     else
  57.       local x, y, z = blueTeamFlag.getPosition()
  58.       local ok, result = commands.testfor( "@a["..tostring(x)..","..tostring(y)..","..tostring(z)..",5]" )
  59.       for k, v in pairs( result ) do
  60.         local name = v:match( "Found (.+)" )
  61.         if redTeamPlayers[ name ] then
  62.           blueFlagHolder = name
  63.           blueTeamFlag.center( false )
  64.           break
  65.         end
  66.       end
  67.     end
  68.   end
  69. end
  70.  
  71. local function redFlagCheck()
  72.   while true do
  73.     if redFlagHolder then
  74.       local a, b = commandsPlus.getPlayerRotation( redFlagHolder )
  75.       local x, y, z = commandsPlus.getPlayerPosition( redFlagHolder )
  76.       redTeamFlag.reposition( x, y + 2, z )
  77.       redTeamFlag.setAngles( a + 90 )
  78.     else
  79.       local x, y, z = redTeamFlag.getPosition()
  80.       local ok, result = commands.testfor( "@a["..tostring(x)..","..tostring(y)..","..tostring(z)..",5]" )
  81.       for k, v in pairs( result ) do
  82.         local name = v:match( "Found (.+)" )
  83.         if blueTeamPlayers[ name ] then
  84.           redFlagHolder = name
  85.           redTeamFlag.center( false )
  86.           break
  87.         end
  88.       end
  89.     end
  90.   end
  91. end
  92.  
  93. local winner
  94.  
  95. local function endGameChecker()
  96.   while true do
  97.     for k, v in pairs( commandsPlus.getNearbyPlayers( 2 ) ) do
  98.       if v == redFlagHolder then
  99.         winner = "Blue Team"
  100.         return
  101.       elseif v == blueFlagHolder then
  102.         winner = "Red Team"
  103.         return
  104.       end
  105.     end
  106.   end
  107. end
  108.  
  109. parallel.waitForAny( blueFlagCheck, redFlagCheck, partTerm.render, endGameChecker )
  110. commands.say( "The " .. winner .. " Wins!" )
Advertisement
Add Comment
Please, Sign In to add comment