Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function onSave()
- saved_data = JSON.encode({started=hasGameStarted})
- return saved_data
- end
- function onload(saved_data)
- --Loads the tracking for if the game has started yet
- if saved_data ~= "" then
- local loaded_data = JSON.decode(saved_data)
- hasGameStarted = loaded_data.started
- else
- hasGameStarted = false
- end
- --Disables interactable status of objects with GUID in list
- for _, guid in ipairs(interactableList_off) do
- local obj = getObjectFromGUID(guid)
- if obj then obj.interactable = false end
- end
- --Activates shuffling if the game hasn't started
- if hasGameStarted == false then
- startLuaCoroutine(Global, "shuffleObjects")
- end
- getObjectFromGUID("a9fe45").createButton({
- label="Select\nFirst\nViking\nTokens", click_function="selectVikingToken",
- function_owner=nil, position={6.8,0,0.7}, height=400, width=300, font_size=75
- })
- math.randomseed(os.time())
- end
- --Shuffle coroutine which will shuffle all objects in a guid list
- function shuffleObjects()
- wait(1)
- for _, guid in ipairs(guidListToShuffle) do
- local obj = getObjectFromGUID(guid)
- if obj then
- obj.shuffle()
- wait(0.3)
- end
- end
- broadcastToAll("All decks have been shuffled.", {1,0.9,0.9})
- return 1
- end
- --Activated by button press, selects 2 starting
- function selectVikingToken(o, c)
- vikingTokenGuidList, vikingTokenList = shuffle(vikingTokenGuidList), {}
- for i, guid in ipairs(vikingTokenGuidList) do
- vikingTokenList[i] = getObjectFromGUID(guid)
- vikingTokenList[i].setLock(true)
- vikingTokenList[i].setRotation({0,0,0})
- end
- vikingTokenList[1].setPositionSmooth({-2.1,4,0.5})
- vikingTokenList[2].setPositionSmooth({-4.1,4,3.5})
- vikingTokenList[3].setPositionSmooth({-0.1,4,3.5})
- hasGameStarted = true
- o.clearButtons()
- startLuaCoroutine(Global, "finalizeVikingTokenPlacement")
- end
- --Coroutine to place items down
- function finalizeVikingTokenPlacement()
- for _, token in ipairs(vikingTokenList) do
- while token.isSmoothMoving() == true do
- coroutine.yield(0)
- end
- end
- wait(0.1)
- vikingTokenList[1].setPositionSmooth({-5.19, 1.40, 3.98})
- vikingTokenList[2].setPositionSmooth({-3.89, 1.40, 8.30})
- vikingTokenList[3].setPositionSmooth({-17.00, 1.04, 1.45})
- for _, token in ipairs(vikingTokenList) do
- token.setLock(false)
- end
- broadcastToAll("Tokens selected and placed.", {1,0.9,0.9})
- return 1
- end
- --Delay function forces yield until X time has elapsed
- function wait(time)
- local start = os.time()
- repeat coroutine.yield(0) until os.time() > start + time
- end
- --Shuffles entries in an array style table
- function shuffle(tbl)
- local size = #tbl
- for i = size, 1, -1 do
- local rand = math.random(size)
- tbl[i], tbl[rand] = tbl[rand], tbl[i]
- end
- return tbl
- end
- --List of objects that are set to not be interactable
- interactableList_off = {
- "c12643","b8bca4","59043a","4bda60","0ca464","c087ba","dc5174","7a7a3b",
- "56b623","d691bf","1663d9","23ce4d","193a63","ad5aa0","35cfd1","a868a6",
- "212033", "e2ec59", "f6db89", "fef019", "47d44d", "90517a", "a9fe45"
- }
- guidListToShuffle = {
- "93fa99","a89645","f2f558","5a95fd","0d1146"
- }
- vikingTokenGuidList = {
- "d006cf", "5a666f", "49f82e"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement