Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --A player presses their Done button.
- function done(obj, player)
- --Check if the correct player clicked the button.
- local active = string.sub(obj.guid, 2, 2)
- if player != colors['n'..active] then
- broadcastToColor('Sorry, but '..playername(active)..' must place this Done button.', player, 'Red')
- return
- end
- local value = getstate('b00009')
- --Make sure the tile number is at least two digits long.
- if string.len(value) < 2 then
- value='0'..value
- end
- local bagguid = 'b'..active..'0001'
- local bagobj = getObjectFromGUID(bagguid)
- local tileguid = 'c'..active..'00'..value
- local tile = getObjectFromGUID(tileguid)
- if not tile then
- bagobj.clearButtons()
- local found = false
- for j = 1, 6 do
- local guid = 'b'..j..'0001'
- if checkbag(guid, tileguid) then
- found = true
- local obj = getObjectFromGUID(bagguid)
- local take = {}
- take.position = pos
- take.rotation = rot
- take.guid = tileguid
- take.smooth = true
- take.callback_function = nil
- obj.takeObject(take)
- end
- end
- if found then
- broadcastToColor('Sorry, something went wrong. Please try again.', player, 'Red')
- else
- broadcastToColor('Sorry, but I cannot find tile '..tonumber(value)..'.', player, 'Red')
- setstate('b'..active..'0001', 0)
- tilecheck()
- end
- return
- end
- --Check the position the tile would be placed at.
- local dashboard = getObjectFromGUID('d'..active..'0001')
- local pos = dashboard.positionToLocal(tile.getPosition())
- local spot = 0
- local xgap = (tiles.p33.x - tiles.p22.x) / 2
- local zgap = (tiles.p33.z - tiles.p22.z) / 2
- for i = 2, 7 do
- if pos.x > (tiles['p2'..i].x + xgap) then
- if pos.x < (tiles['p2'..i].x - xgap) then
- for j = 2, 6 do
- if pos.z > (tiles['p'..j..i].z - zgap) then
- if pos.z < (tiles['p'..j..i].z + zgap) then
- spot = tonumber(j..i)
- end
- end
- end
- end
- end
- end
- if spot == 0 then
- broadcastToColor('Sorry, but tile '..tonumber(value)..' is not placed on your Dashboard.', player, 'Red')
- return
- end
- --Check if any of the player's tiles are already placed on that spot.
- for i = 1, 9 do
- if spot == getstate('c'..active..'000'..i) then
- broadcastToColor('Sorry, but you cannot place two tiles on top of each other.', player, 'Red')
- return
- end
- end
- for i = 10, 38 do
- if spot == getstate('c'..active..'00'..i) then
- broadcastToColor('Sorry, but you cannot place two tiles on top of each other.', player, 'Red')
- return
- end
- end
- --Place the tile.
- pos = dashboard.positionToWorld(tiles['p'..spot])
- local rot = dashboard.getRotation()
- tile.setPositionSmooth(pos)
- tile.setRotationSmooth(rot)
- tile.setLock(true)
- tile.interactable = false
- tile.script_state = spot
- bagobj.script_state = 0
- --Check if lava needs to be placed.
- local lava = false
- if getstate('c'..active..'0037') == spot - 10 then
- lava = true
- elseif getstate('c'..active..'0037') == spot - 1 then
- lava = true
- elseif getstate('c'..active..'0037') == spot + 1 then
- lava = true
- elseif getstate('c'..active..'0037') == spot + 10 then
- lava = true
- elseif getstate('c'..active..'0038') == spot - 10 then
- lava = true
- elseif getstate('c'..active..'0038') == spot - 1 then
- lava = true
- elseif getstate('c'..active..'0038') == spot + 1 then
- lava = true
- elseif getstate('c'..active..'0038') == spot + 10 then
- lava = true
- end
- spot = spot + (100 * active)
- --Place lava.
- if lava then
- local lavapos = pos
- lavapos.y = 5
- takefrombag('b00004', '', lavapos, rot, true, true, spot)
- end
- --Place a crystal or goldnugget.
- pos.y = 1.5
- if tile.getVar('special') == 'crystal' then
- takefrombag('b00002', '', pos, rot, true, true, spot)
- elseif tile.getVar('special') == 'goldnugget' then
- takefrombag('b00003', '', pos, rot, true, true, spot)
- end
- tilecheck()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement