[0.17.68] LuaForce::SetSpawnPosition LuaForce::GetSpawnPosition

Place to get help with not working mods / modding interface.
PyroFire
Filter Inserter
Filter Inserter
Posts: 356
Joined: Tue Mar 08, 2016 8:18 am
Contact:

[0.17.68] LuaForce::SetSpawnPosition LuaForce::GetSpawnPosition

Post 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)
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3749
Joined: Tue May 13, 2014 11:06 am
Contact:

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

Post 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
PyroFire
Filter Inserter
Filter Inserter
Posts: 356
Joined: Tue Mar 08, 2016 8:18 am
Contact:

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

Post 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?
Bilka
Factorio Staff
Factorio Staff
Posts: 3464
Joined: Sat Aug 13, 2016 9:20 am
Contact:

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

Post by Bilka »

The player spawns on the surface they died on. Moving to modding help.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5412
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

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

Post 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.
Post Reply

Return to “Modding help”