#Random spawn points

1 messages · Page 1 of 1 (latest)

warm raft
#

This is probably super unoptimzied and messy. But I am trying to make it to where when an object with a "spawn" value is detected, the player can randomly spawn between these locations:

const spawns = world.getDimension('overworld').getEntities({ type: 'chaotic:multi' }).filter(e => e.getDynamicProperty('multiType') === 'spawn').sort(() => Math.random() - Math.random())
const rng = spawns.length;
const random2 = Math.floor(Math.random() * (rng - 1 + 1)) + 1
const spawn = spawns[random2]
const x = spawn.location.x
const y = spawn.location.y
const z = spawn.location.z
const dimension = world.getDimension('overworld')
player.camera.fade({ fadeColor: { red: 0, green: 0, blue: 0 }, fadeTime: { fadeInTime: 0, fadeOutTime: 1, holdTime: 0 } })
// if (players[spawnNumber]) players[spawnNumber].teleport({ x: x, y: y, z: z })
player.setSpawnPoint({dimension:dimension,x:x,y:y,z:z})

It's probably explanatory on what im trying to do, however this is really bad of an approach it seems because it sometimes doesen't change my spawn at all, fails to get entity locations, and other issues.

warm raft
#

Still not able to figure this out really

manic wagon
warm raft
warm raft
#

Yeah..

neat patrol
#

something like this perhaps, havent tested but the logic should check out - when player dies change their spawnpoint to a random one from a list. You can have a list per dimension and do some improvements to the code to make it work. let me know if this helps

const spawns = [{x:0,y:0,z:24},{x:344,y:0,z:24},{x:0,y:0,z:222}]

world.afterEvents.entityDie.subscribe((event) => {
  const deadPlayer= event.deadEntity;
  if (deadPlayer instanceof Player) {
  const randomSpawnPoint = spawns[Math.round(Math.random()*(spawns.length-1))]
  deadPlayer.setSpawnPoint({dimension: deadPlayer.dimension,   x:randomSpawnPoint.x,y:randomSpawnPoint.y,z:randomSpawnPoint.z})
}
 
});
warm raft
neat patrol
#

you can still do that with this system - just have an entity update the spawns array with its current location. either on its own spawn event or whichever other time you need.