Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- coordinates = {
- barr = {
- building_type = 1,
- x = {4,2,1,3},
- y = {-1,3,-4,1}
- }
- }
- add_building("turrets", 8, 1, 1)
- add_building("turrets", 8, -1, 1)
- add_building("turrets", 8, 1, -1)
- add_building("turrets", 8, -1, -1)
- add_building("gates", 6, -1, 0)
- add_building("gates", 6, 1, 0)
- add_building("gates", 6, 0, 1)
- add_building("gates", 6, 0, -1)
- function add_building(name, buildType, x, y) --preset name, building ID, x and y offset (tiles)
- local buildType, x, y = tonumber(buildType), tonumber(x), tonumber(y)
- if not coordinates[name] then --create a table inside if doesn't exist
- coordinates[name] = {}
- coordinates[name].building_type = buildType
- coordinates[name].x = {}
- coordinates[name].y = {}
- end
- if coordinates[name].building_type ~= buildType then --only 1 type of buildings per table allowed
- print("©255000000Error! Failed to add building type: \""..buildType.."\" to the existing type: "..coordinates[name].building_type)
- return false
- end
- --insert the given coordinates to the table
- coordinates[name].x[ #coordinates[name].x + 1 ] = x
- coordinates[name].y[ #coordinates[name].y + 1 ] = y
- end
- -- Is only used if you decide to build JUST ONE BUILDING, MANUALLY
- function build_it(number, id, name, team) --player ID, name of the table to build, choose team of the object to spawn
- local number, id = tonumber(number), tonumber(id)
- if not coordinates[name] then
- print("©255000000Error! Table coordinates["..name.."] doesn't exist! [build_it]")
- return false
- end
- local TileX = coordinates[name].x[number] + player(id,"tilex")
- local TileY = coordinates[name].y[number] + player(id,"tiley")
- local buildingID = coordinates[name].building_type
- if not team then --if the team isn't given, take player's team
- team = player(id, "team")
- end
- if not entity(TileX, TileY, "exists") then
- parse("spawnobject "..buildingID.." "..TileX.." "..TileY.." 0 0 "..team.." "..id)
- end
- end
- function build_all(id, name, team)
- if not coordinates[name] then
- print("©255000000Error! Table coordinates["..name.."] doesn't exist! [build_all]")
- return false
- end
- for k,v in pairs(coordinates[name].x) do --FOR EVERY ENTRY in table BUILD THE BUILDING
- build_it(k, id, name, team) -- k is the key
- end
- end
Add Comment
Please, Sign In to add comment