Jump to content

Spawning objects "randomly" without visiting the server?


Recommended Posts

Hi all.

I'm looking to inject a Shipwrecked Island Adventures shard into an existing cluster. The overall plan is this:

  • in Forest, remove 5 cave_entrances (plugged sinkholes, weren't traversed yet) from the world and hardwire the remaining cave_entrance_opens to Caves shard the same way they are connected automatically now. (done)
  • In caves, do the appropriate wiring on the 5 cave_exits that lead to existing cave_entrance_opens in the Forest. (done)
  • In unexplored Shipwrecked map, spawn 5 plugged sinkholes randomly on the islands, and hardwire them with the other 5 cave_exits in the caves. (???)

Is there a way to pick a "random place in the world for a cave_entrance" ? ie. x-shaped 4x4 pattern, somewhere on land (ie. tile with a turf from a set of "land" turfs).

On a somewhat related note - anyone encountered an issue where c_migrateto("1") puts you next to a particular cave_entrance, rather than multiplayer_portal_moonrock?

Link to comment
Share on other sites

7 hours ago, Satop said:

Why not do it manually?

Kinda spoils the excitement of exploration, when I've already been to the world and have parts of the map pre-revealed.

My buddy and I looked at the telestaff and if that's anything to go by, the game doesn't really have a better strategy than "keep picking random numbers until the position you pick is suitable".

Link to comment
Share on other sites

So, this should work "OK":

Spoiler

-- readable version:
local map = TheWorld.Map
local max = 1000
local count = 5
for i = 1, count do
  repeat
    x = math.random(-max, max)
    z = math.random(-max, max)
    local curr = map:GetTile(map:GetTileCoordsAtPoint(x, 0, z))
  until curr ~= GROUND.OCEAN_COASTAL and
    curr ~= GROUND.OCEAN_COASTAL_SHORE and
    curr ~= GROUND.OCEAN_SWELL and
    curr ~= GROUND.OCEAN_ROUGH and
    curr ~= GROUND.OCEAN_REEF and
    curr ~= GROUND.OCEAN_REEF_SHORE and
    curr ~= GROUND.OCEAN_HAZARDOUS and
    not (curr >= 50 and curr <= 55 ) and
    curr ~= 255 and
    curr ~= 1
  print("Picked a position: "..x.."; "..z)
  local plug = SpawnPrefab("cave_entrance")
  plug.Transform:SetPosition(x, 0, z)
end

-- paste-able version:
local map = TheWorld.Map local max = 1000 local count = 5 for i = 1,count do repeat x = math.random(-max, max) z = math.random(-max, max) local curr = map:GetTile(map:GetTileCoordsAtPoint(x, 0, z)) until curr ~= GROUND.OCEAN_COASTAL and curr ~= GROUND.OCEAN_COASTAL_SHORE and curr ~= GROUND.OCEAN_SWELL and curr ~= GROUND.OCEAN_ROUGH and curr ~= GROUND.OCEAN_REEF and curr ~= GROUND.OCEAN_REEF_SHORE and curr ~= GROUND.OCEAN_HAZARDOUS and not (curr >= 50 and curr <= 55 ) and curr ~= 255 and curr ~= 1 print("Picked a position: "..x.."; "..z) ThePlayer.Transform:SetPosition(x, 0, z) end

 

It "mostly" works, but isn't perfect.

  • Given the amount of shoreline in a world that's split up into a ton of islands, chances are pretty high at least some plugs will end up very close to land-sea boundary. Object with collision physics + land-sea border = not good.
  • Not taking into account other objects. It sometimes happens that a pickable/harvestable object become inaccessible because of the sinkhole.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...