From eba4b316c70108bd56e66f03647968d19425d570 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Sat, 4 Nov 2023 13:53:24 +0100 Subject: [PATCH 1/4] added position checking --- src/core/Global.ttslua | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index 9ee7283d..2b91d671 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -1020,6 +1020,14 @@ function contentDownloadCallback(request, params) end end + -- if position is undefined, get empty position + if not spawnTable.position then + spawnTable.rotation = { 0, 270, 0} + + local pos = getValidSpawnPosition() + if pos then spawnTable.position = pos end + end + -- if spawned from menu, ping the position if params.name then spawnTable["callback_function"] = function(obj) @@ -1034,6 +1042,41 @@ function contentDownloadCallback(request, params) end end +-- gets the first empty position to spawn a custom content object safely +function getValidSpawnPosition() + local potentialSpawnPositionX = { 65, 50, 35 } + local potentialSpawnPositionY = 1.5 + local potentialSpawnPositionZ = { 35, 21, 7, -7, -21, -35 } + + for i, posX in ipairs(potentialSpawnPositionX) do + for j, posZ in ipairs(potentialSpawnPositionZ) do + local pos = { + x = posX, + y = potentialSpawnPositionY, + z = posZ, + } + if checkPositionForContentSpawn(pos) then + return pos + end + end + end + return nil +end + +-- checks whether something is in the specified position +-- returns true if empty +function checkPositionForContentSpawn(checkPos) + local search = Physics.cast({ + direction = { 0, 1, 0 }, + max_distance = 0.1, + type = 3, + size = { 0.1, 0.1, 0.1 }, + origin = checkPos + }) + -- first hit is the table surface, additional hits means something is there + return #search == 1 +end + -- downloading of the library file function libraryDownloadCallback(request) if request.is_error or request.response_code ~= 200 then From 0084915f08203141155dac7158e0c89719e38598 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Sat, 4 Nov 2023 19:07:17 +0100 Subject: [PATCH 2/4] added feedback if full --- src/core/Global.ttslua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index 2b91d671..0bacbef6 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -1025,7 +1025,11 @@ function contentDownloadCallback(request, params) spawnTable.rotation = { 0, 270, 0} local pos = getValidSpawnPosition() - if pos then spawnTable.position = pos end + if pos then + spawnTable.position = pos + else + broadcastToAll("Couldn't find an empty spot to spawn, will use default position of the item!", "Red") + end end -- if spawned from menu, ping the position From bbbf47ff8a4e4a9401f1f0bb668f141b725328fd Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Sun, 5 Nov 2023 13:11:07 +0100 Subject: [PATCH 3/4] added camera move --- src/core/Global.ttslua | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index 0bacbef6..34d471e3 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -692,8 +692,10 @@ function onClick_select(_, _, identificationKey) end -- click function for the download button in the preview window -function onClick_download() - placeholder_download(library[contentToShow][currentListItem]) +function onClick_download(player) + local params = library[contentToShow][currentListItem] + params.player = player + placeholder_download(params) end -- the download button on the placeholder objects calls this to directly initiate a download @@ -1032,10 +1034,24 @@ function contentDownloadCallback(request, params) end end - -- if spawned from menu, ping the position + -- if spawned from menu, move the camera and/or ping the table if params.name then spawnTable["callback_function"] = function(obj) - Player.getPlayers()[1].pingTable(obj.getPosition()) + Wait.time(function() + -- move camera + if params.player then + params.player.lookAt({ + position = obj.getPosition(), + pitch = 65, + yaw = 90, + distance = 65 + }) + end + + -- ping object + local pingPlayer = params.player or Player.getPlayers()[1] + pingPlayer.pingTable(obj.getPosition()) + end, 0.1) end end From 00372f9d2f9583f151061b2e33350c8496330663 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Mon, 6 Nov 2023 17:41:23 +0100 Subject: [PATCH 4/4] added return --- src/core/Global.ttslua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index c1e8acab..f98801f5 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -1030,7 +1030,8 @@ function contentDownloadCallback(request, params) if pos then spawnTable.position = pos else - broadcastToAll("Couldn't find an empty spot to spawn, will use default position of the item!", "Red") + broadcastToAll("Please make space in the area below the tentacle stand in the upper middle of the table and try again.", "Red") + return end end