Advertisement
MrStump

Odin possible script

Apr 25th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.44 KB | None | 0 0
  1. function onSave()
  2.     saved_data = JSON.encode({started=hasGameStarted})
  3.     return saved_data
  4. end
  5.  
  6. function onload(saved_data)
  7.     --Loads the tracking for if the game has started yet
  8.     if saved_data ~= "" then
  9.         local loaded_data = JSON.decode(saved_data)
  10.         hasGameStarted = loaded_data.started
  11.     else
  12.         hasGameStarted = false
  13.     end
  14.  
  15.     --Disables interactable status of objects with GUID in list
  16.     for _, guid in ipairs(interactableList_off) do
  17.         local obj = getObjectFromGUID(guid)
  18.         if obj then obj.interactable = false end
  19.     end
  20.  
  21.     --Activates shuffling if the game hasn't started
  22.     if hasGameStarted == false then
  23.         startLuaCoroutine(Global, "shuffleObjects")
  24.     end
  25.  
  26.     getObjectFromGUID("a9fe45").createButton({
  27.         label="Select\nFirst\nViking\nTokens", click_function="selectVikingToken",
  28.         function_owner=nil, position={6.8,0,0.7}, height=400, width=300, font_size=75
  29.     })
  30.  
  31.     math.randomseed(os.time())
  32. end
  33.  
  34. --Shuffle coroutine which will shuffle all objects in a guid list
  35. function shuffleObjects()
  36.     wait(1)
  37.     for _, guid in ipairs(guidListToShuffle) do
  38.         local obj = getObjectFromGUID(guid)
  39.         if obj then
  40.             obj.shuffle()
  41.             wait(0.3)
  42.         end
  43.     end
  44.     broadcastToAll("All decks have been shuffled.", {1,0.9,0.9})
  45.     return 1
  46. end
  47.  
  48. --Activated by button press, selects 2 starting
  49. function selectVikingToken(o, c)
  50.     vikingTokenGuidList, vikingTokenList = shuffle(vikingTokenGuidList), {}
  51.     for i, guid in ipairs(vikingTokenGuidList) do
  52.         vikingTokenList[i] = getObjectFromGUID(guid)
  53.         vikingTokenList[i].setLock(true)
  54.         vikingTokenList[i].setRotation({0,0,0})
  55.     end
  56.  
  57.     vikingTokenList[1].setPositionSmooth({-2.1,4,0.5})
  58.     vikingTokenList[2].setPositionSmooth({-4.1,4,3.5})
  59.     vikingTokenList[3].setPositionSmooth({-0.1,4,3.5})
  60.  
  61.     hasGameStarted = true
  62.     o.clearButtons()
  63.     startLuaCoroutine(Global, "finalizeVikingTokenPlacement")
  64. end
  65.  
  66. --Coroutine to place items down
  67. function finalizeVikingTokenPlacement()
  68.     for _, token in ipairs(vikingTokenList) do
  69.         while token.isSmoothMoving() == true do
  70.             coroutine.yield(0)
  71.         end
  72.     end
  73.     wait(0.1)
  74.     vikingTokenList[1].setPositionSmooth({-5.19, 1.40, 3.98})
  75.     vikingTokenList[2].setPositionSmooth({-3.89, 1.40, 8.30})
  76.     vikingTokenList[3].setPositionSmooth({-17.00, 1.04, 1.45})
  77.     for _, token in ipairs(vikingTokenList) do
  78.         token.setLock(false)
  79.     end
  80.     broadcastToAll("Tokens selected and placed.", {1,0.9,0.9})
  81.     return 1
  82. end
  83.  
  84.  
  85. --Delay function forces yield until X time has elapsed
  86. function wait(time)
  87.     local start = os.time()
  88.     repeat coroutine.yield(0) until os.time() > start + time
  89. end
  90.  
  91. --Shuffles entries in an array style table
  92. function shuffle(tbl)
  93.     local size = #tbl
  94.     for i = size, 1, -1 do
  95.         local rand = math.random(size)
  96.         tbl[i], tbl[rand] = tbl[rand], tbl[i]
  97.     end
  98.     return tbl
  99. end
  100.  
  101. --List of objects that are set to not be interactable
  102. interactableList_off = {
  103.     "c12643","b8bca4","59043a","4bda60","0ca464","c087ba","dc5174","7a7a3b",
  104.     "56b623","d691bf","1663d9","23ce4d","193a63","ad5aa0","35cfd1","a868a6",
  105.     "212033", "e2ec59", "f6db89", "fef019", "47d44d", "90517a", "a9fe45"
  106. }
  107.  
  108. guidListToShuffle = {
  109.     "93fa99","a89645","f2f558","5a95fd","0d1146"
  110. }
  111.  
  112. vikingTokenGuidList = {
  113.     "d006cf", "5a666f", "49f82e"
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement