Page 1 of 1

Programmatic access to "player spawns"?

PostPosted: Sat Sep 05, 2015 12:40
by Ben
Hello everyone,

I'm browsing docs and code, trying to understand the "player spawn point" system. Here's what I have so far:

  1. There is a "static_spawn_point" setting in minetest.conf. That will cause all players to respawn at this point. Dunno if you can read this setting, but I'm not interested in a global spawn point.
  2. Mods (e.g. beds) "set a player's spawn point" by remembering a position in some internal variable, registering a handler on_respawn_player, and teleporting the player.
  3. There are /sethome and /home commands from Minetest Game (mod "sethome"). These are saved in a local variable, too, and inaccessible to other mods.

Is that it? Have I missed anything relevant? If not, can we talk about this? Because what I would like is a standardized way for mods to read and set a player's spawn point / home point.

I do realize that a player may not even have a fixed spawn point; for example, if we wanted to emulate World of Warcraft™ a bit more, players would respawn "at the nearest graveyard" (and have a hearthstone, with cooldown, instead of /home. But that's a different idea.)

Re: Programmatic access to "player spawns"?

PostPosted: Sat Sep 05, 2015 13:24
by BobbyBonsaimind
The static spawn point can be read by using minetest.setting_get_pos("static_spawnpoint"). Additionally you can register a function at minetest.register_on_respawnplayer(function) which allows you to override the spawn point of the player. The function that you register just needs to return true, and the default mechanism will be disabled for the spawn of the player.

Also don't forget that the first join does not count as respawn as far as I know, so you need to also register a function at minetest.register_on_newplayer(function).

Otherwise that's it. You can have a look at my Spawn Usher mod, which makes sure that the player does not spawn in solid nodes. The spawnusher.on_spawn_player() function should be the most interesting one, as it combines all of these aspects.

Re: Programmatic access to "player spawns"?

PostPosted: Sat Sep 05, 2015 19:50
by Ben
Thanks, maybe I wasn't clear: I'm not looking for "how can I change a player's spawn point", but other aspects. Say I wanted to point to a player's spawn point (or home point) on the minimap, or a compass mod. I'd need to know or find out which mod (or mods!) control the on_respawn behaviour, and then ask them for the coordinates.

Or say I wanted to add a method to set the spawn point: you can now sleep in a bed or activate a spirit totem node. I'd need to write the new position into beds, which it is (surprise!) not prepared to do.

I think it goes deeper: who here thinks that, at any time, each player "has a spawn point"? And who doesn't?

Your Spawn Usher mod, incidently, is quite interesting: it is a kind of "spawn controller", but it itself delegates the actual spawn point to "providers". So I wouldn't be able to ask the usher, either ;-) Do you have any examples of providers, by the way?

Re: Programmatic access to "player spawns"?

PostPosted: Sat Sep 05, 2015 20:25
by BobbyBonsaimind
Yes, the mods would need to support that otherwise you'll have a really hard time. Though, Lua actually helps you there, as there are no private or protected variables in Lua, only local ones. There is a really good chance that the information you need is actually accessible in one way or another. But to add support in the mod would actually be the best course of action, obviously.

You are right, I completely missed to properly document it, I have added documentation for the providers and the callbacks to the README. Also it does only partly move the control to the providers, by default it picks a random location around the static spawn point and then invokes the providers which can override that position.
What you missed (and I completely forgot about) is that you can also register after spawn callbacks, which will tell you the final spawn point of the player. That combination would allow you to override the spawn point if you want to.