SHARE
TWEET

Untitled

a guest May 23rd, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --A player presses their Done button.
  2. function done(obj, player)
  3.   --Check if the correct player clicked the button.
  4.   local active = string.sub(obj.guid, 2, 2)
  5.   if player != colors['n'..active] then
  6.     broadcastToColor('Sorry, but '..playername(active)..' must place this Done button.', player, 'Red')
  7.     return
  8.   end
  9.   local value = getstate('b00009')
  10.   --Make sure the tile number is at least two digits long.
  11.   if string.len(value) < 2 then
  12.     value='0'..value
  13.   end
  14.   local bagguid = 'b'..active..'0001'
  15.   local bagobj = getObjectFromGUID(bagguid)
  16.   local tileguid = 'c'..active..'00'..value
  17.   local tile = getObjectFromGUID(tileguid)
  18.   if not tile then
  19.     bagobj.clearButtons()
  20.     local found = false
  21.     for j = 1, 6 do
  22.       local guid = 'b'..j..'0001'
  23.       if checkbag(guid, tileguid) then
  24.         found = true
  25.         local obj = getObjectFromGUID(bagguid)
  26.         local take = {}
  27.         take.position = pos
  28.         take.rotation = rot
  29.         take.guid = tileguid
  30.         take.smooth = true
  31.         take.callback_function = nil
  32.         obj.takeObject(take)
  33.       end
  34.     end
  35.     if found then
  36.       broadcastToColor('Sorry, something went wrong. Please try again.', player, 'Red')
  37.     else
  38.       broadcastToColor('Sorry, but I cannot find tile '..tonumber(value)..'.', player, 'Red')
  39.       setstate('b'..active..'0001', 0)
  40.       tilecheck()
  41.     end
  42.     return
  43.   end
  44.   --Check the position the tile would be placed at.
  45.   local dashboard = getObjectFromGUID('d'..active..'0001')
  46.   local pos = dashboard.positionToLocal(tile.getPosition())
  47.   local spot = 0
  48.   local xgap = (tiles.p33.x - tiles.p22.x) / 2
  49.   local zgap = (tiles.p33.z - tiles.p22.z) / 2
  50.   for i = 2, 7 do
  51.     if pos.x > (tiles['p2'..i].x + xgap) then
  52.       if pos.x < (tiles['p2'..i].x - xgap) then
  53.         for j = 2, 6 do
  54.           if pos.z > (tiles['p'..j..i].z - zgap) then
  55.             if pos.z < (tiles['p'..j..i].z + zgap) then
  56.               spot = tonumber(j..i)
  57.             end
  58.           end
  59.         end
  60.       end
  61.     end
  62.   end
  63.   if spot == 0 then
  64.     broadcastToColor('Sorry, but tile '..tonumber(value)..' is not placed on your Dashboard.', player, 'Red')
  65.     return
  66.   end
  67.   --Check if any of the player's tiles are already placed on that spot.
  68.   for i = 1, 9 do
  69.     if spot == getstate('c'..active..'000'..i) then
  70.       broadcastToColor('Sorry, but you cannot place two tiles on top of each other.', player, 'Red')
  71.       return
  72.     end
  73.   end
  74.   for i = 10, 38 do
  75.     if spot == getstate('c'..active..'00'..i) then
  76.       broadcastToColor('Sorry, but you cannot place two tiles on top of each other.', player, 'Red')
  77.       return
  78.     end
  79.   end
  80.   --Place the tile.
  81.   pos = dashboard.positionToWorld(tiles['p'..spot])
  82.   local rot = dashboard.getRotation()
  83.   tile.setPositionSmooth(pos)
  84.   tile.setRotationSmooth(rot)
  85.   tile.setLock(true)
  86.   tile.interactable = false
  87.   tile.script_state = spot
  88.   bagobj.script_state = 0
  89.   --Check if lava needs to be placed.
  90.   local lava = false
  91.   if getstate('c'..active..'0037') == spot - 10 then
  92.     lava = true
  93.   elseif getstate('c'..active..'0037') == spot - 1 then
  94.     lava = true
  95.   elseif getstate('c'..active..'0037') == spot + 1 then
  96.     lava = true
  97.   elseif getstate('c'..active..'0037') == spot + 10 then
  98.     lava = true
  99.   elseif getstate('c'..active..'0038') == spot - 10 then
  100.     lava = true
  101.   elseif getstate('c'..active..'0038') == spot - 1 then
  102.     lava = true
  103.   elseif getstate('c'..active..'0038') == spot + 1 then
  104.     lava = true
  105.   elseif getstate('c'..active..'0038') == spot + 10 then
  106.     lava = true
  107.   end
  108.   spot = spot + (100 * active)
  109.   --Place lava.
  110.   if lava then
  111.     local lavapos = pos
  112.     lavapos.y = 5
  113.     takefrombag('b00004', '', lavapos, rot, true, true, spot)
  114.   end
  115.   --Place a crystal or goldnugget.
  116.   pos.y = 1.5
  117.   if tile.getVar('special') == 'crystal' then
  118.     takefrombag('b00002', '', pos, rot, true, true, spot)
  119.   elseif tile.getVar('special') == 'goldnugget' then
  120.     takefrombag('b00003', '', pos, rot, true, true, spot)
  121.   end
  122.   tilecheck()
  123. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top