SaveNameAshes Reborn Memory DeckboxesEpochTime}`Date5/14/2021 9:40:53 AMVersionNumberv13.1.1GameModeAshes Reborn Memory DeckboxesGameTypeObjectsGameComplexityPlayingTime01PlayerCounts01Tagsj0 Board Games1 Card Games2 Dice Games3Cards4 Components5EnglishGravity?PlayArea?Table Table_RPGSky Sky_RegalNoteTabStatesN0mtitleRulesbodycolorGreyvisibleColor&r?g?b?id1ntitleWhitebodycolorWhitevisibleColor&r?g?b?id2ntitleBrownbodycolorBrownvisibleColor&rZ?gh?b= ?id3jtitleRedbodycolorRedvisibleColor&r Zd?g?b@b?id4ptitleOrangebodycolorOrangevisibleColor&r@?g ?b`?id5ptitleYellowbodycolorYellowvisibleColor&r?gj?b?id6ntitleGreenbodycolorGreenvisibleColor&rt?gn?b ?id7ltitleBluebodycolorBluevisibleColor&r?5?g?b?id8ltitleTealbodycolorTealvisibleColor&r`?g?5?b@l?id9ptitlePurplebodycolorPurplevisibleColor&r@b?g?b?id 10ltitlePinkbodycolorPinkvisibleColor&rQ?g?b?id 11ntitleBlackbodycolorBlackvisibleColor&r?g?b?id GridTypeLinesColor&rgbOpacity?ThickLinesSnappingOffsetBothSnappingxSize`ff @ySize`ff @PosOffset&xy?zLightingwLightIntensity@_?LightColor&r?go_?b|?AmbientIntensity`?AmbientTypeAmbientSkyColor&r?g?b?AmbientEquatorColor&r?g?b?AmbientGroundColor&r?g?b?ReflectionIntensity?LutIndexLutContribution?LutURLHands*EnableDisableUnusedHidingComponentTagslabelsTurns`EnableTypeTurnOrderReverseSkipEmptyDisableInteractionsPassTurnsDecalPalletLuaScriptA--[[ Lua code. See documentation: https://api.tabletopsimulator.com/ --]] --[[ The onLoad event is called after the game save finishes loading. --]] function onLoad() --[[ print('onLoad!') --]] end --[[ The onUpdate event is called once per frame. --]] function onUpdate() --[[ print('onUpdate loop!') --]] endLuaScriptStateXmlUIRObjectStatesv0n'GUIDa8f382NameCustom_Model_BagTransformposX`ff @posYࠗ@posZL%rotX`f>rotYೀf@rotZғ>scaleX@scaleY?scaleZ@Nickname Deck NameDescriptionGMNotesColorDiffuse&r?g Ϳ?b?LayoutGroupSortIndexValueLockedGridSnapIgnoreFoWMeasureMovementDragSelectableAutoraiseStickyTooltipGridProjectionHideWhenFaceDownHandsMaterialIndexMeshIndexNumberCustomMeshMeshURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126265930592/04FC7B7EB48D30899FF8B0C2B310B61364B90E81/DiffuseURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126266540862/344EA0D8F4C83B8AB4866CADD338881BF3CEF12D/NormalURLColliderURLConvexMaterialIndexTypeIndexCustomShaderSpecularColor&r?g?b?SpecularIntensitySpecularSharpness@FresnelStrengthCastShadowsBagOrderLuaScript#function updateSave() local data_to_save = {["ml"]=memoryList} saved_data = JSON.encode(data_to_save) self.script_state = saved_data end function onload(saved_data) if saved_data ~= "" then local loaded_data = JSON.decode(saved_data) --Set up information off of loaded_data memoryList = loaded_data.ml else --Set up information for if there is no saved saved data memoryList = {} end if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end end --Beginning Setup --Make setup button function createSetupButton() self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Triggered by setup button, function buttonClick_setup() memoryListBackup = duplicateTable(memoryList) memoryList = {} self.clearButtons() createButtonsOnAllObjects() createSetupActionButtons() end --Creates selection buttons on objects function createButtonsOnAllObjects() local howManyButtons = 0 for _, obj in ipairs(getAllObjects()) do if obj ~= self then local dummyIndex = howManyButtons --On a normal bag, the button positions aren't the same size as the bag. globalScaleFactor = 1 * 1/self.getScale().x --Super sweet math to set button positions local selfPos = self.getPosition() local objPos = obj.getPosition() local deltaPos = findOffsetDistance(selfPos, objPos, obj) local objPos = rotateLocalCoordinates(deltaPos, self) objPos.x = -objPos.x * globalScaleFactor objPos.y = objPos.y * globalScaleFactor objPos.z = objPos.z * globalScaleFactor --Offset rotation of bag local rot = self.getRotation() rot.y = -rot.y + 180 --Create function local funcName = "selectButton_" .. howManyButtons local func = function() buttonClick_selection(dummyIndex, obj) end self.setVar(funcName, func) self.createButton({ click_function=funcName, function_owner=self, position=objPos, rotation=rot, height=1000, width=1000, color={0.75,0.25,0.25,0.6}, }) howManyButtons = howManyButtons + 1 end end end --Creates submit and cancel buttons function createSetupActionButtons() self.createButton({ label="Cancel", click_function="buttonClick_cancel", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Submit", click_function="buttonClick_submit", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Reset", click_function="buttonClick_reset", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --During Setup --Checks or unchecks buttons function buttonClick_selection(index, obj) local color = {0,1,0,0.6} if memoryList[obj.getGUID()] == nil then self.editButton({index=index, color=color}) --Adding pos/rot to memory table local pos, rot = obj.getPosition(), obj.getRotation() --I need to add it like this or it won't save due to indexing issue memoryList[obj.getGUID()] = { pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, lock=obj.getLock() } obj.highlightOn({0,1,0}) else color = {0.75,0.25,0.25,0.6} self.editButton({index=index, color=color}) memoryList[obj.getGUID()] = nil obj.highlightOff() end end --Cancels selection process function buttonClick_cancel() memoryList = memoryListBackup self.clearButtons() if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end removeAllHighlights() broadcastToAll("Selection Canceled", {1,1,1}) end --Saves selections function buttonClick_submit() if next(memoryList) == nil then broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) else self.clearButtons() createMemoryActionButtons() local count = 0 for guid in pairs(memoryList) do count = count + 1 local obj = getObjectFromGUID(guid) if obj ~= nil then obj.highlightOff() end end broadcastToAll(count.." Objects Saved", {1,1,1}) updateSave() end end --Resets bag to starting status function buttonClick_reset() memoryList = {} self.clearButtons() createSetupButton() removeAllHighlights() broadcastToAll("Tool Reset", {1,1,1}) updateSave() end --After Setup --Creates recall and place buttons function createMemoryActionButtons() self.createButton({ label="Place", click_function="buttonClick_place", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Recall", click_function="buttonClick_recall", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Sends objects from bag/table to their saved position/rotation function buttonClick_place() local bagObjList = self.getObjects() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) --If obj is out on the table, move it to the saved pos/rot if obj ~= nil then obj.setPositionSmooth(entry.pos) obj.setRotationSmooth(entry.rot) obj.setLock(entry.lock) else --If obj is inside of the bag for _, bagObj in ipairs(bagObjList) do if bagObj.guid == guid then local item = self.takeObject({ guid=guid, position=entry.pos, rotation=entry.rot, }) item.setLock(entry.lock) break end end end end broadcastToAll("Objects Placed", {1,1,1}) end --Recalls objects to bag from table function buttonClick_recall() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) if obj ~= nil then self.putObject(obj) end end broadcastToAll("Objects Recalled", {1,1,1}) end --Utility functions --Find delta (difference) between 2 x/y/z coordinates function findOffsetDistance(p1, p2, obj) local deltaPos = {} local bounds = obj.getBounds() deltaPos.x = (p2.x-p1.x) deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) deltaPos.z = (p2.z-p1.z) return deltaPos end --Used to rotate a set of coordinates by an angle function rotateLocalCoordinates(desiredPos, obj) local objPos, objRot = obj.getPosition(), obj.getRotation() local angle = math.rad(objRot.y) local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} return {x=x, y=desiredPos.y, z=z} end --Coroutine delay, in seconds function wait(time) local start = os.time() repeat coroutine.yield(0) until os.time() > start + time end --Duplicates a table (needed to prevent it making reference to the same objects) function duplicateTable(oldTable) local newTable = {} for k, v in pairs(oldTable) do newTable[k] = v end return newTable end --Moves scripted highlight from all objects function removeAllHighlights() for _, obj in ipairs(getAllObjects()) do obj.highlightOff() end end --Round number (num) to the Nth decimal (dec) function round(num, dec) local mult = 10^(dec or 0) return math.floor(num * mult + 0.5) / mult end LuaScriptState {"ml":[]}XmlUI1e'GUID699655NameCustom_Model_BagTransformposXL5@posYࠗ@posZrotX@&SrotYf@rotZ 0SyscaleX@scaleY?scaleZ@Nickname Deck NameDescriptionGMNotesColorDiffuse&r?g Ϳ?b?LayoutGroupSortIndexValueLockedGridSnapIgnoreFoWMeasureMovementDragSelectableAutoraiseStickyTooltipGridProjectionHideWhenFaceDownHandsMaterialIndexMeshIndexNumberCustomMeshMeshURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126265930592/04FC7B7EB48D30899FF8B0C2B310B61364B90E81/DiffuseURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126266543957/EDF94AF972286069E289F9746DEC40821569D425/NormalURLColliderURLConvexMaterialIndexTypeIndexCustomShaderSpecularColor&r?g?b?SpecularIntensitySpecularSharpness@FresnelStrengthCastShadowsBagOrderLuaScript#function updateSave() local data_to_save = {["ml"]=memoryList} saved_data = JSON.encode(data_to_save) self.script_state = saved_data end function onload(saved_data) if saved_data ~= "" then local loaded_data = JSON.decode(saved_data) --Set up information off of loaded_data memoryList = loaded_data.ml else --Set up information for if there is no saved saved data memoryList = {} end if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end end --Beginning Setup --Make setup button function createSetupButton() self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Triggered by setup button, function buttonClick_setup() memoryListBackup = duplicateTable(memoryList) memoryList = {} self.clearButtons() createButtonsOnAllObjects() createSetupActionButtons() end --Creates selection buttons on objects function createButtonsOnAllObjects() local howManyButtons = 0 for _, obj in ipairs(getAllObjects()) do if obj ~= self then local dummyIndex = howManyButtons --On a normal bag, the button positions aren't the same size as the bag. globalScaleFactor = 1 * 1/self.getScale().x --Super sweet math to set button positions local selfPos = self.getPosition() local objPos = obj.getPosition() local deltaPos = findOffsetDistance(selfPos, objPos, obj) local objPos = rotateLocalCoordinates(deltaPos, self) objPos.x = -objPos.x * globalScaleFactor objPos.y = objPos.y * globalScaleFactor objPos.z = objPos.z * globalScaleFactor --Offset rotation of bag local rot = self.getRotation() rot.y = -rot.y + 180 --Create function local funcName = "selectButton_" .. howManyButtons local func = function() buttonClick_selection(dummyIndex, obj) end self.setVar(funcName, func) self.createButton({ click_function=funcName, function_owner=self, position=objPos, rotation=rot, height=1000, width=1000, color={0.75,0.25,0.25,0.6}, }) howManyButtons = howManyButtons + 1 end end end --Creates submit and cancel buttons function createSetupActionButtons() self.createButton({ label="Cancel", click_function="buttonClick_cancel", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Submit", click_function="buttonClick_submit", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Reset", click_function="buttonClick_reset", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --During Setup --Checks or unchecks buttons function buttonClick_selection(index, obj) local color = {0,1,0,0.6} if memoryList[obj.getGUID()] == nil then self.editButton({index=index, color=color}) --Adding pos/rot to memory table local pos, rot = obj.getPosition(), obj.getRotation() --I need to add it like this or it won't save due to indexing issue memoryList[obj.getGUID()] = { pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, lock=obj.getLock() } obj.highlightOn({0,1,0}) else color = {0.75,0.25,0.25,0.6} self.editButton({index=index, color=color}) memoryList[obj.getGUID()] = nil obj.highlightOff() end end --Cancels selection process function buttonClick_cancel() memoryList = memoryListBackup self.clearButtons() if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end removeAllHighlights() broadcastToAll("Selection Canceled", {1,1,1}) end --Saves selections function buttonClick_submit() if next(memoryList) == nil then broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) else self.clearButtons() createMemoryActionButtons() local count = 0 for guid in pairs(memoryList) do count = count + 1 local obj = getObjectFromGUID(guid) if obj ~= nil then obj.highlightOff() end end broadcastToAll(count.." Objects Saved", {1,1,1}) updateSave() end end --Resets bag to starting status function buttonClick_reset() memoryList = {} self.clearButtons() createSetupButton() removeAllHighlights() broadcastToAll("Tool Reset", {1,1,1}) updateSave() end --After Setup --Creates recall and place buttons function createMemoryActionButtons() self.createButton({ label="Place", click_function="buttonClick_place", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Recall", click_function="buttonClick_recall", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Sends objects from bag/table to their saved position/rotation function buttonClick_place() local bagObjList = self.getObjects() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) --If obj is out on the table, move it to the saved pos/rot if obj ~= nil then obj.setPositionSmooth(entry.pos) obj.setRotationSmooth(entry.rot) obj.setLock(entry.lock) else --If obj is inside of the bag for _, bagObj in ipairs(bagObjList) do if bagObj.guid == guid then local item = self.takeObject({ guid=guid, position=entry.pos, rotation=entry.rot, }) item.setLock(entry.lock) break end end end end broadcastToAll("Objects Placed", {1,1,1}) end --Recalls objects to bag from table function buttonClick_recall() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) if obj ~= nil then self.putObject(obj) end end broadcastToAll("Objects Recalled", {1,1,1}) end --Utility functions --Find delta (difference) between 2 x/y/z coordinates function findOffsetDistance(p1, p2, obj) local deltaPos = {} local bounds = obj.getBounds() deltaPos.x = (p2.x-p1.x) deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) deltaPos.z = (p2.z-p1.z) return deltaPos end --Used to rotate a set of coordinates by an angle function rotateLocalCoordinates(desiredPos, obj) local objPos, objRot = obj.getPosition(), obj.getRotation() local angle = math.rad(objRot.y) local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} return {x=x, y=desiredPos.y, z=z} end --Coroutine delay, in seconds function wait(time) local start = os.time() repeat coroutine.yield(0) until os.time() > start + time end --Duplicates a table (needed to prevent it making reference to the same objects) function duplicateTable(oldTable) local newTable = {} for k, v in pairs(oldTable) do newTable[k] = v end return newTable end --Moves scripted highlight from all objects function removeAllHighlights() for _, obj in ipairs(getAllObjects()) do obj.highlightOff() end end --Round number (num) to the Nth decimal (dec) function round(num, dec) local mult = 10^(dec or 0) return math.floor(num * mult + 0.5) / mult end LuaScriptStateXmlUI2e'GUID3074a9NameCustom_Model_BagTransformposX`ff posYࠗ@posZL%rotX;(rotYf@rotZ Ҧ>scaleX@scaleY?scaleZ@Nickname Deck NameDescriptionGMNotesColorDiffuse&r?g Ϳ?b?LayoutGroupSortIndexValueLockedGridSnapIgnoreFoWMeasureMovementDragSelectableAutoraiseStickyTooltipGridProjectionHideWhenFaceDownHandsMaterialIndexMeshIndexNumberCustomMeshMeshURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126265930592/04FC7B7EB48D30899FF8B0C2B310B61364B90E81/DiffuseURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126266541382/5971BB02F221A3C5C61BCC21B16B2979165EACC6/NormalURLColliderURLConvexMaterialIndexTypeIndexCustomShaderSpecularColor&r?g?b?SpecularIntensitySpecularSharpness@FresnelStrengthCastShadowsBagOrderLuaScript#function updateSave() local data_to_save = {["ml"]=memoryList} saved_data = JSON.encode(data_to_save) self.script_state = saved_data end function onload(saved_data) if saved_data ~= "" then local loaded_data = JSON.decode(saved_data) --Set up information off of loaded_data memoryList = loaded_data.ml else --Set up information for if there is no saved saved data memoryList = {} end if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end end --Beginning Setup --Make setup button function createSetupButton() self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Triggered by setup button, function buttonClick_setup() memoryListBackup = duplicateTable(memoryList) memoryList = {} self.clearButtons() createButtonsOnAllObjects() createSetupActionButtons() end --Creates selection buttons on objects function createButtonsOnAllObjects() local howManyButtons = 0 for _, obj in ipairs(getAllObjects()) do if obj ~= self then local dummyIndex = howManyButtons --On a normal bag, the button positions aren't the same size as the bag. globalScaleFactor = 1 * 1/self.getScale().x --Super sweet math to set button positions local selfPos = self.getPosition() local objPos = obj.getPosition() local deltaPos = findOffsetDistance(selfPos, objPos, obj) local objPos = rotateLocalCoordinates(deltaPos, self) objPos.x = -objPos.x * globalScaleFactor objPos.y = objPos.y * globalScaleFactor objPos.z = objPos.z * globalScaleFactor --Offset rotation of bag local rot = self.getRotation() rot.y = -rot.y + 180 --Create function local funcName = "selectButton_" .. howManyButtons local func = function() buttonClick_selection(dummyIndex, obj) end self.setVar(funcName, func) self.createButton({ click_function=funcName, function_owner=self, position=objPos, rotation=rot, height=1000, width=1000, color={0.75,0.25,0.25,0.6}, }) howManyButtons = howManyButtons + 1 end end end --Creates submit and cancel buttons function createSetupActionButtons() self.createButton({ label="Cancel", click_function="buttonClick_cancel", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Submit", click_function="buttonClick_submit", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Reset", click_function="buttonClick_reset", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --During Setup --Checks or unchecks buttons function buttonClick_selection(index, obj) local color = {0,1,0,0.6} if memoryList[obj.getGUID()] == nil then self.editButton({index=index, color=color}) --Adding pos/rot to memory table local pos, rot = obj.getPosition(), obj.getRotation() --I need to add it like this or it won't save due to indexing issue memoryList[obj.getGUID()] = { pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, lock=obj.getLock() } obj.highlightOn({0,1,0}) else color = {0.75,0.25,0.25,0.6} self.editButton({index=index, color=color}) memoryList[obj.getGUID()] = nil obj.highlightOff() end end --Cancels selection process function buttonClick_cancel() memoryList = memoryListBackup self.clearButtons() if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end removeAllHighlights() broadcastToAll("Selection Canceled", {1,1,1}) end --Saves selections function buttonClick_submit() if next(memoryList) == nil then broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) else self.clearButtons() createMemoryActionButtons() local count = 0 for guid in pairs(memoryList) do count = count + 1 local obj = getObjectFromGUID(guid) if obj ~= nil then obj.highlightOff() end end broadcastToAll(count.." Objects Saved", {1,1,1}) updateSave() end end --Resets bag to starting status function buttonClick_reset() memoryList = {} self.clearButtons() createSetupButton() removeAllHighlights() broadcastToAll("Tool Reset", {1,1,1}) updateSave() end --After Setup --Creates recall and place buttons function createMemoryActionButtons() self.createButton({ label="Place", click_function="buttonClick_place", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Recall", click_function="buttonClick_recall", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Sends objects from bag/table to their saved position/rotation function buttonClick_place() local bagObjList = self.getObjects() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) --If obj is out on the table, move it to the saved pos/rot if obj ~= nil then obj.setPositionSmooth(entry.pos) obj.setRotationSmooth(entry.rot) obj.setLock(entry.lock) else --If obj is inside of the bag for _, bagObj in ipairs(bagObjList) do if bagObj.guid == guid then local item = self.takeObject({ guid=guid, position=entry.pos, rotation=entry.rot, }) item.setLock(entry.lock) break end end end end broadcastToAll("Objects Placed", {1,1,1}) end --Recalls objects to bag from table function buttonClick_recall() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) if obj ~= nil then self.putObject(obj) end end broadcastToAll("Objects Recalled", {1,1,1}) end --Utility functions --Find delta (difference) between 2 x/y/z coordinates function findOffsetDistance(p1, p2, obj) local deltaPos = {} local bounds = obj.getBounds() deltaPos.x = (p2.x-p1.x) deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) deltaPos.z = (p2.z-p1.z) return deltaPos end --Used to rotate a set of coordinates by an angle function rotateLocalCoordinates(desiredPos, obj) local objPos, objRot = obj.getPosition(), obj.getRotation() local angle = math.rad(objRot.y) local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} return {x=x, y=desiredPos.y, z=z} end --Coroutine delay, in seconds function wait(time) local start = os.time() repeat coroutine.yield(0) until os.time() > start + time end --Duplicates a table (needed to prevent it making reference to the same objects) function duplicateTable(oldTable) local newTable = {} for k, v in pairs(oldTable) do newTable[k] = v end return newTable end --Moves scripted highlight from all objects function removeAllHighlights() for _, obj in ipairs(getAllObjects()) do obj.highlightOff() end end --Round number (num) to the Nth decimal (dec) function round(num, dec) local mult = 10^(dec or 0) return math.floor(num * mult + 0.5) / mult end LuaScriptStateXmlUI3e'GUID12741eNameCustom_Model_BagTransformposXL5@posY@posZL%@rotX`OrotYȀf@rotZ,>scaleX@scaleY?scaleZ@Nickname Deck NameDescriptionGMNotesColorDiffuse&r?g Ϳ?b?LayoutGroupSortIndexValueLockedGridSnapIgnoreFoWMeasureMovementDragSelectableAutoraiseStickyTooltipGridProjectionHideWhenFaceDownHandsMaterialIndexMeshIndexNumberCustomMeshMeshURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126265930592/04FC7B7EB48D30899FF8B0C2B310B61364B90E81/DiffuseURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126266543884/70C1967AAFBEAD18233E569F1BA8B9BBCDD0A1FB/NormalURLColliderURLConvexMaterialIndexTypeIndexCustomShaderSpecularColor&r?g?b?SpecularIntensitySpecularSharpness@FresnelStrengthCastShadowsBagOrderLuaScript#function updateSave() local data_to_save = {["ml"]=memoryList} saved_data = JSON.encode(data_to_save) self.script_state = saved_data end function onload(saved_data) if saved_data ~= "" then local loaded_data = JSON.decode(saved_data) --Set up information off of loaded_data memoryList = loaded_data.ml else --Set up information for if there is no saved saved data memoryList = {} end if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end end --Beginning Setup --Make setup button function createSetupButton() self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Triggered by setup button, function buttonClick_setup() memoryListBackup = duplicateTable(memoryList) memoryList = {} self.clearButtons() createButtonsOnAllObjects() createSetupActionButtons() end --Creates selection buttons on objects function createButtonsOnAllObjects() local howManyButtons = 0 for _, obj in ipairs(getAllObjects()) do if obj ~= self then local dummyIndex = howManyButtons --On a normal bag, the button positions aren't the same size as the bag. globalScaleFactor = 1 * 1/self.getScale().x --Super sweet math to set button positions local selfPos = self.getPosition() local objPos = obj.getPosition() local deltaPos = findOffsetDistance(selfPos, objPos, obj) local objPos = rotateLocalCoordinates(deltaPos, self) objPos.x = -objPos.x * globalScaleFactor objPos.y = objPos.y * globalScaleFactor objPos.z = objPos.z * globalScaleFactor --Offset rotation of bag local rot = self.getRotation() rot.y = -rot.y + 180 --Create function local funcName = "selectButton_" .. howManyButtons local func = function() buttonClick_selection(dummyIndex, obj) end self.setVar(funcName, func) self.createButton({ click_function=funcName, function_owner=self, position=objPos, rotation=rot, height=1000, width=1000, color={0.75,0.25,0.25,0.6}, }) howManyButtons = howManyButtons + 1 end end end --Creates submit and cancel buttons function createSetupActionButtons() self.createButton({ label="Cancel", click_function="buttonClick_cancel", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Submit", click_function="buttonClick_submit", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Reset", click_function="buttonClick_reset", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --During Setup --Checks or unchecks buttons function buttonClick_selection(index, obj) local color = {0,1,0,0.6} if memoryList[obj.getGUID()] == nil then self.editButton({index=index, color=color}) --Adding pos/rot to memory table local pos, rot = obj.getPosition(), obj.getRotation() --I need to add it like this or it won't save due to indexing issue memoryList[obj.getGUID()] = { pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, lock=obj.getLock() } obj.highlightOn({0,1,0}) else color = {0.75,0.25,0.25,0.6} self.editButton({index=index, color=color}) memoryList[obj.getGUID()] = nil obj.highlightOff() end end --Cancels selection process function buttonClick_cancel() memoryList = memoryListBackup self.clearButtons() if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end removeAllHighlights() broadcastToAll("Selection Canceled", {1,1,1}) end --Saves selections function buttonClick_submit() if next(memoryList) == nil then broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) else self.clearButtons() createMemoryActionButtons() local count = 0 for guid in pairs(memoryList) do count = count + 1 local obj = getObjectFromGUID(guid) if obj ~= nil then obj.highlightOff() end end broadcastToAll(count.." Objects Saved", {1,1,1}) updateSave() end end --Resets bag to starting status function buttonClick_reset() memoryList = {} self.clearButtons() createSetupButton() removeAllHighlights() broadcastToAll("Tool Reset", {1,1,1}) updateSave() end --After Setup --Creates recall and place buttons function createMemoryActionButtons() self.createButton({ label="Place", click_function="buttonClick_place", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Recall", click_function="buttonClick_recall", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Sends objects from bag/table to their saved position/rotation function buttonClick_place() local bagObjList = self.getObjects() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) --If obj is out on the table, move it to the saved pos/rot if obj ~= nil then obj.setPositionSmooth(entry.pos) obj.setRotationSmooth(entry.rot) obj.setLock(entry.lock) else --If obj is inside of the bag for _, bagObj in ipairs(bagObjList) do if bagObj.guid == guid then local item = self.takeObject({ guid=guid, position=entry.pos, rotation=entry.rot, }) item.setLock(entry.lock) break end end end end broadcastToAll("Objects Placed", {1,1,1}) end --Recalls objects to bag from table function buttonClick_recall() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) if obj ~= nil then self.putObject(obj) end end broadcastToAll("Objects Recalled", {1,1,1}) end --Utility functions --Find delta (difference) between 2 x/y/z coordinates function findOffsetDistance(p1, p2, obj) local deltaPos = {} local bounds = obj.getBounds() deltaPos.x = (p2.x-p1.x) deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) deltaPos.z = (p2.z-p1.z) return deltaPos end --Used to rotate a set of coordinates by an angle function rotateLocalCoordinates(desiredPos, obj) local objPos, objRot = obj.getPosition(), obj.getRotation() local angle = math.rad(objRot.y) local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} return {x=x, y=desiredPos.y, z=z} end --Coroutine delay, in seconds function wait(time) local start = os.time() repeat coroutine.yield(0) until os.time() > start + time end --Duplicates a table (needed to prevent it making reference to the same objects) function duplicateTable(oldTable) local newTable = {} for k, v in pairs(oldTable) do newTable[k] = v end return newTable end --Moves scripted highlight from all objects function removeAllHighlights() for _, obj in ipairs(getAllObjects()) do obj.highlightOff() end end --Round number (num) to the Nth decimal (dec) function round(num, dec) local mult = 10^(dec or 0) return math.floor(num * mult + 0.5) / mult end LuaScriptStateXmlUI4e'GUID823475NameCustom_Model_BagTransformposX`ff@posYࠗ@posZrotX`Q>rotY f@rotZ@~QbscaleX@scaleY?scaleZ@Nickname Deck NameDescriptionGMNotesColorDiffuse&r?g Ϳ?b?LayoutGroupSortIndexValueLockedGridSnapIgnoreFoWMeasureMovementDragSelectableAutoraiseStickyTooltipGridProjectionHideWhenFaceDownHandsMaterialIndexMeshIndexNumberCustomMeshMeshURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126265930592/04FC7B7EB48D30899FF8B0C2B310B61364B90E81/DiffuseURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126266759491/B828E60ECDB45F2FB79E2829D6EBB12B274C0C03/NormalURLColliderURLConvexMaterialIndexTypeIndexCustomShaderSpecularColor&r?g?b?SpecularIntensitySpecularSharpness@FresnelStrengthCastShadowsBagOrderLuaScript#function updateSave() local data_to_save = {["ml"]=memoryList} saved_data = JSON.encode(data_to_save) self.script_state = saved_data end function onload(saved_data) if saved_data ~= "" then local loaded_data = JSON.decode(saved_data) --Set up information off of loaded_data memoryList = loaded_data.ml else --Set up information for if there is no saved saved data memoryList = {} end if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end end --Beginning Setup --Make setup button function createSetupButton() self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Triggered by setup button, function buttonClick_setup() memoryListBackup = duplicateTable(memoryList) memoryList = {} self.clearButtons() createButtonsOnAllObjects() createSetupActionButtons() end --Creates selection buttons on objects function createButtonsOnAllObjects() local howManyButtons = 0 for _, obj in ipairs(getAllObjects()) do if obj ~= self then local dummyIndex = howManyButtons --On a normal bag, the button positions aren't the same size as the bag. globalScaleFactor = 1 * 1/self.getScale().x --Super sweet math to set button positions local selfPos = self.getPosition() local objPos = obj.getPosition() local deltaPos = findOffsetDistance(selfPos, objPos, obj) local objPos = rotateLocalCoordinates(deltaPos, self) objPos.x = -objPos.x * globalScaleFactor objPos.y = objPos.y * globalScaleFactor objPos.z = objPos.z * globalScaleFactor --Offset rotation of bag local rot = self.getRotation() rot.y = -rot.y + 180 --Create function local funcName = "selectButton_" .. howManyButtons local func = function() buttonClick_selection(dummyIndex, obj) end self.setVar(funcName, func) self.createButton({ click_function=funcName, function_owner=self, position=objPos, rotation=rot, height=1000, width=1000, color={0.75,0.25,0.25,0.6}, }) howManyButtons = howManyButtons + 1 end end end --Creates submit and cancel buttons function createSetupActionButtons() self.createButton({ label="Cancel", click_function="buttonClick_cancel", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Submit", click_function="buttonClick_submit", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Reset", click_function="buttonClick_reset", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --During Setup --Checks or unchecks buttons function buttonClick_selection(index, obj) local color = {0,1,0,0.6} if memoryList[obj.getGUID()] == nil then self.editButton({index=index, color=color}) --Adding pos/rot to memory table local pos, rot = obj.getPosition(), obj.getRotation() --I need to add it like this or it won't save due to indexing issue memoryList[obj.getGUID()] = { pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, lock=obj.getLock() } obj.highlightOn({0,1,0}) else color = {0.75,0.25,0.25,0.6} self.editButton({index=index, color=color}) memoryList[obj.getGUID()] = nil obj.highlightOff() end end --Cancels selection process function buttonClick_cancel() memoryList = memoryListBackup self.clearButtons() if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end removeAllHighlights() broadcastToAll("Selection Canceled", {1,1,1}) end --Saves selections function buttonClick_submit() if next(memoryList) == nil then broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) else self.clearButtons() createMemoryActionButtons() local count = 0 for guid in pairs(memoryList) do count = count + 1 local obj = getObjectFromGUID(guid) if obj ~= nil then obj.highlightOff() end end broadcastToAll(count.." Objects Saved", {1,1,1}) updateSave() end end --Resets bag to starting status function buttonClick_reset() memoryList = {} self.clearButtons() createSetupButton() removeAllHighlights() broadcastToAll("Tool Reset", {1,1,1}) updateSave() end --After Setup --Creates recall and place buttons function createMemoryActionButtons() self.createButton({ label="Place", click_function="buttonClick_place", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Recall", click_function="buttonClick_recall", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Sends objects from bag/table to their saved position/rotation function buttonClick_place() local bagObjList = self.getObjects() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) --If obj is out on the table, move it to the saved pos/rot if obj ~= nil then obj.setPositionSmooth(entry.pos) obj.setRotationSmooth(entry.rot) obj.setLock(entry.lock) else --If obj is inside of the bag for _, bagObj in ipairs(bagObjList) do if bagObj.guid == guid then local item = self.takeObject({ guid=guid, position=entry.pos, rotation=entry.rot, }) item.setLock(entry.lock) break end end end end broadcastToAll("Objects Placed", {1,1,1}) end --Recalls objects to bag from table function buttonClick_recall() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) if obj ~= nil then self.putObject(obj) end end broadcastToAll("Objects Recalled", {1,1,1}) end --Utility functions --Find delta (difference) between 2 x/y/z coordinates function findOffsetDistance(p1, p2, obj) local deltaPos = {} local bounds = obj.getBounds() deltaPos.x = (p2.x-p1.x) deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) deltaPos.z = (p2.z-p1.z) return deltaPos end --Used to rotate a set of coordinates by an angle function rotateLocalCoordinates(desiredPos, obj) local objPos, objRot = obj.getPosition(), obj.getRotation() local angle = math.rad(objRot.y) local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} return {x=x, y=desiredPos.y, z=z} end --Coroutine delay, in seconds function wait(time) local start = os.time() repeat coroutine.yield(0) until os.time() > start + time end --Duplicates a table (needed to prevent it making reference to the same objects) function duplicateTable(oldTable) local newTable = {} for k, v in pairs(oldTable) do newTable[k] = v end return newTable end --Moves scripted highlight from all objects function removeAllHighlights() for _, obj in ipairs(getAllObjects()) do obj.highlightOff() end end --Round number (num) to the Nth decimal (dec) function round(num, dec) local mult = 10^(dec or 0) return math.floor(num * mult + 0.5) / mult end LuaScriptStateXmlUI5e'GUIDd8a8fcNameCustom_Model_BagTransformposX`ff@posYࠗ@posZL%@rotX@ʌFrotY`Af@rotZ;n>scaleX@scaleY?scaleZ@Nickname Deck NameDescriptionGMNotesColorDiffuse&r?g Ϳ?b?LayoutGroupSortIndexValueLockedGridSnapIgnoreFoWMeasureMovementDragSelectableAutoraiseStickyTooltipGridProjectionHideWhenFaceDownHandsMaterialIndexMeshIndexNumberCustomMeshMeshURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126265930592/04FC7B7EB48D30899FF8B0C2B310B61364B90E81/DiffuseURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126266485260/A5A267428DF4745E61CDB4A5CB20C9C5AE55CED2/NormalURLColliderURLConvexMaterialIndexTypeIndexCustomShaderSpecularColor&r?g?b?SpecularIntensitySpecularSharpness@FresnelStrengthCastShadowsBagOrderLuaScript#function updateSave() local data_to_save = {["ml"]=memoryList} saved_data = JSON.encode(data_to_save) self.script_state = saved_data end function onload(saved_data) if saved_data ~= "" then local loaded_data = JSON.decode(saved_data) --Set up information off of loaded_data memoryList = loaded_data.ml else --Set up information for if there is no saved saved data memoryList = {} end if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end end --Beginning Setup --Make setup button function createSetupButton() self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Triggered by setup button, function buttonClick_setup() memoryListBackup = duplicateTable(memoryList) memoryList = {} self.clearButtons() createButtonsOnAllObjects() createSetupActionButtons() end --Creates selection buttons on objects function createButtonsOnAllObjects() local howManyButtons = 0 for _, obj in ipairs(getAllObjects()) do if obj ~= self then local dummyIndex = howManyButtons --On a normal bag, the button positions aren't the same size as the bag. globalScaleFactor = 1 * 1/self.getScale().x --Super sweet math to set button positions local selfPos = self.getPosition() local objPos = obj.getPosition() local deltaPos = findOffsetDistance(selfPos, objPos, obj) local objPos = rotateLocalCoordinates(deltaPos, self) objPos.x = -objPos.x * globalScaleFactor objPos.y = objPos.y * globalScaleFactor objPos.z = objPos.z * globalScaleFactor --Offset rotation of bag local rot = self.getRotation() rot.y = -rot.y + 180 --Create function local funcName = "selectButton_" .. howManyButtons local func = function() buttonClick_selection(dummyIndex, obj) end self.setVar(funcName, func) self.createButton({ click_function=funcName, function_owner=self, position=objPos, rotation=rot, height=1000, width=1000, color={0.75,0.25,0.25,0.6}, }) howManyButtons = howManyButtons + 1 end end end --Creates submit and cancel buttons function createSetupActionButtons() self.createButton({ label="Cancel", click_function="buttonClick_cancel", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Submit", click_function="buttonClick_submit", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Reset", click_function="buttonClick_reset", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --During Setup --Checks or unchecks buttons function buttonClick_selection(index, obj) local color = {0,1,0,0.6} if memoryList[obj.getGUID()] == nil then self.editButton({index=index, color=color}) --Adding pos/rot to memory table local pos, rot = obj.getPosition(), obj.getRotation() --I need to add it like this or it won't save due to indexing issue memoryList[obj.getGUID()] = { pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, lock=obj.getLock() } obj.highlightOn({0,1,0}) else color = {0.75,0.25,0.25,0.6} self.editButton({index=index, color=color}) memoryList[obj.getGUID()] = nil obj.highlightOff() end end --Cancels selection process function buttonClick_cancel() memoryList = memoryListBackup self.clearButtons() if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end removeAllHighlights() broadcastToAll("Selection Canceled", {1,1,1}) end --Saves selections function buttonClick_submit() if next(memoryList) == nil then broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) else self.clearButtons() createMemoryActionButtons() local count = 0 for guid in pairs(memoryList) do count = count + 1 local obj = getObjectFromGUID(guid) if obj ~= nil then obj.highlightOff() end end broadcastToAll(count.." Objects Saved", {1,1,1}) updateSave() end end --Resets bag to starting status function buttonClick_reset() memoryList = {} self.clearButtons() createSetupButton() removeAllHighlights() broadcastToAll("Tool Reset", {1,1,1}) updateSave() end --After Setup --Creates recall and place buttons function createMemoryActionButtons() self.createButton({ label="Place", click_function="buttonClick_place", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Recall", click_function="buttonClick_recall", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Sends objects from bag/table to their saved position/rotation function buttonClick_place() local bagObjList = self.getObjects() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) --If obj is out on the table, move it to the saved pos/rot if obj ~= nil then obj.setPositionSmooth(entry.pos) obj.setRotationSmooth(entry.rot) obj.setLock(entry.lock) else --If obj is inside of the bag for _, bagObj in ipairs(bagObjList) do if bagObj.guid == guid then local item = self.takeObject({ guid=guid, position=entry.pos, rotation=entry.rot, }) item.setLock(entry.lock) break end end end end broadcastToAll("Objects Placed", {1,1,1}) end --Recalls objects to bag from table function buttonClick_recall() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) if obj ~= nil then self.putObject(obj) end end broadcastToAll("Objects Recalled", {1,1,1}) end --Utility functions --Find delta (difference) between 2 x/y/z coordinates function findOffsetDistance(p1, p2, obj) local deltaPos = {} local bounds = obj.getBounds() deltaPos.x = (p2.x-p1.x) deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) deltaPos.z = (p2.z-p1.z) return deltaPos end --Used to rotate a set of coordinates by an angle function rotateLocalCoordinates(desiredPos, obj) local objPos, objRot = obj.getPosition(), obj.getRotation() local angle = math.rad(objRot.y) local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} return {x=x, y=desiredPos.y, z=z} end --Coroutine delay, in seconds function wait(time) local start = os.time() repeat coroutine.yield(0) until os.time() > start + time end --Duplicates a table (needed to prevent it making reference to the same objects) function duplicateTable(oldTable) local newTable = {} for k, v in pairs(oldTable) do newTable[k] = v end return newTable end --Moves scripted highlight from all objects function removeAllHighlights() for _, obj in ipairs(getAllObjects()) do obj.highlightOff() end end --Round number (num) to the Nth decimal (dec) function round(num, dec) local mult = 10^(dec or 0) return math.floor(num * mult + 0.5) / mult end LuaScriptStateXmlUI6e'GUID612a87NameCustom_Model_BagTransformposX`ff,@posY @posZrotXҸRrotYf@rotZ scaleX@scaleY`?scaleZ@Nickname Deck NameDescriptionGMNotesColorDiffuse&r?g Ϳ?b?LayoutGroupSortIndexValueLockedGridSnapIgnoreFoWMeasureMovementDragSelectableAutoraiseStickyTooltipGridProjectionHideWhenFaceDownHandsMaterialIndexMeshIndexNumberCustomMeshMeshURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126265930592/04FC7B7EB48D30899FF8B0C2B310B61364B90E81/DiffuseURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126266543508/5A92E5DC86D58E0CFE0C246692390762CB30834D/NormalURLColliderURLConvexMaterialIndexTypeIndexCustomShaderSpecularColor&r?g?b?SpecularIntensitySpecularSharpness@FresnelStrengthCastShadowsBagOrderLuaScript#function updateSave() local data_to_save = {["ml"]=memoryList} saved_data = JSON.encode(data_to_save) self.script_state = saved_data end function onload(saved_data) if saved_data ~= "" then local loaded_data = JSON.decode(saved_data) --Set up information off of loaded_data memoryList = loaded_data.ml else --Set up information for if there is no saved saved data memoryList = {} end if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end end --Beginning Setup --Make setup button function createSetupButton() self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Triggered by setup button, function buttonClick_setup() memoryListBackup = duplicateTable(memoryList) memoryList = {} self.clearButtons() createButtonsOnAllObjects() createSetupActionButtons() end --Creates selection buttons on objects function createButtonsOnAllObjects() local howManyButtons = 0 for _, obj in ipairs(getAllObjects()) do if obj ~= self then local dummyIndex = howManyButtons --On a normal bag, the button positions aren't the same size as the bag. globalScaleFactor = 1 * 1/self.getScale().x --Super sweet math to set button positions local selfPos = self.getPosition() local objPos = obj.getPosition() local deltaPos = findOffsetDistance(selfPos, objPos, obj) local objPos = rotateLocalCoordinates(deltaPos, self) objPos.x = -objPos.x * globalScaleFactor objPos.y = objPos.y * globalScaleFactor objPos.z = objPos.z * globalScaleFactor --Offset rotation of bag local rot = self.getRotation() rot.y = -rot.y + 180 --Create function local funcName = "selectButton_" .. howManyButtons local func = function() buttonClick_selection(dummyIndex, obj) end self.setVar(funcName, func) self.createButton({ click_function=funcName, function_owner=self, position=objPos, rotation=rot, height=1000, width=1000, color={0.75,0.25,0.25,0.6}, }) howManyButtons = howManyButtons + 1 end end end --Creates submit and cancel buttons function createSetupActionButtons() self.createButton({ label="Cancel", click_function="buttonClick_cancel", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Submit", click_function="buttonClick_submit", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Reset", click_function="buttonClick_reset", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --During Setup --Checks or unchecks buttons function buttonClick_selection(index, obj) local color = {0,1,0,0.6} if memoryList[obj.getGUID()] == nil then self.editButton({index=index, color=color}) --Adding pos/rot to memory table local pos, rot = obj.getPosition(), obj.getRotation() --I need to add it like this or it won't save due to indexing issue memoryList[obj.getGUID()] = { pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, lock=obj.getLock() } obj.highlightOn({0,1,0}) else color = {0.75,0.25,0.25,0.6} self.editButton({index=index, color=color}) memoryList[obj.getGUID()] = nil obj.highlightOff() end end --Cancels selection process function buttonClick_cancel() memoryList = memoryListBackup self.clearButtons() if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end removeAllHighlights() broadcastToAll("Selection Canceled", {1,1,1}) end --Saves selections function buttonClick_submit() if next(memoryList) == nil then broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) else self.clearButtons() createMemoryActionButtons() local count = 0 for guid in pairs(memoryList) do count = count + 1 local obj = getObjectFromGUID(guid) if obj ~= nil then obj.highlightOff() end end broadcastToAll(count.." Objects Saved", {1,1,1}) updateSave() end end --Resets bag to starting status function buttonClick_reset() memoryList = {} self.clearButtons() createSetupButton() removeAllHighlights() broadcastToAll("Tool Reset", {1,1,1}) updateSave() end --After Setup --Creates recall and place buttons function createMemoryActionButtons() self.createButton({ label="Place", click_function="buttonClick_place", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Recall", click_function="buttonClick_recall", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Sends objects from bag/table to their saved position/rotation function buttonClick_place() local bagObjList = self.getObjects() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) --If obj is out on the table, move it to the saved pos/rot if obj ~= nil then obj.setPositionSmooth(entry.pos) obj.setRotationSmooth(entry.rot) obj.setLock(entry.lock) else --If obj is inside of the bag for _, bagObj in ipairs(bagObjList) do if bagObj.guid == guid then local item = self.takeObject({ guid=guid, position=entry.pos, rotation=entry.rot, }) item.setLock(entry.lock) break end end end end broadcastToAll("Objects Placed", {1,1,1}) end --Recalls objects to bag from table function buttonClick_recall() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) if obj ~= nil then self.putObject(obj) end end broadcastToAll("Objects Recalled", {1,1,1}) end --Utility functions --Find delta (difference) between 2 x/y/z coordinates function findOffsetDistance(p1, p2, obj) local deltaPos = {} local bounds = obj.getBounds() deltaPos.x = (p2.x-p1.x) deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) deltaPos.z = (p2.z-p1.z) return deltaPos end --Used to rotate a set of coordinates by an angle function rotateLocalCoordinates(desiredPos, obj) local objPos, objRot = obj.getPosition(), obj.getRotation() local angle = math.rad(objRot.y) local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} return {x=x, y=desiredPos.y, z=z} end --Coroutine delay, in seconds function wait(time) local start = os.time() repeat coroutine.yield(0) until os.time() > start + time end --Duplicates a table (needed to prevent it making reference to the same objects) function duplicateTable(oldTable) local newTable = {} for k, v in pairs(oldTable) do newTable[k] = v end return newTable end --Moves scripted highlight from all objects function removeAllHighlights() for _, obj in ipairs(getAllObjects()) do obj.highlightOff() end end --Round number (num) to the Nth decimal (dec) function round(num, dec) local mult = 10^(dec or 0) return math.floor(num * mult + 0.5) / mult end LuaScriptStateXmlUI7e'GUIDe32accNameCustom_Model_BagTransformposX`ffposYࠗ@posZrotXCOrotYf@rotZ`1gscaleX@scaleY?scaleZ@Nickname Deck NameDescriptionGMNotesColorDiffuse&r?g?b?LayoutGroupSortIndexValueLockedGridSnapIgnoreFoWMeasureMovementDragSelectableAutoraiseStickyTooltipGridProjectionHideWhenFaceDownHandsMaterialIndexMeshIndexNumberCustomMeshMeshURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126265930592/04FC7B7EB48D30899FF8B0C2B310B61364B90E81/DiffuseURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126266543304/B2C6540DA05C53F7940987B9FBCB7D1C0F33941C/NormalURLColliderURLConvexMaterialIndexTypeIndexCustomShaderSpecularColor&r?g?b?SpecularIntensitySpecularSharpness@FresnelStrengthCastShadowsBagOrderLuaScript#function updateSave() local data_to_save = {["ml"]=memoryList} saved_data = JSON.encode(data_to_save) self.script_state = saved_data end function onload(saved_data) if saved_data ~= "" then local loaded_data = JSON.decode(saved_data) --Set up information off of loaded_data memoryList = loaded_data.ml else --Set up information for if there is no saved saved data memoryList = {} end if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end end --Beginning Setup --Make setup button function createSetupButton() self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Triggered by setup button, function buttonClick_setup() memoryListBackup = duplicateTable(memoryList) memoryList = {} self.clearButtons() createButtonsOnAllObjects() createSetupActionButtons() end --Creates selection buttons on objects function createButtonsOnAllObjects() local howManyButtons = 0 for _, obj in ipairs(getAllObjects()) do if obj ~= self then local dummyIndex = howManyButtons --On a normal bag, the button positions aren't the same size as the bag. globalScaleFactor = 1 * 1/self.getScale().x --Super sweet math to set button positions local selfPos = self.getPosition() local objPos = obj.getPosition() local deltaPos = findOffsetDistance(selfPos, objPos, obj) local objPos = rotateLocalCoordinates(deltaPos, self) objPos.x = -objPos.x * globalScaleFactor objPos.y = objPos.y * globalScaleFactor objPos.z = objPos.z * globalScaleFactor --Offset rotation of bag local rot = self.getRotation() rot.y = -rot.y + 180 --Create function local funcName = "selectButton_" .. howManyButtons local func = function() buttonClick_selection(dummyIndex, obj) end self.setVar(funcName, func) self.createButton({ click_function=funcName, function_owner=self, position=objPos, rotation=rot, height=1000, width=1000, color={0.75,0.25,0.25,0.6}, }) howManyButtons = howManyButtons + 1 end end end --Creates submit and cancel buttons function createSetupActionButtons() self.createButton({ label="Cancel", click_function="buttonClick_cancel", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Submit", click_function="buttonClick_submit", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Reset", click_function="buttonClick_reset", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --During Setup --Checks or unchecks buttons function buttonClick_selection(index, obj) local color = {0,1,0,0.6} if memoryList[obj.getGUID()] == nil then self.editButton({index=index, color=color}) --Adding pos/rot to memory table local pos, rot = obj.getPosition(), obj.getRotation() --I need to add it like this or it won't save due to indexing issue memoryList[obj.getGUID()] = { pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, lock=obj.getLock() } obj.highlightOn({0,1,0}) else color = {0.75,0.25,0.25,0.6} self.editButton({index=index, color=color}) memoryList[obj.getGUID()] = nil obj.highlightOff() end end --Cancels selection process function buttonClick_cancel() memoryList = memoryListBackup self.clearButtons() if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end removeAllHighlights() broadcastToAll("Selection Canceled", {1,1,1}) end --Saves selections function buttonClick_submit() if next(memoryList) == nil then broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) else self.clearButtons() createMemoryActionButtons() local count = 0 for guid in pairs(memoryList) do count = count + 1 local obj = getObjectFromGUID(guid) if obj ~= nil then obj.highlightOff() end end broadcastToAll(count.." Objects Saved", {1,1,1}) updateSave() end end --Resets bag to starting status function buttonClick_reset() memoryList = {} self.clearButtons() createSetupButton() removeAllHighlights() broadcastToAll("Tool Reset", {1,1,1}) updateSave() end --After Setup --Creates recall and place buttons function createMemoryActionButtons() self.createButton({ label="Place", click_function="buttonClick_place", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Recall", click_function="buttonClick_recall", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Sends objects from bag/table to their saved position/rotation function buttonClick_place() local bagObjList = self.getObjects() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) --If obj is out on the table, move it to the saved pos/rot if obj ~= nil then obj.setPositionSmooth(entry.pos) obj.setRotationSmooth(entry.rot) obj.setLock(entry.lock) else --If obj is inside of the bag for _, bagObj in ipairs(bagObjList) do if bagObj.guid == guid then local item = self.takeObject({ guid=guid, position=entry.pos, rotation=entry.rot, }) item.setLock(entry.lock) break end end end end broadcastToAll("Objects Placed", {1,1,1}) end --Recalls objects to bag from table function buttonClick_recall() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) if obj ~= nil then self.putObject(obj) end end broadcastToAll("Objects Recalled", {1,1,1}) end --Utility functions --Find delta (difference) between 2 x/y/z coordinates function findOffsetDistance(p1, p2, obj) local deltaPos = {} local bounds = obj.getBounds() deltaPos.x = (p2.x-p1.x) deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) deltaPos.z = (p2.z-p1.z) return deltaPos end --Used to rotate a set of coordinates by an angle function rotateLocalCoordinates(desiredPos, obj) local objPos, objRot = obj.getPosition(), obj.getRotation() local angle = math.rad(objRot.y) local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} return {x=x, y=desiredPos.y, z=z} end --Coroutine delay, in seconds function wait(time) local start = os.time() repeat coroutine.yield(0) until os.time() > start + time end --Duplicates a table (needed to prevent it making reference to the same objects) function duplicateTable(oldTable) local newTable = {} for k, v in pairs(oldTable) do newTable[k] = v end return newTable end --Moves scripted highlight from all objects function removeAllHighlights() for _, obj in ipairs(getAllObjects()) do obj.highlightOff() end end --Round number (num) to the Nth decimal (dec) function round(num, dec) local mult = 10^(dec or 0) return math.floor(num * mult + 0.5) / mult end LuaScriptStateXmlUI8e'GUID858130NameCustom_Model_BagTransformposXposYࠗ@posZL%@rotX>rotY?f@rotZ]*>scaleX@scaleY?scaleZ@Nickname Deck NameDescriptionGMNotesColorDiffuse&r?g Ϳ?b?LayoutGroupSortIndexValueLockedGridSnapIgnoreFoWMeasureMovementDragSelectableAutoraiseStickyTooltipGridProjectionHideWhenFaceDownHandsMaterialIndexMeshIndexNumberCustomMeshMeshURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126265930592/04FC7B7EB48D30899FF8B0C2B310B61364B90E81/DiffuseURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126266543581/3A55DFBF6C55D9FA0F07E3F55191232B8BFB58A4/NormalURLColliderURLConvexMaterialIndexTypeIndexCustomShaderSpecularColor&r?g?b?SpecularIntensitySpecularSharpness@FresnelStrengthCastShadowsBagOrderLuaScript#function updateSave() local data_to_save = {["ml"]=memoryList} saved_data = JSON.encode(data_to_save) self.script_state = saved_data end function onload(saved_data) if saved_data ~= "" then local loaded_data = JSON.decode(saved_data) --Set up information off of loaded_data memoryList = loaded_data.ml else --Set up information for if there is no saved saved data memoryList = {} end if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end end --Beginning Setup --Make setup button function createSetupButton() self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Triggered by setup button, function buttonClick_setup() memoryListBackup = duplicateTable(memoryList) memoryList = {} self.clearButtons() createButtonsOnAllObjects() createSetupActionButtons() end --Creates selection buttons on objects function createButtonsOnAllObjects() local howManyButtons = 0 for _, obj in ipairs(getAllObjects()) do if obj ~= self then local dummyIndex = howManyButtons --On a normal bag, the button positions aren't the same size as the bag. globalScaleFactor = 1 * 1/self.getScale().x --Super sweet math to set button positions local selfPos = self.getPosition() local objPos = obj.getPosition() local deltaPos = findOffsetDistance(selfPos, objPos, obj) local objPos = rotateLocalCoordinates(deltaPos, self) objPos.x = -objPos.x * globalScaleFactor objPos.y = objPos.y * globalScaleFactor objPos.z = objPos.z * globalScaleFactor --Offset rotation of bag local rot = self.getRotation() rot.y = -rot.y + 180 --Create function local funcName = "selectButton_" .. howManyButtons local func = function() buttonClick_selection(dummyIndex, obj) end self.setVar(funcName, func) self.createButton({ click_function=funcName, function_owner=self, position=objPos, rotation=rot, height=1000, width=1000, color={0.75,0.25,0.25,0.6}, }) howManyButtons = howManyButtons + 1 end end end --Creates submit and cancel buttons function createSetupActionButtons() self.createButton({ label="Cancel", click_function="buttonClick_cancel", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Submit", click_function="buttonClick_submit", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Reset", click_function="buttonClick_reset", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --During Setup --Checks or unchecks buttons function buttonClick_selection(index, obj) local color = {0,1,0,0.6} if memoryList[obj.getGUID()] == nil then self.editButton({index=index, color=color}) --Adding pos/rot to memory table local pos, rot = obj.getPosition(), obj.getRotation() --I need to add it like this or it won't save due to indexing issue memoryList[obj.getGUID()] = { pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, lock=obj.getLock() } obj.highlightOn({0,1,0}) else color = {0.75,0.25,0.25,0.6} self.editButton({index=index, color=color}) memoryList[obj.getGUID()] = nil obj.highlightOff() end end --Cancels selection process function buttonClick_cancel() memoryList = memoryListBackup self.clearButtons() if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end removeAllHighlights() broadcastToAll("Selection Canceled", {1,1,1}) end --Saves selections function buttonClick_submit() if next(memoryList) == nil then broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) else self.clearButtons() createMemoryActionButtons() local count = 0 for guid in pairs(memoryList) do count = count + 1 local obj = getObjectFromGUID(guid) if obj ~= nil then obj.highlightOff() end end broadcastToAll(count.." Objects Saved", {1,1,1}) updateSave() end end --Resets bag to starting status function buttonClick_reset() memoryList = {} self.clearButtons() createSetupButton() removeAllHighlights() broadcastToAll("Tool Reset", {1,1,1}) updateSave() end --After Setup --Creates recall and place buttons function createMemoryActionButtons() self.createButton({ label="Place", click_function="buttonClick_place", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Recall", click_function="buttonClick_recall", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Sends objects from bag/table to their saved position/rotation function buttonClick_place() local bagObjList = self.getObjects() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) --If obj is out on the table, move it to the saved pos/rot if obj ~= nil then obj.setPositionSmooth(entry.pos) obj.setRotationSmooth(entry.rot) obj.setLock(entry.lock) else --If obj is inside of the bag for _, bagObj in ipairs(bagObjList) do if bagObj.guid == guid then local item = self.takeObject({ guid=guid, position=entry.pos, rotation=entry.rot, }) item.setLock(entry.lock) break end end end end broadcastToAll("Objects Placed", {1,1,1}) end --Recalls objects to bag from table function buttonClick_recall() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) if obj ~= nil then self.putObject(obj) end end broadcastToAll("Objects Recalled", {1,1,1}) end --Utility functions --Find delta (difference) between 2 x/y/z coordinates function findOffsetDistance(p1, p2, obj) local deltaPos = {} local bounds = obj.getBounds() deltaPos.x = (p2.x-p1.x) deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) deltaPos.z = (p2.z-p1.z) return deltaPos end --Used to rotate a set of coordinates by an angle function rotateLocalCoordinates(desiredPos, obj) local objPos, objRot = obj.getPosition(), obj.getRotation() local angle = math.rad(objRot.y) local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} return {x=x, y=desiredPos.y, z=z} end --Coroutine delay, in seconds function wait(time) local start = os.time() repeat coroutine.yield(0) until os.time() > start + time end --Duplicates a table (needed to prevent it making reference to the same objects) function duplicateTable(oldTable) local newTable = {} for k, v in pairs(oldTable) do newTable[k] = v end return newTable end --Moves scripted highlight from all objects function removeAllHighlights() for _, obj in ipairs(getAllObjects()) do obj.highlightOff() end end --Round number (num) to the Nth decimal (dec) function round(num, dec) local mult = 10^(dec or 0) return math.floor(num * mult + 0.5) / mult end LuaScriptStateXmlUI9e'GUID674572NameCustom_Model_BagTransformposX>posY@posZ>rotX`>rotY ~f@rotZZscaleX@scaleY?scaleZ@Nickname Deck NameDescriptionGMNotesColorDiffuse&r?g Ϳ?b?LayoutGroupSortIndexValueLockedGridSnapIgnoreFoWMeasureMovementDragSelectableAutoraiseStickyTooltipGridProjectionHideWhenFaceDownHandsMaterialIndexMeshIndexNumberCustomMeshMeshURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126265930592/04FC7B7EB48D30899FF8B0C2B310B61364B90E81/DiffuseURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126266543661/9221BB399B1DE1555EBE065564C8C1FB07C7555D/NormalURLColliderURLConvexMaterialIndexTypeIndexCustomShaderSpecularColor&r?g?b?SpecularIntensitySpecularSharpness@FresnelStrengthCastShadowsBagOrderLuaScript#function updateSave() local data_to_save = {["ml"]=memoryList} saved_data = JSON.encode(data_to_save) self.script_state = saved_data end function onload(saved_data) if saved_data ~= "" then local loaded_data = JSON.decode(saved_data) --Set up information off of loaded_data memoryList = loaded_data.ml else --Set up information for if there is no saved saved data memoryList = {} end if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end end --Beginning Setup --Make setup button function createSetupButton() self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Triggered by setup button, function buttonClick_setup() memoryListBackup = duplicateTable(memoryList) memoryList = {} self.clearButtons() createButtonsOnAllObjects() createSetupActionButtons() end --Creates selection buttons on objects function createButtonsOnAllObjects() local howManyButtons = 0 for _, obj in ipairs(getAllObjects()) do if obj ~= self then local dummyIndex = howManyButtons --On a normal bag, the button positions aren't the same size as the bag. globalScaleFactor = 1 * 1/self.getScale().x --Super sweet math to set button positions local selfPos = self.getPosition() local objPos = obj.getPosition() local deltaPos = findOffsetDistance(selfPos, objPos, obj) local objPos = rotateLocalCoordinates(deltaPos, self) objPos.x = -objPos.x * globalScaleFactor objPos.y = objPos.y * globalScaleFactor objPos.z = objPos.z * globalScaleFactor --Offset rotation of bag local rot = self.getRotation() rot.y = -rot.y + 180 --Create function local funcName = "selectButton_" .. howManyButtons local func = function() buttonClick_selection(dummyIndex, obj) end self.setVar(funcName, func) self.createButton({ click_function=funcName, function_owner=self, position=objPos, rotation=rot, height=1000, width=1000, color={0.75,0.25,0.25,0.6}, }) howManyButtons = howManyButtons + 1 end end end --Creates submit and cancel buttons function createSetupActionButtons() self.createButton({ label="Cancel", click_function="buttonClick_cancel", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Submit", click_function="buttonClick_submit", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Reset", click_function="buttonClick_reset", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --During Setup --Checks or unchecks buttons function buttonClick_selection(index, obj) local color = {0,1,0,0.6} if memoryList[obj.getGUID()] == nil then self.editButton({index=index, color=color}) --Adding pos/rot to memory table local pos, rot = obj.getPosition(), obj.getRotation() --I need to add it like this or it won't save due to indexing issue memoryList[obj.getGUID()] = { pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, lock=obj.getLock() } obj.highlightOn({0,1,0}) else color = {0.75,0.25,0.25,0.6} self.editButton({index=index, color=color}) memoryList[obj.getGUID()] = nil obj.highlightOff() end end --Cancels selection process function buttonClick_cancel() memoryList = memoryListBackup self.clearButtons() if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end removeAllHighlights() broadcastToAll("Selection Canceled", {1,1,1}) end --Saves selections function buttonClick_submit() if next(memoryList) == nil then broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) else self.clearButtons() createMemoryActionButtons() local count = 0 for guid in pairs(memoryList) do count = count + 1 local obj = getObjectFromGUID(guid) if obj ~= nil then obj.highlightOff() end end broadcastToAll(count.." Objects Saved", {1,1,1}) updateSave() end end --Resets bag to starting status function buttonClick_reset() memoryList = {} self.clearButtons() createSetupButton() removeAllHighlights() broadcastToAll("Tool Reset", {1,1,1}) updateSave() end --After Setup --Creates recall and place buttons function createMemoryActionButtons() self.createButton({ label="Place", click_function="buttonClick_place", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Recall", click_function="buttonClick_recall", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Sends objects from bag/table to their saved position/rotation function buttonClick_place() local bagObjList = self.getObjects() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) --If obj is out on the table, move it to the saved pos/rot if obj ~= nil then obj.setPositionSmooth(entry.pos) obj.setRotationSmooth(entry.rot) obj.setLock(entry.lock) else --If obj is inside of the bag for _, bagObj in ipairs(bagObjList) do if bagObj.guid == guid then local item = self.takeObject({ guid=guid, position=entry.pos, rotation=entry.rot, }) item.setLock(entry.lock) break end end end end broadcastToAll("Objects Placed", {1,1,1}) end --Recalls objects to bag from table function buttonClick_recall() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) if obj ~= nil then self.putObject(obj) end end broadcastToAll("Objects Recalled", {1,1,1}) end --Utility functions --Find delta (difference) between 2 x/y/z coordinates function findOffsetDistance(p1, p2, obj) local deltaPos = {} local bounds = obj.getBounds() deltaPos.x = (p2.x-p1.x) deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) deltaPos.z = (p2.z-p1.z) return deltaPos end --Used to rotate a set of coordinates by an angle function rotateLocalCoordinates(desiredPos, obj) local objPos, objRot = obj.getPosition(), obj.getRotation() local angle = math.rad(objRot.y) local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} return {x=x, y=desiredPos.y, z=z} end --Coroutine delay, in seconds function wait(time) local start = os.time() repeat coroutine.yield(0) until os.time() > start + time end --Duplicates a table (needed to prevent it making reference to the same objects) function duplicateTable(oldTable) local newTable = {} for k, v in pairs(oldTable) do newTable[k] = v end return newTable end --Moves scripted highlight from all objects function removeAllHighlights() for _, obj in ipairs(getAllObjects()) do obj.highlightOff() end end --Round number (num) to the Nth decimal (dec) function round(num, dec) local mult = 10^(dec or 0) return math.floor(num * mult + 0.5) / mult end LuaScriptStateXmlUI10e'GUID5188ceNameCustom_Model_BagTransformposX`ff,@posYࠗ@posZL%@rotX@|k>rotYf@rotZ[K>scaleX@scaleY?scaleZ@Nickname Deck NameDescriptionGMNotesColorDiffuse&r?g Ϳ?b?LayoutGroupSortIndexValueLockedGridSnapIgnoreFoWMeasureMovementDragSelectableAutoraiseStickyTooltipGridProjectionHideWhenFaceDownHandsMaterialIndexMeshIndexNumberCustomMeshMeshURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126265930592/04FC7B7EB48D30899FF8B0C2B310B61364B90E81/DiffuseURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126266543433/E800DE0E5E0230B28B36133DD95564F70AD1F192/NormalURLColliderURLConvexMaterialIndexTypeIndexCustomShaderSpecularColor&r?g?b?SpecularIntensitySpecularSharpness@FresnelStrengthCastShadowsBagOrderLuaScript#function updateSave() local data_to_save = {["ml"]=memoryList} saved_data = JSON.encode(data_to_save) self.script_state = saved_data end function onload(saved_data) if saved_data ~= "" then local loaded_data = JSON.decode(saved_data) --Set up information off of loaded_data memoryList = loaded_data.ml else --Set up information for if there is no saved saved data memoryList = {} end if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end end --Beginning Setup --Make setup button function createSetupButton() self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Triggered by setup button, function buttonClick_setup() memoryListBackup = duplicateTable(memoryList) memoryList = {} self.clearButtons() createButtonsOnAllObjects() createSetupActionButtons() end --Creates selection buttons on objects function createButtonsOnAllObjects() local howManyButtons = 0 for _, obj in ipairs(getAllObjects()) do if obj ~= self then local dummyIndex = howManyButtons --On a normal bag, the button positions aren't the same size as the bag. globalScaleFactor = 1 * 1/self.getScale().x --Super sweet math to set button positions local selfPos = self.getPosition() local objPos = obj.getPosition() local deltaPos = findOffsetDistance(selfPos, objPos, obj) local objPos = rotateLocalCoordinates(deltaPos, self) objPos.x = -objPos.x * globalScaleFactor objPos.y = objPos.y * globalScaleFactor objPos.z = objPos.z * globalScaleFactor --Offset rotation of bag local rot = self.getRotation() rot.y = -rot.y + 180 --Create function local funcName = "selectButton_" .. howManyButtons local func = function() buttonClick_selection(dummyIndex, obj) end self.setVar(funcName, func) self.createButton({ click_function=funcName, function_owner=self, position=objPos, rotation=rot, height=1000, width=1000, color={0.75,0.25,0.25,0.6}, }) howManyButtons = howManyButtons + 1 end end end --Creates submit and cancel buttons function createSetupActionButtons() self.createButton({ label="Cancel", click_function="buttonClick_cancel", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Submit", click_function="buttonClick_submit", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Reset", click_function="buttonClick_reset", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --During Setup --Checks or unchecks buttons function buttonClick_selection(index, obj) local color = {0,1,0,0.6} if memoryList[obj.getGUID()] == nil then self.editButton({index=index, color=color}) --Adding pos/rot to memory table local pos, rot = obj.getPosition(), obj.getRotation() --I need to add it like this or it won't save due to indexing issue memoryList[obj.getGUID()] = { pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, lock=obj.getLock() } obj.highlightOn({0,1,0}) else color = {0.75,0.25,0.25,0.6} self.editButton({index=index, color=color}) memoryList[obj.getGUID()] = nil obj.highlightOff() end end --Cancels selection process function buttonClick_cancel() memoryList = memoryListBackup self.clearButtons() if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end removeAllHighlights() broadcastToAll("Selection Canceled", {1,1,1}) end --Saves selections function buttonClick_submit() if next(memoryList) == nil then broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) else self.clearButtons() createMemoryActionButtons() local count = 0 for guid in pairs(memoryList) do count = count + 1 local obj = getObjectFromGUID(guid) if obj ~= nil then obj.highlightOff() end end broadcastToAll(count.." Objects Saved", {1,1,1}) updateSave() end end --Resets bag to starting status function buttonClick_reset() memoryList = {} self.clearButtons() createSetupButton() removeAllHighlights() broadcastToAll("Tool Reset", {1,1,1}) updateSave() end --After Setup --Creates recall and place buttons function createMemoryActionButtons() self.createButton({ label="Place", click_function="buttonClick_place", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Recall", click_function="buttonClick_recall", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Sends objects from bag/table to their saved position/rotation function buttonClick_place() local bagObjList = self.getObjects() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) --If obj is out on the table, move it to the saved pos/rot if obj ~= nil then obj.setPositionSmooth(entry.pos) obj.setRotationSmooth(entry.rot) obj.setLock(entry.lock) else --If obj is inside of the bag for _, bagObj in ipairs(bagObjList) do if bagObj.guid == guid then local item = self.takeObject({ guid=guid, position=entry.pos, rotation=entry.rot, }) item.setLock(entry.lock) break end end end end broadcastToAll("Objects Placed", {1,1,1}) end --Recalls objects to bag from table function buttonClick_recall() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) if obj ~= nil then self.putObject(obj) end end broadcastToAll("Objects Recalled", {1,1,1}) end --Utility functions --Find delta (difference) between 2 x/y/z coordinates function findOffsetDistance(p1, p2, obj) local deltaPos = {} local bounds = obj.getBounds() deltaPos.x = (p2.x-p1.x) deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) deltaPos.z = (p2.z-p1.z) return deltaPos end --Used to rotate a set of coordinates by an angle function rotateLocalCoordinates(desiredPos, obj) local objPos, objRot = obj.getPosition(), obj.getRotation() local angle = math.rad(objRot.y) local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} return {x=x, y=desiredPos.y, z=z} end --Coroutine delay, in seconds function wait(time) local start = os.time() repeat coroutine.yield(0) until os.time() > start + time end --Duplicates a table (needed to prevent it making reference to the same objects) function duplicateTable(oldTable) local newTable = {} for k, v in pairs(oldTable) do newTable[k] = v end return newTable end --Moves scripted highlight from all objects function removeAllHighlights() for _, obj in ipairs(getAllObjects()) do obj.highlightOff() end end --Round number (num) to the Nth decimal (dec) function round(num, dec) local mult = 10^(dec or 0) return math.floor(num * mult + 0.5) / mult end LuaScriptStateXmlUI11e'GUID3e1647NameCustom_Model_BagTransformposX`ff,posYࠗ@posZL%@rotXL"p>rotY'f@rotZGscaleX@scaleY?scaleZ@Nickname Deck NameDescriptionGMNotesColorDiffuse&r?g Ϳ?b?LayoutGroupSortIndexValueLockedGridSnapIgnoreFoWMeasureMovementDragSelectableAutoraiseStickyTooltipGridProjectionHideWhenFaceDownHandsMaterialIndexMeshIndexNumberCustomMeshMeshURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126265930592/04FC7B7EB48D30899FF8B0C2B310B61364B90E81/DiffuseURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126266543735/7EAB0CBB9B429EEEB5EA04A24173566383675F83/NormalURLColliderURLConvexMaterialIndexTypeIndexCustomShaderSpecularColor&r?g?b?SpecularIntensitySpecularSharpness@FresnelStrengthCastShadowsBagOrderLuaScript#function updateSave() local data_to_save = {["ml"]=memoryList} saved_data = JSON.encode(data_to_save) self.script_state = saved_data end function onload(saved_data) if saved_data ~= "" then local loaded_data = JSON.decode(saved_data) --Set up information off of loaded_data memoryList = loaded_data.ml else --Set up information for if there is no saved saved data memoryList = {} end if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end end --Beginning Setup --Make setup button function createSetupButton() self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Triggered by setup button, function buttonClick_setup() memoryListBackup = duplicateTable(memoryList) memoryList = {} self.clearButtons() createButtonsOnAllObjects() createSetupActionButtons() end --Creates selection buttons on objects function createButtonsOnAllObjects() local howManyButtons = 0 for _, obj in ipairs(getAllObjects()) do if obj ~= self then local dummyIndex = howManyButtons --On a normal bag, the button positions aren't the same size as the bag. globalScaleFactor = 1 * 1/self.getScale().x --Super sweet math to set button positions local selfPos = self.getPosition() local objPos = obj.getPosition() local deltaPos = findOffsetDistance(selfPos, objPos, obj) local objPos = rotateLocalCoordinates(deltaPos, self) objPos.x = -objPos.x * globalScaleFactor objPos.y = objPos.y * globalScaleFactor objPos.z = objPos.z * globalScaleFactor --Offset rotation of bag local rot = self.getRotation() rot.y = -rot.y + 180 --Create function local funcName = "selectButton_" .. howManyButtons local func = function() buttonClick_selection(dummyIndex, obj) end self.setVar(funcName, func) self.createButton({ click_function=funcName, function_owner=self, position=objPos, rotation=rot, height=1000, width=1000, color={0.75,0.25,0.25,0.6}, }) howManyButtons = howManyButtons + 1 end end end --Creates submit and cancel buttons function createSetupActionButtons() self.createButton({ label="Cancel", click_function="buttonClick_cancel", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Submit", click_function="buttonClick_submit", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Reset", click_function="buttonClick_reset", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --During Setup --Checks or unchecks buttons function buttonClick_selection(index, obj) local color = {0,1,0,0.6} if memoryList[obj.getGUID()] == nil then self.editButton({index=index, color=color}) --Adding pos/rot to memory table local pos, rot = obj.getPosition(), obj.getRotation() --I need to add it like this or it won't save due to indexing issue memoryList[obj.getGUID()] = { pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, lock=obj.getLock() } obj.highlightOn({0,1,0}) else color = {0.75,0.25,0.25,0.6} self.editButton({index=index, color=color}) memoryList[obj.getGUID()] = nil obj.highlightOff() end end --Cancels selection process function buttonClick_cancel() memoryList = memoryListBackup self.clearButtons() if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end removeAllHighlights() broadcastToAll("Selection Canceled", {1,1,1}) end --Saves selections function buttonClick_submit() if next(memoryList) == nil then broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) else self.clearButtons() createMemoryActionButtons() local count = 0 for guid in pairs(memoryList) do count = count + 1 local obj = getObjectFromGUID(guid) if obj ~= nil then obj.highlightOff() end end broadcastToAll(count.." Objects Saved", {1,1,1}) updateSave() end end --Resets bag to starting status function buttonClick_reset() memoryList = {} self.clearButtons() createSetupButton() removeAllHighlights() broadcastToAll("Tool Reset", {1,1,1}) updateSave() end --After Setup --Creates recall and place buttons function createMemoryActionButtons() self.createButton({ label="Place", click_function="buttonClick_place", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Recall", click_function="buttonClick_recall", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Sends objects from bag/table to their saved position/rotation function buttonClick_place() local bagObjList = self.getObjects() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) --If obj is out on the table, move it to the saved pos/rot if obj ~= nil then obj.setPositionSmooth(entry.pos) obj.setRotationSmooth(entry.rot) obj.setLock(entry.lock) else --If obj is inside of the bag for _, bagObj in ipairs(bagObjList) do if bagObj.guid == guid then local item = self.takeObject({ guid=guid, position=entry.pos, rotation=entry.rot, }) item.setLock(entry.lock) break end end end end broadcastToAll("Objects Placed", {1,1,1}) end --Recalls objects to bag from table function buttonClick_recall() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) if obj ~= nil then self.putObject(obj) end end broadcastToAll("Objects Recalled", {1,1,1}) end --Utility functions --Find delta (difference) between 2 x/y/z coordinates function findOffsetDistance(p1, p2, obj) local deltaPos = {} local bounds = obj.getBounds() deltaPos.x = (p2.x-p1.x) deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) deltaPos.z = (p2.z-p1.z) return deltaPos end --Used to rotate a set of coordinates by an angle function rotateLocalCoordinates(desiredPos, obj) local objPos, objRot = obj.getPosition(), obj.getRotation() local angle = math.rad(objRot.y) local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} return {x=x, y=desiredPos.y, z=z} end --Coroutine delay, in seconds function wait(time) local start = os.time() repeat coroutine.yield(0) until os.time() > start + time end --Duplicates a table (needed to prevent it making reference to the same objects) function duplicateTable(oldTable) local newTable = {} for k, v in pairs(oldTable) do newTable[k] = v end return newTable end --Moves scripted highlight from all objects function removeAllHighlights() for _, obj in ipairs(getAllObjects()) do obj.highlightOff() end end --Round number (num) to the Nth decimal (dec) function round(num, dec) local mult = 10^(dec or 0) return math.floor(num * mult + 0.5) / mult end LuaScriptStateXmlUI12e'GUID23088cNameCustom_Model_BagTransformposX`ff,posYࠗ@posZrotXZ1jrotY`Mf@rotZQpscaleX@scaleY?scaleZ@Nickname Deck NameDescriptionGMNotesColorDiffuse&r?g Ϳ?b?LayoutGroupSortIndexValueLockedGridSnapIgnoreFoWMeasureMovementDragSelectableAutoraiseStickyTooltipGridProjectionHideWhenFaceDownHandsMaterialIndexMeshIndexNumberCustomMeshMeshURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126265930592/04FC7B7EB48D30899FF8B0C2B310B61364B90E81/DiffuseURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126266543811/78C19E6568B7377BC233841D5BFC55850D03052C/NormalURLColliderURLConvexMaterialIndexTypeIndexCustomShaderSpecularColor&r?g?b?SpecularIntensitySpecularSharpness@FresnelStrengthCastShadowsBagOrderLuaScript#function updateSave() local data_to_save = {["ml"]=memoryList} saved_data = JSON.encode(data_to_save) self.script_state = saved_data end function onload(saved_data) if saved_data ~= "" then local loaded_data = JSON.decode(saved_data) --Set up information off of loaded_data memoryList = loaded_data.ml else --Set up information for if there is no saved saved data memoryList = {} end if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end end --Beginning Setup --Make setup button function createSetupButton() self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Triggered by setup button, function buttonClick_setup() memoryListBackup = duplicateTable(memoryList) memoryList = {} self.clearButtons() createButtonsOnAllObjects() createSetupActionButtons() end --Creates selection buttons on objects function createButtonsOnAllObjects() local howManyButtons = 0 for _, obj in ipairs(getAllObjects()) do if obj ~= self then local dummyIndex = howManyButtons --On a normal bag, the button positions aren't the same size as the bag. globalScaleFactor = 1 * 1/self.getScale().x --Super sweet math to set button positions local selfPos = self.getPosition() local objPos = obj.getPosition() local deltaPos = findOffsetDistance(selfPos, objPos, obj) local objPos = rotateLocalCoordinates(deltaPos, self) objPos.x = -objPos.x * globalScaleFactor objPos.y = objPos.y * globalScaleFactor objPos.z = objPos.z * globalScaleFactor --Offset rotation of bag local rot = self.getRotation() rot.y = -rot.y + 180 --Create function local funcName = "selectButton_" .. howManyButtons local func = function() buttonClick_selection(dummyIndex, obj) end self.setVar(funcName, func) self.createButton({ click_function=funcName, function_owner=self, position=objPos, rotation=rot, height=1000, width=1000, color={0.75,0.25,0.25,0.6}, }) howManyButtons = howManyButtons + 1 end end end --Creates submit and cancel buttons function createSetupActionButtons() self.createButton({ label="Cancel", click_function="buttonClick_cancel", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Submit", click_function="buttonClick_submit", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Reset", click_function="buttonClick_reset", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --During Setup --Checks or unchecks buttons function buttonClick_selection(index, obj) local color = {0,1,0,0.6} if memoryList[obj.getGUID()] == nil then self.editButton({index=index, color=color}) --Adding pos/rot to memory table local pos, rot = obj.getPosition(), obj.getRotation() --I need to add it like this or it won't save due to indexing issue memoryList[obj.getGUID()] = { pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, lock=obj.getLock() } obj.highlightOn({0,1,0}) else color = {0.75,0.25,0.25,0.6} self.editButton({index=index, color=color}) memoryList[obj.getGUID()] = nil obj.highlightOff() end end --Cancels selection process function buttonClick_cancel() memoryList = memoryListBackup self.clearButtons() if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end removeAllHighlights() broadcastToAll("Selection Canceled", {1,1,1}) end --Saves selections function buttonClick_submit() if next(memoryList) == nil then broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) else self.clearButtons() createMemoryActionButtons() local count = 0 for guid in pairs(memoryList) do count = count + 1 local obj = getObjectFromGUID(guid) if obj ~= nil then obj.highlightOff() end end broadcastToAll(count.." Objects Saved", {1,1,1}) updateSave() end end --Resets bag to starting status function buttonClick_reset() memoryList = {} self.clearButtons() createSetupButton() removeAllHighlights() broadcastToAll("Tool Reset", {1,1,1}) updateSave() end --After Setup --Creates recall and place buttons function createMemoryActionButtons() self.createButton({ label="Place", click_function="buttonClick_place", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Recall", click_function="buttonClick_recall", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Sends objects from bag/table to their saved position/rotation function buttonClick_place() local bagObjList = self.getObjects() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) --If obj is out on the table, move it to the saved pos/rot if obj ~= nil then obj.setPositionSmooth(entry.pos) obj.setRotationSmooth(entry.rot) obj.setLock(entry.lock) else --If obj is inside of the bag for _, bagObj in ipairs(bagObjList) do if bagObj.guid == guid then local item = self.takeObject({ guid=guid, position=entry.pos, rotation=entry.rot, }) item.setLock(entry.lock) break end end end end broadcastToAll("Objects Placed", {1,1,1}) end --Recalls objects to bag from table function buttonClick_recall() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) if obj ~= nil then self.putObject(obj) end end broadcastToAll("Objects Recalled", {1,1,1}) end --Utility functions --Find delta (difference) between 2 x/y/z coordinates function findOffsetDistance(p1, p2, obj) local deltaPos = {} local bounds = obj.getBounds() deltaPos.x = (p2.x-p1.x) deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) deltaPos.z = (p2.z-p1.z) return deltaPos end --Used to rotate a set of coordinates by an angle function rotateLocalCoordinates(desiredPos, obj) local objPos, objRot = obj.getPosition(), obj.getRotation() local angle = math.rad(objRot.y) local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} return {x=x, y=desiredPos.y, z=z} end --Coroutine delay, in seconds function wait(time) local start = os.time() repeat coroutine.yield(0) until os.time() > start + time end --Duplicates a table (needed to prevent it making reference to the same objects) function duplicateTable(oldTable) local newTable = {} for k, v in pairs(oldTable) do newTable[k] = v end return newTable end --Moves scripted highlight from all objects function removeAllHighlights() for _, obj in ipairs(getAllObjects()) do obj.highlightOff() end end --Round number (num) to the Nth decimal (dec) function round(num, dec) local mult = 10^(dec or 0) return math.floor(num * mult + 0.5) / mult end LuaScriptStateXmlUI13e'GUID95d226NameCustom_Model_BagTransformposXL5posYࠗ@posZrotX-ErotY`f@rotZSv>scaleX@scaleY?scaleZ@Nickname Deck NameDescriptionGMNotesColorDiffuse&r?g Ϳ?b?LayoutGroupSortIndexValueLockedGridSnapIgnoreFoWMeasureMovementDragSelectableAutoraiseStickyTooltipGridProjectionHideWhenFaceDownHandsMaterialIndexMeshIndexNumberCustomMeshMeshURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126265930592/04FC7B7EB48D30899FF8B0C2B310B61364B90E81/DiffuseURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126266554290/1929E13F016B5F0D2D86CBEBD0E14B2E48F5F4F5/NormalURLColliderURLConvexMaterialIndexTypeIndexCustomShaderSpecularColor&r?g?b?SpecularIntensitySpecularSharpness@FresnelStrengthCastShadowsBagOrderLuaScript#function updateSave() local data_to_save = {["ml"]=memoryList} saved_data = JSON.encode(data_to_save) self.script_state = saved_data end function onload(saved_data) if saved_data ~= "" then local loaded_data = JSON.decode(saved_data) --Set up information off of loaded_data memoryList = loaded_data.ml else --Set up information for if there is no saved saved data memoryList = {} end if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end end --Beginning Setup --Make setup button function createSetupButton() self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Triggered by setup button, function buttonClick_setup() memoryListBackup = duplicateTable(memoryList) memoryList = {} self.clearButtons() createButtonsOnAllObjects() createSetupActionButtons() end --Creates selection buttons on objects function createButtonsOnAllObjects() local howManyButtons = 0 for _, obj in ipairs(getAllObjects()) do if obj ~= self then local dummyIndex = howManyButtons --On a normal bag, the button positions aren't the same size as the bag. globalScaleFactor = 1 * 1/self.getScale().x --Super sweet math to set button positions local selfPos = self.getPosition() local objPos = obj.getPosition() local deltaPos = findOffsetDistance(selfPos, objPos, obj) local objPos = rotateLocalCoordinates(deltaPos, self) objPos.x = -objPos.x * globalScaleFactor objPos.y = objPos.y * globalScaleFactor objPos.z = objPos.z * globalScaleFactor --Offset rotation of bag local rot = self.getRotation() rot.y = -rot.y + 180 --Create function local funcName = "selectButton_" .. howManyButtons local func = function() buttonClick_selection(dummyIndex, obj) end self.setVar(funcName, func) self.createButton({ click_function=funcName, function_owner=self, position=objPos, rotation=rot, height=1000, width=1000, color={0.75,0.25,0.25,0.6}, }) howManyButtons = howManyButtons + 1 end end end --Creates submit and cancel buttons function createSetupActionButtons() self.createButton({ label="Cancel", click_function="buttonClick_cancel", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Submit", click_function="buttonClick_submit", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Reset", click_function="buttonClick_reset", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --During Setup --Checks or unchecks buttons function buttonClick_selection(index, obj) local color = {0,1,0,0.6} if memoryList[obj.getGUID()] == nil then self.editButton({index=index, color=color}) --Adding pos/rot to memory table local pos, rot = obj.getPosition(), obj.getRotation() --I need to add it like this or it won't save due to indexing issue memoryList[obj.getGUID()] = { pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, lock=obj.getLock() } obj.highlightOn({0,1,0}) else color = {0.75,0.25,0.25,0.6} self.editButton({index=index, color=color}) memoryList[obj.getGUID()] = nil obj.highlightOff() end end --Cancels selection process function buttonClick_cancel() memoryList = memoryListBackup self.clearButtons() if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end removeAllHighlights() broadcastToAll("Selection Canceled", {1,1,1}) end --Saves selections function buttonClick_submit() if next(memoryList) == nil then broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) else self.clearButtons() createMemoryActionButtons() local count = 0 for guid in pairs(memoryList) do count = count + 1 local obj = getObjectFromGUID(guid) if obj ~= nil then obj.highlightOff() end end broadcastToAll(count.." Objects Saved", {1,1,1}) updateSave() end end --Resets bag to starting status function buttonClick_reset() memoryList = {} self.clearButtons() createSetupButton() removeAllHighlights() broadcastToAll("Tool Reset", {1,1,1}) updateSave() end --After Setup --Creates recall and place buttons function createMemoryActionButtons() self.createButton({ label="Place", click_function="buttonClick_place", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Recall", click_function="buttonClick_recall", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Sends objects from bag/table to their saved position/rotation function buttonClick_place() local bagObjList = self.getObjects() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) --If obj is out on the table, move it to the saved pos/rot if obj ~= nil then obj.setPositionSmooth(entry.pos) obj.setRotationSmooth(entry.rot) obj.setLock(entry.lock) else --If obj is inside of the bag for _, bagObj in ipairs(bagObjList) do if bagObj.guid == guid then local item = self.takeObject({ guid=guid, position=entry.pos, rotation=entry.rot, }) item.setLock(entry.lock) break end end end end broadcastToAll("Objects Placed", {1,1,1}) end --Recalls objects to bag from table function buttonClick_recall() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) if obj ~= nil then self.putObject(obj) end end broadcastToAll("Objects Recalled", {1,1,1}) end --Utility functions --Find delta (difference) between 2 x/y/z coordinates function findOffsetDistance(p1, p2, obj) local deltaPos = {} local bounds = obj.getBounds() deltaPos.x = (p2.x-p1.x) deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) deltaPos.z = (p2.z-p1.z) return deltaPos end --Used to rotate a set of coordinates by an angle function rotateLocalCoordinates(desiredPos, obj) local objPos, objRot = obj.getPosition(), obj.getRotation() local angle = math.rad(objRot.y) local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} return {x=x, y=desiredPos.y, z=z} end --Coroutine delay, in seconds function wait(time) local start = os.time() repeat coroutine.yield(0) until os.time() > start + time end --Duplicates a table (needed to prevent it making reference to the same objects) function duplicateTable(oldTable) local newTable = {} for k, v in pairs(oldTable) do newTable[k] = v end return newTable end --Moves scripted highlight from all objects function removeAllHighlights() for _, obj in ipairs(getAllObjects()) do obj.highlightOff() end end --Round number (num) to the Nth decimal (dec) function round(num, dec) local mult = 10^(dec or 0) return math.floor(num * mult + 0.5) / mult end LuaScriptStateXmlUI14e'GUID073efdNameCustom_Model_BagTransformposXL5posYࠗ@posZL%@rotX@ts>rotY$f@rotZ`xscaleX@scaleY?scaleZ@Nickname Deck NameDescriptionGMNotesColorDiffuse&r?g Ϳ?b?LayoutGroupSortIndexValueLockedGridSnapIgnoreFoWMeasureMovementDragSelectableAutoraiseStickyTooltipGridProjectionHideWhenFaceDownHandsMaterialIndexMeshIndexNumberCustomMeshMeshURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126265930592/04FC7B7EB48D30899FF8B0C2B310B61364B90E81/DiffuseURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126266495613/62AA5E096609269E30E23BE5794BC99319A6BB4A/NormalURLColliderURLConvexMaterialIndexTypeIndexCustomShaderSpecularColor&r?g?b?SpecularIntensitySpecularSharpness@FresnelStrengthCastShadowsBagOrderLuaScript#function updateSave() local data_to_save = {["ml"]=memoryList} saved_data = JSON.encode(data_to_save) self.script_state = saved_data end function onload(saved_data) if saved_data ~= "" then local loaded_data = JSON.decode(saved_data) --Set up information off of loaded_data memoryList = loaded_data.ml else --Set up information for if there is no saved saved data memoryList = {} end if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end end --Beginning Setup --Make setup button function createSetupButton() self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Triggered by setup button, function buttonClick_setup() memoryListBackup = duplicateTable(memoryList) memoryList = {} self.clearButtons() createButtonsOnAllObjects() createSetupActionButtons() end --Creates selection buttons on objects function createButtonsOnAllObjects() local howManyButtons = 0 for _, obj in ipairs(getAllObjects()) do if obj ~= self then local dummyIndex = howManyButtons --On a normal bag, the button positions aren't the same size as the bag. globalScaleFactor = 1 * 1/self.getScale().x --Super sweet math to set button positions local selfPos = self.getPosition() local objPos = obj.getPosition() local deltaPos = findOffsetDistance(selfPos, objPos, obj) local objPos = rotateLocalCoordinates(deltaPos, self) objPos.x = -objPos.x * globalScaleFactor objPos.y = objPos.y * globalScaleFactor objPos.z = objPos.z * globalScaleFactor --Offset rotation of bag local rot = self.getRotation() rot.y = -rot.y + 180 --Create function local funcName = "selectButton_" .. howManyButtons local func = function() buttonClick_selection(dummyIndex, obj) end self.setVar(funcName, func) self.createButton({ click_function=funcName, function_owner=self, position=objPos, rotation=rot, height=1000, width=1000, color={0.75,0.25,0.25,0.6}, }) howManyButtons = howManyButtons + 1 end end end --Creates submit and cancel buttons function createSetupActionButtons() self.createButton({ label="Cancel", click_function="buttonClick_cancel", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Submit", click_function="buttonClick_submit", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Reset", click_function="buttonClick_reset", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --During Setup --Checks or unchecks buttons function buttonClick_selection(index, obj) local color = {0,1,0,0.6} if memoryList[obj.getGUID()] == nil then self.editButton({index=index, color=color}) --Adding pos/rot to memory table local pos, rot = obj.getPosition(), obj.getRotation() --I need to add it like this or it won't save due to indexing issue memoryList[obj.getGUID()] = { pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, lock=obj.getLock() } obj.highlightOn({0,1,0}) else color = {0.75,0.25,0.25,0.6} self.editButton({index=index, color=color}) memoryList[obj.getGUID()] = nil obj.highlightOff() end end --Cancels selection process function buttonClick_cancel() memoryList = memoryListBackup self.clearButtons() if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end removeAllHighlights() broadcastToAll("Selection Canceled", {1,1,1}) end --Saves selections function buttonClick_submit() if next(memoryList) == nil then broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) else self.clearButtons() createMemoryActionButtons() local count = 0 for guid in pairs(memoryList) do count = count + 1 local obj = getObjectFromGUID(guid) if obj ~= nil then obj.highlightOff() end end broadcastToAll(count.." Objects Saved", {1,1,1}) updateSave() end end --Resets bag to starting status function buttonClick_reset() memoryList = {} self.clearButtons() createSetupButton() removeAllHighlights() broadcastToAll("Tool Reset", {1,1,1}) updateSave() end --After Setup --Creates recall and place buttons function createMemoryActionButtons() self.createButton({ label="Place", click_function="buttonClick_place", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Recall", click_function="buttonClick_recall", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Sends objects from bag/table to their saved position/rotation function buttonClick_place() local bagObjList = self.getObjects() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) --If obj is out on the table, move it to the saved pos/rot if obj ~= nil then obj.setPositionSmooth(entry.pos) obj.setRotationSmooth(entry.rot) obj.setLock(entry.lock) else --If obj is inside of the bag for _, bagObj in ipairs(bagObjList) do if bagObj.guid == guid then local item = self.takeObject({ guid=guid, position=entry.pos, rotation=entry.rot, }) item.setLock(entry.lock) break end end end end broadcastToAll("Objects Placed", {1,1,1}) end --Recalls objects to bag from table function buttonClick_recall() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) if obj ~= nil then self.putObject(obj) end end broadcastToAll("Objects Recalled", {1,1,1}) end --Utility functions --Find delta (difference) between 2 x/y/z coordinates function findOffsetDistance(p1, p2, obj) local deltaPos = {} local bounds = obj.getBounds() deltaPos.x = (p2.x-p1.x) deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) deltaPos.z = (p2.z-p1.z) return deltaPos end --Used to rotate a set of coordinates by an angle function rotateLocalCoordinates(desiredPos, obj) local objPos, objRot = obj.getPosition(), obj.getRotation() local angle = math.rad(objRot.y) local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} return {x=x, y=desiredPos.y, z=z} end --Coroutine delay, in seconds function wait(time) local start = os.time() repeat coroutine.yield(0) until os.time() > start + time end --Duplicates a table (needed to prevent it making reference to the same objects) function duplicateTable(oldTable) local newTable = {} for k, v in pairs(oldTable) do newTable[k] = v end return newTable end --Moves scripted highlight from all objects function removeAllHighlights() for _, obj in ipairs(getAllObjects()) do obj.highlightOff() end end --Round number (num) to the Nth decimal (dec) function round(num, dec) local mult = 10^(dec or 0) return math.floor(num * mult + 0.5) / mult end LuaScriptStateXmlUI15e'GUID704a29NameCustom_Model_BagTransformposX`ffposY@posZL%@rotX>rotYf@rotZ>scaleX@scaleY?scaleZ@Nickname Deck NameDescriptionGMNotesColorDiffuse&r?g Ϳ?b?LayoutGroupSortIndexValueLockedGridSnapIgnoreFoWMeasureMovementDragSelectableAutoraiseStickyTooltipGridProjectionHideWhenFaceDownHandsMaterialIndexMeshIndexNumberCustomMeshMeshURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126265930592/04FC7B7EB48D30899FF8B0C2B310B61364B90E81/DiffuseURLfhttp://cloud-3.steamusercontent.com/ugc/1791848126266543227/0A6824F5500A8179783AD1F634A551E03E7A93A0/NormalURLColliderURLConvexMaterialIndexTypeIndexCustomShaderSpecularColor&r?g?b?SpecularIntensitySpecularSharpness@FresnelStrengthCastShadowsBagOrderLuaScript#function updateSave() local data_to_save = {["ml"]=memoryList} saved_data = JSON.encode(data_to_save) self.script_state = saved_data end function onload(saved_data) if saved_data ~= "" then local loaded_data = JSON.decode(saved_data) --Set up information off of loaded_data memoryList = loaded_data.ml else --Set up information for if there is no saved saved data memoryList = {} end if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end end --Beginning Setup --Make setup button function createSetupButton() self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Triggered by setup button, function buttonClick_setup() memoryListBackup = duplicateTable(memoryList) memoryList = {} self.clearButtons() createButtonsOnAllObjects() createSetupActionButtons() end --Creates selection buttons on objects function createButtonsOnAllObjects() local howManyButtons = 0 for _, obj in ipairs(getAllObjects()) do if obj ~= self then local dummyIndex = howManyButtons --On a normal bag, the button positions aren't the same size as the bag. globalScaleFactor = 1 * 1/self.getScale().x --Super sweet math to set button positions local selfPos = self.getPosition() local objPos = obj.getPosition() local deltaPos = findOffsetDistance(selfPos, objPos, obj) local objPos = rotateLocalCoordinates(deltaPos, self) objPos.x = -objPos.x * globalScaleFactor objPos.y = objPos.y * globalScaleFactor objPos.z = objPos.z * globalScaleFactor --Offset rotation of bag local rot = self.getRotation() rot.y = -rot.y + 180 --Create function local funcName = "selectButton_" .. howManyButtons local func = function() buttonClick_selection(dummyIndex, obj) end self.setVar(funcName, func) self.createButton({ click_function=funcName, function_owner=self, position=objPos, rotation=rot, height=1000, width=1000, color={0.75,0.25,0.25,0.6}, }) howManyButtons = howManyButtons + 1 end end end --Creates submit and cancel buttons function createSetupActionButtons() self.createButton({ label="Cancel", click_function="buttonClick_cancel", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Submit", click_function="buttonClick_submit", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=1100, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Reset", click_function="buttonClick_reset", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --During Setup --Checks or unchecks buttons function buttonClick_selection(index, obj) local color = {0,1,0,0.6} if memoryList[obj.getGUID()] == nil then self.editButton({index=index, color=color}) --Adding pos/rot to memory table local pos, rot = obj.getPosition(), obj.getRotation() --I need to add it like this or it won't save due to indexing issue memoryList[obj.getGUID()] = { pos={x=round(pos.x,4), y=round(pos.y,4), z=round(pos.z,4)}, rot={x=round(rot.x,4), y=round(rot.y,4), z=round(rot.z,4)}, lock=obj.getLock() } obj.highlightOn({0,1,0}) else color = {0.75,0.25,0.25,0.6} self.editButton({index=index, color=color}) memoryList[obj.getGUID()] = nil obj.highlightOff() end end --Cancels selection process function buttonClick_cancel() memoryList = memoryListBackup self.clearButtons() if next(memoryList) == nil then createSetupButton() else createMemoryActionButtons() end removeAllHighlights() broadcastToAll("Selection Canceled", {1,1,1}) end --Saves selections function buttonClick_submit() if next(memoryList) == nil then broadcastToAll("You cannot submit without any selections.", {0.75, 0.25, 0.25}) else self.clearButtons() createMemoryActionButtons() local count = 0 for guid in pairs(memoryList) do count = count + 1 local obj = getObjectFromGUID(guid) if obj ~= nil then obj.highlightOff() end end broadcastToAll(count.." Objects Saved", {1,1,1}) updateSave() end end --Resets bag to starting status function buttonClick_reset() memoryList = {} self.clearButtons() createSetupButton() removeAllHighlights() broadcastToAll("Tool Reset", {1,1,1}) updateSave() end --After Setup --Creates recall and place buttons function createMemoryActionButtons() self.createButton({ label="Place", click_function="buttonClick_place", function_owner=self, position={0,-1.2,2.1}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Recall", click_function="buttonClick_recall", function_owner=self, position={0,-1.2,2.9}, rotation={0,0,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) self.createButton({ label="Setup", click_function="buttonClick_setup", function_owner=self, position={-1.6,-1.2,0}, rotation={0,270,0}, height=350, width=800, font_size=250, color={0,0,0}, font_color={1,1,1} }) end --Sends objects from bag/table to their saved position/rotation function buttonClick_place() local bagObjList = self.getObjects() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) --If obj is out on the table, move it to the saved pos/rot if obj ~= nil then obj.setPositionSmooth(entry.pos) obj.setRotationSmooth(entry.rot) obj.setLock(entry.lock) else --If obj is inside of the bag for _, bagObj in ipairs(bagObjList) do if bagObj.guid == guid then local item = self.takeObject({ guid=guid, position=entry.pos, rotation=entry.rot, }) item.setLock(entry.lock) break end end end end broadcastToAll("Objects Placed", {1,1,1}) end --Recalls objects to bag from table function buttonClick_recall() for guid, entry in pairs(memoryList) do local obj = getObjectFromGUID(guid) if obj ~= nil then self.putObject(obj) end end broadcastToAll("Objects Recalled", {1,1,1}) end --Utility functions --Find delta (difference) between 2 x/y/z coordinates function findOffsetDistance(p1, p2, obj) local deltaPos = {} local bounds = obj.getBounds() deltaPos.x = (p2.x-p1.x) deltaPos.y = (p2.y-p1.y) + (bounds.size.y - bounds.offset.y) deltaPos.z = (p2.z-p1.z) return deltaPos end --Used to rotate a set of coordinates by an angle function rotateLocalCoordinates(desiredPos, obj) local objPos, objRot = obj.getPosition(), obj.getRotation() local angle = math.rad(objRot.y) local x = desiredPos.x * math.cos(angle) - desiredPos.z * math.sin(angle) local z = desiredPos.x * math.sin(angle) + desiredPos.z * math.cos(angle) --return {x=objPos.x+x, y=objPos.y+desiredPos.y, z=objPos.z+z} return {x=x, y=desiredPos.y, z=z} end --Coroutine delay, in seconds function wait(time) local start = os.time() repeat coroutine.yield(0) until os.time() > start + time end --Duplicates a table (needed to prevent it making reference to the same objects) function duplicateTable(oldTable) local newTable = {} for k, v in pairs(oldTable) do newTable[k] = v end return newTable end --Moves scripted highlight from all objects function removeAllHighlights() for _, obj in ipairs(getAllObjects()) do obj.highlightOff() end end --Round number (num) to the Nth decimal (dec) function round(num, dec) local mult = 10^(dec or 0) return math.floor(num * mult + 0.5) / mult end LuaScriptStateXmlUI