Merge pull request #456 from argonui/custom-content-spawn-position
Unified custom content spawn position
This commit is contained in:
commit
5fc0362c7e
@ -692,8 +692,10 @@ function onClick_select(_, _, identificationKey)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- click function for the download button in the preview window
|
-- click function for the download button in the preview window
|
||||||
function onClick_download()
|
function onClick_download(player)
|
||||||
placeholder_download(library[contentToShow][currentListItem])
|
local params = library[contentToShow][currentListItem]
|
||||||
|
params.player = player
|
||||||
|
placeholder_download(params)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- the download button on the placeholder objects calls this to directly initiate a download
|
-- the download button on the placeholder objects calls this to directly initiate a download
|
||||||
@ -1020,10 +1022,37 @@ function contentDownloadCallback(request, params)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- if spawned from menu, ping the position
|
-- 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
|
||||||
|
else
|
||||||
|
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
|
||||||
|
|
||||||
|
-- if spawned from menu, move the camera and/or ping the table
|
||||||
if params.name then
|
if params.name then
|
||||||
spawnTable["callback_function"] = function(obj)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1034,6 +1063,41 @@ function contentDownloadCallback(request, params)
|
|||||||
end
|
end
|
||||||
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
|
-- downloading of the library file
|
||||||
function libraryDownloadCallback(request)
|
function libraryDownloadCallback(request)
|
||||||
if request.is_error or request.response_code ~= 200 then
|
if request.is_error or request.response_code ~= 200 then
|
||||||
|
Loading…
Reference in New Issue
Block a user