Page 1 of 1

[0.17.68] LuaForce::SetSpawnPosition LuaForce::GetSpawnPosition

Posted: Sun Sep 08, 2019 8:04 am
by PyroFire
https://lua-api.factorio.com/latest/LuaForce.html#LuaForce.set_spawn_position wrote: set_spawn_position(position, surface)

Parameters
position :: Position: The new position on the given surface.
surface :: SurfaceSpecification: Surface to set the spawn position for.
https://lua-api.factorio.com/latest/LuaForce.html#LuaForce.get_spawn_position wrote: get_spawn_position(surface) → Position

Parameters
surface :: SurfaceSpecification
Why is the surface a parameter and not a returned value?

Code: Select all

local position,surface = myForce.get_spawn_position()
???????????????

An event would be nice too

Code: Select all

script.on_event(defines.events.on_player_spawn_position_changed,function(ev)
local surface=game.surfaces[ev.surface_index]
local player=game.players[ev.player_index]
end)

Re: [0.17.68] LuaForce::SetSpawnPosition LuaForce::GetSpawnPosition

Posted: Sun Sep 08, 2019 8:06 am
by DaveMcW

Code: Select all

for _, surface in pairs(game.surfaces) do
  local position = myForce.get_spawn_position(surface)
  -- Do stuff with position, surface
end

Re: [0.17.68] LuaForce::SetSpawnPosition LuaForce::GetSpawnPosition

Posted: Sun Sep 08, 2019 8:09 am
by PyroFire
But this would assume there is a spawn position for each surface.

Sure, that can be a thing, but the player only spawns on one surface set by LuaForce::SetSpawnPosition.
How do i know which one it is set to?

Re: [0.17.68] LuaForce::SetSpawnPosition LuaForce::GetSpawnPosition

Posted: Sun Sep 08, 2019 8:18 am
by Bilka
The player spawns on the surface they died on. Moving to modding help.

Re: [0.17.68] LuaForce::SetSpawnPosition LuaForce::GetSpawnPosition

Posted: Sun Sep 08, 2019 10:12 am
by Klonan
The force has a separate spawn point for each surface,
E.G, surface 1 can have the spawn point {100, 100},
And surface 2 can have the spawn point {5000, -1000}

If a player dies on surface 1, he will respawn at {100, 100},
If the player dies on surface 2, he will respawn at {5000, -1000}

So when setting and getting the spawn point, it needs to know which surface you mean.