VADemon

http://www.unrealsoftware.de/forum_answer.php?post=348133

Feb 23rd, 2013
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.26 KB | None | 0 0
  1. coordinates = {
  2.     barr = {
  3.         building_type = 1,
  4.         x = {4,2,1,3},
  5.         y = {-1,3,-4,1}
  6.     }
  7. }
  8.  
  9. add_building("turrets", 8, 1, 1)
  10. add_building("turrets", 8, -1, 1)
  11. add_building("turrets", 8, 1, -1)
  12. add_building("turrets", 8, -1, -1)
  13.  
  14. add_building("gates", 6, -1, 0)
  15. add_building("gates", 6, 1, 0)
  16. add_building("gates", 6, 0, 1)
  17. add_building("gates", 6, 0, -1)
  18.  
  19. function add_building(name, buildType, x, y) --preset name, building ID, x and y offset (tiles)
  20.     local buildType, x, y = tonumber(buildType), tonumber(x), tonumber(y)
  21.    
  22.     if not coordinates[name] then --create a table inside if doesn't exist
  23.         coordinates[name] = {}
  24.         coordinates[name].building_type = buildType
  25.         coordinates[name].x = {}
  26.         coordinates[name].y = {}
  27.     end
  28.    
  29.     if coordinates[name].building_type ~= buildType then --only 1 type of buildings per table allowed
  30.         print("©255000000Error! Failed to add building type: \""..buildType.."\" to the existing type: "..coordinates[name].building_type)
  31.         return false
  32.     end
  33.    
  34.     --insert the given coordinates to the table
  35.     coordinates[name].x[ #coordinates[name].x + 1 ] = x
  36.     coordinates[name].y[ #coordinates[name].y + 1 ] = y
  37. end
  38.  
  39. -- Is only used if you decide to build JUST ONE BUILDING, MANUALLY
  40. function build_it(number, id, name, team) --player ID, name of the table to build, choose team of the object to spawn
  41.     local number, id = tonumber(number), tonumber(id)
  42.     if not coordinates[name] then
  43.         print("©255000000Error! Table coordinates["..name.."] doesn't exist! [build_it]")
  44.         return false
  45.     end
  46.    
  47.     local TileX = coordinates[name].x[number] + player(id,"tilex")
  48.     local TileY = coordinates[name].y[number] + player(id,"tiley")
  49.     local buildingID = coordinates[name].building_type
  50.    
  51.     if not team then --if the team isn't given, take player's team
  52.         team = player(id, "team")
  53.     end
  54.    
  55.     if not entity(TileX, TileY, "exists") then
  56.         parse("spawnobject "..buildingID.." "..TileX.." "..TileY.." 0 0 "..team.." "..id)
  57.     end
  58. end
  59.  
  60. function build_all(id, name, team)
  61.     if not coordinates[name] then
  62.         print("©255000000Error! Table coordinates["..name.."] doesn't exist! [build_all]")
  63.         return false
  64.     end
  65.    
  66.     for k,v in pairs(coordinates[name].x) do --FOR EVERY ENTRY in table BUILD THE BUILDING
  67.         build_it(k, id, name, team) -- k is the key
  68.     end
  69. end
Add Comment
Please, Sign In to add comment