Advertisement
MrStump

Untitled

Aug 16th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.67 KB | None | 0 0
  1. --If you set this to true it will add a table of fake players
  2. debugGame = false
  3.  
  4. function onload()
  5.     --startLuaCoroutine(Global, "boneFix") --Do not enable
  6.     --startLuaCoroutine(Global, "setupBones") --Do not enable
  7.  
  8.     --Disables interactable status of objects with GUID in list
  9.     for _, guid in ipairs(interactableList_off) do
  10.         local obj = getObjectFromGUID(guid)
  11.         if obj then obj.interactable = false end
  12.     end
  13.  
  14.     bag_bones = getObjectFromGUID("4b725f")
  15.     gameBoard = getObjectFromGUID("ef7e3c")
  16.     deck_dino = getObjectFromGUID("5a37ec")
  17.     deck_pale = getObjectFromGUID("c3e85e")
  18.     paleToken = getObjectFromGUID("c0f732")
  19.  
  20.     local hiderButton = getObjectFromGUID("c282c9")
  21.     if hiderButton ~= nil then
  22.         hiderButton.reload()
  23.     end
  24.  
  25.     spawnGameButtons()
  26. end
  27.  
  28.  
  29.  
  30. --Game start setup
  31.  
  32.  
  33.  
  34. --Button click to begin game
  35. function click_start(obj)
  36.     function coroutine_click_start()
  37.         local seatedPlayers = getSeatedPlayers()
  38.         if debugGame == true then seatedPlayers = {"Red", "White", "Yellow", "Blue", "Green"} end
  39.         if #seatedPlayers < 2 then
  40.             broadcastToAll("This game requestes at least 2 players!", {0.9,0.1,0.1})
  41.         else
  42.             obj.clearButtons()
  43.             local paleRandom = paleToken.getVar("paleRandom")
  44.             obj.AssetBundle.playLoopingEffect(3)
  45.             obj.AssetBundle.playTriggerEffect(1)
  46.             --Shuffle Palentologists, dino cards, bone bag
  47.             broadcastToAll("Shuffling Decks and Bone Bag", {1,1,1})
  48.             if bag_bones ~= nil then bag_bones.shuffle() wait(0.5) end
  49.             if deck_dino ~= nil then deck_dino.shuffle() wait(0.5) end
  50.             destroyObject(obj)
  51.             destroyObject(paleToken)
  52.             if deck_pale ~= nil then deck_pale.shuffle() wait(0.5) end
  53.  
  54.             --Deal palentolgists
  55.             broadcastToAll("Dealing Starting Items", {1,1,1})
  56.             if paleRandom == true then
  57.                 --Random palentolgists
  58.                 for _, color in ipairs(seatedPlayers) do
  59.                     local pos = ref_paleCards[color].pos
  60.                     local rot = ref_paleCards[color].rot
  61.                     deck_pale.takeObject({position=pos, rotation=rot})
  62.                     wait(0.2)
  63.                 end
  64.             else
  65.                 deck_pale.setPositionSmooth({-6.29, 1.8, 2.90})
  66.                 deck_pale.setRotationSmooth({0,0,180})
  67.             end
  68.  
  69.             --Deal 2 dinosaur cards
  70.             for _, color in ipairs(seatedPlayers) do
  71.                 deck_dino.deal(1, color)
  72.                 wait(0.15)
  73.                 deck_dino.deal(1, color)
  74.                 wait(0.25)
  75.             end
  76.  
  77.             --Deal player bones
  78.             for _, playerPad in ipairs(ref_playerBoneSpawn.pad) do
  79.                 for _, seatColor in ipairs(seatedPlayers) do
  80.                     if seatColor == playerPad.color then
  81.                         local pad = getObjectFromGUID(playerPad.guid)
  82.                         for i=1, 7 do
  83.                             local pos_local = ref_playerBoneSpawn.pos[i]
  84.                             local pos = pad.positionToWorld(pos_local)
  85.                             local rot = pad.getRotation()
  86.                             rot.y = rot.y + 90
  87.                             for _, bone in ipairs(bag_bones.getObjects()) do
  88.                                 if bone.name == ref_playerBoneSpawn.type[i] then
  89.                                     bag_bones.takeObject({
  90.                                         position=pos,
  91.                                         rotation=rot,
  92.                                         guid=bone.guid
  93.                                     })
  94.                                     wait(0.05)
  95.                                     break
  96.                                 end
  97.                             end
  98.                         end
  99.                     end
  100.                 end
  101.             end
  102.  
  103.             --Deal starting board bones
  104.             broadcastToAll("Placing Bones in the World", {1,1,1})
  105.             bag_bones.shuffle()
  106.             wait(0.01)
  107.  
  108.             zOffset = 0.1
  109.             rot = gameBoard.getRotation()
  110.  
  111.             if #seatedPlayers >= 4 then
  112.                 for _, pos_local in ipairs(ref_hexSpot_4) do
  113.                     pos_local[2] = pos_local[2]+0.06
  114.                     pos_local[3] = pos_local[3]-zOffset
  115.                     for i=1, 3 do
  116.                         local pos = gameBoard.positionToWorld(pos_local)
  117.                         bag_bones.takeObject({position=pos, rotation=rot})
  118.                         pos_local[3] = pos_local[3]+zOffset
  119.                         wait(0.05)
  120.                     end
  121.                 end
  122.             end
  123.  
  124.             for _, pos_local in ipairs(ref_hexSpot_all) do
  125.                 pos_local[2] = pos_local[2]+0.06
  126.                 pos_local[3] = pos_local[3]-zOffset
  127.                 for i=1, 3 do
  128.                     local pos = gameBoard.positionToWorld(pos_local)
  129.                     bag_bones.takeObject({position=pos, rotation=rot})
  130.                     pos_local[3] = pos_local[3]+zOffset
  131.                     wait(0.05)
  132.                 end
  133.             end
  134.  
  135.             if #seatedPlayers >= 5 then
  136.                 for _, pos_local in ipairs(ref_hexSpot_5) do
  137.                     pos_local[2] = pos_local[2]+0.06
  138.                     pos_local[3] = pos_local[3]-zOffset
  139.                     for i=1, 3 do
  140.                         local pos = gameBoard.positionToWorld(pos_local)
  141.                         bag_bones.takeObject({position=pos, rotation=rot})
  142.                         pos_local[3] = pos_local[3]+zOffset
  143.                         wait(0.05)
  144.                     end
  145.                 end
  146.             end
  147.  
  148.             --Place score cube on track
  149.             local scorePos = {-12.42, 1.43, -3.63}
  150.             for _, color in ipairs(seatedPlayers) do
  151.                 if ref_scoreCubes[color] ~= nil then
  152.                     local cube = getObjectFromGUID(ref_scoreCubes[color])
  153.                     cube.setPositionSmooth(scorePos)
  154.                     scorePos[2] = scorePos[2] + 0.55
  155.                 end
  156.             end
  157.  
  158.             wait(0.4)
  159.             if paleRandom == true then
  160.                 broadcastToAll("Choose a first player and begin.", {1,1,1})
  161.             else
  162.                 broadcastToAll("Choose paleontologists, pick a first player and begin.", {1,1,1})
  163.             end
  164.         end
  165.  
  166.  
  167.         return 1
  168.     end
  169.     startLuaCoroutine(Global, "coroutine_click_start")
  170. end
  171.  
  172.  
  173. --Hidden zone manipulation
  174.  
  175.  
  176.  
  177. --Button click to hide/reveal
  178. function click_hiddenMove(button, color)
  179.     function coroutine_click_hiddenMove()
  180.         if hide_lockout ~= true then
  181.             hide_lockout = true
  182.             local loopID = button.AssetBundle.getLoopingEffectIndex()
  183.             if loopID == 1 then
  184.                 --Hide
  185.                 button.AssetBundle.playLoopingEffect(2)
  186.                 button.AssetBundle.playTriggerEffect(1)
  187.                 local hex = RGBToBracketedHex(stringColorToRGB(color))
  188.                 broadcastToAll(hex..Player[color].steam_name.."[-] has pressed [i]Hide[/i].", {1,1,1})
  189.                 for _, zoneGUID in ipairs(ref_hiddenZones) do
  190.                     local zone = getObjectFromGUID(zoneGUID)
  191.                     local pos = zone.getPosition()
  192.                     zone.setPositionSmooth({pos.x,3.50,pos.z})
  193.                     wait(0.15)
  194.                 end
  195.             elseif loopID == 2 then
  196.                 --Show
  197.                 button.AssetBundle.playLoopingEffect(1)
  198.                 button.AssetBundle.playTriggerEffect(1)
  199.                 local hex = RGBToBracketedHex(stringColorToRGB(color))
  200.                 broadcastToAll(hex..Player[color].steam_name.."[-] has pressed [i]Show[/i].", {1,1,1})
  201.                 for _, zoneGUID in ipairs(ref_hiddenZones) do
  202.                     local zone = getObjectFromGUID(zoneGUID)
  203.                     local pos = zone.getPosition()
  204.                     zone.setPositionSmooth({pos.x,-5,pos.z})
  205.                     wait(0.15)
  206.                 end
  207.             end
  208.             wait(0.2)
  209.             hide_lockout = false
  210.         end
  211.  
  212.         return 1
  213.     end
  214.     startLuaCoroutine(Global, "coroutine_click_hiddenMove")
  215. end
  216.  
  217.  
  218.  
  219. --Utility functions
  220.  
  221.  
  222.  
  223. --Coroutine delay, in seconds
  224. function wait(time)
  225.     local start = os.time()
  226.     repeat coroutine.yield(0) until os.time() > start + time
  227. end
  228.  
  229. --Converts an RGB table into bracketed hex (bb font coloring)
  230. function RGBToBracketedHex(rgb)
  231.     if rgb ~= nil then
  232.         return "[" .. string.format("%02x%02x%02x", rgb.r*255,rgb.g*255,rgb.b*255) .. "]"
  233.     else
  234.         return ""
  235.     end
  236. end
  237.  
  238.  
  239.  
  240. --Button creation
  241.  
  242.  
  243.  
  244. function spawnGameButtons()
  245.     --Fog-hider button
  246.     button_showHide = getObjectFromGUID("c282c9")
  247.     if button_showHide ~= nil then
  248.         button_showHide.createButton({
  249.             click_function="click_hiddenMove", function_owner=Global,
  250.             position={0,1,0}, rotation={0,0,0}, height=1500, width=1500
  251.         })
  252.     end
  253.     --Start button
  254.     button_start = getObjectFromGUID("faafaa")
  255.     if button_start ~= nil then
  256.         button_start.createButton({
  257.             click_function="click_start", function_owner=Global,
  258.             position={0,1,0}, rotation={0,0,0}, height=1500, width=1500
  259.         })
  260.     end
  261. end
  262.  
  263.  
  264.  
  265. --Data tables
  266.  
  267.  
  268.  
  269. --Items non-interactable (by guid)
  270. interactableList_off = {
  271.     "0d2505",
  272. }
  273.  
  274. --Hidden zones (fogOfWarTrigger) (by guid)
  275. ref_hiddenZones = {
  276.     "405ca1", "3962c7", "775c85", "c6f89d", "066fa5",
  277. }
  278.  
  279. --For giving players their starting bones
  280. ref_playerBoneSpawn = {
  281.     pad = {
  282.         {guid="f3d98a", color="Red"},
  283.         {guid="a70fe4", color="White"},
  284.         {guid="79ae07", color="Yellow"},
  285.         {guid="6d1aaa", color="Blue"},
  286.         {guid="7b3f40", color="Green"},
  287.     },
  288.     pos = {
  289.         {0.407, 0.083, -0.073}, {0.14, 0.085, -0.09},
  290.         {-0.151, 0.089, -0.073}, {-0.45, 0.076, -0.086},
  291.         {0.267, 0.093, 0.11}, {-0.022, 0.088, 0.113}, {-0.299, 0.083, 0.106}
  292.     },
  293.     type = {
  294.         "Red Bone", "Red Bone", "Yellow Bone", "Yellow Bone",
  295.         "Green Bone", "Green Bone", "Green Bone"
  296.     }
  297. }
  298.  
  299. --For placing bones onto the board (for all game types, 1 row per line)
  300. ref_hexSpot_all = {
  301.     {1.711, 0.1, 0.001}, {0.852, 0.1, 0}, {-0.868, 0.1, -0.001}, {-1.727, 0.1, -0.001},
  302.     {1.281, 0.1, 0.745}, {-0.438, 0.1, 0.744}, {-1.298, 0.1, 0.743},
  303.     {1.711, 0.1, 1.489}, {0.851, 0.1, 1.489}, {-0.009, 0.1, 1.489}, {-0.868, 0.1, 1.488}, {-1.728, 0.1, 1.488},
  304.     {1.28, 0.1, 2.234}, {0.421, 0.1, 2.233}, {-1.298, 0.1, 2.232},
  305.     {1.71, 0.1, 2.978}, {-0.009, 0.1, 2.977}, {-0.869, 0.1, 2.977}, {-1.729, 0.1, 2.977},
  306. }
  307.  
  308. --For placing more bones onto the board (for games of 4 or 5)
  309. ref_hexSpot_4 = {
  310.     {1.282, 0.1, -0.744}, {0.422, 0.1, -0.745},
  311.     {-0.437, 0.1, -0.745}, {-1.297, 0.1, -0.745}
  312. }
  313.  
  314. --For placing more bones onto the board (for games of 5)
  315. ref_hexSpot_5 = {
  316.     {1.28, 0.1, 3.723}, {0.42, 0.1, 3.722},
  317.     {-0.44, 0.1, 3.722}, {-1.299, 0.1, 3.721},
  318. }
  319.  
  320. ref_scoreCubes = {
  321.     ["Red"] = "21caf4",
  322.     ["White"] = "9f3a83",
  323.     ["Yellow"] = "1641f8",
  324.     ["Blue"] = "af0766",
  325.     ["Green"] = "64520e",
  326. }
  327.  
  328. ref_paleCards = {
  329.     ["Red"] = {pos={0.49, 0.70, -12.94}, rot={0,90,0}},
  330.     ["White"] = {pos={20.66, 0.70, -13.06}, rot={0,90,0}},
  331.     ["Yellow"] = {pos={20.58, 0.70, 8.15}, rot={0,180,0}},
  332.     ["Blue"] = {pos={10.51, 0.70, 17.48}, rot={0,270,0}},
  333.     ["Green"] = {pos={-10.45, 0.70, 17.37}, rot={0,270,0}},
  334. }
  335.  
  336. --[[ This function was only used to remove sticky and tooltip from bones.
  337. function boneFix()
  338.     local bag = getObjectFromGUID("4b725f")
  339.     local theBones = {}
  340.     for _, bone in ipairs(bag.getObjects()) do
  341.         local spawnedBone = bag.takeObject({position={0,10,0}})
  342.         wait(0.01)
  343.         spawnedBone.setLock(true)
  344.         spawnedBone.sticky = false
  345.         spawnedBone.tooltip = false
  346.         table.insert(theBones, spawnedBone)
  347.     end
  348.     wait(2)
  349.     for _, bone in ipairs(theBones) do
  350.         bone.setLock(false)
  351.         bag.putObject(bone)
  352.         wait(0.01)
  353.     end
  354.     return 1
  355. end
  356. --Round number (num) to the Nth decimal (dec)
  357. function round(num, dec)
  358.   local mult = 10^(dec or 0)
  359.   return math.floor(num * mult + 0.5) / mult
  360. end
  361. ]]
  362.  
  363. --[[ This function was used to find the centerpoint of each (valid) grid space
  364. function setupBones()
  365.     while true do
  366.         gameBoard = getObjectFromGUID("ef7e3c")
  367.         setupTile = getObjectFromGUID("0f4cc2")
  368.         local pos = gameBoard.positionToLocal(setupTile.getPosition())
  369.  
  370.         setNotes("{"..round(pos.x,3)..", "..round(pos.y,3)..", "..round(pos.z,3).."}, ")
  371.         wait(0.5)
  372.     end
  373.     return 1
  374. end
  375. ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement