diff --git a/README.md b/README.md index 7f720d3..a3f12a0 100644 --- a/README.md +++ b/README.md @@ -8,13 +8,19 @@ Static Spawnpoint [spawnpoint] This is a rather simple mod introducing two commands to set a static spawnpoint and to teleport to it. Yes, I know you can set this in `minetest.conf`, however, doing so causes the spawnpoint to be the same across all of your worlds (very inconvenient). Instead of using `minetest.conf`, this mod stores the spawnpoint as a string in a file called `spawnpoint.conf` in the world directory. This allows each and every world to have a different spawnpoint. -The most unique thing about this spawn mod, is that it includes a feature allowing you to set the time between executing the command until the player is actually teleported. By default, the teleportation will be interupted if the player moves within that time. The time can be configured in `minetest.conf` with `spawnpoint.time` (if `0`, players will be immediately teleported), and you can disable the feature requiring players to stand still by setting `spawnpoint.do_not_move` to `false` (default: `true`). +The most unique thing about this spawn mod, is that it includes a feature allowing you to set the time between executing the command until the player is actually teleported. By default, the teleportation will be interupted if the player moves within that time. The time and the feature requiring players to stand still can be configured as documented below in the configuration section. ### Commands -- `/spawnpoint`: Display spawnpoint position if set +- `/spawnpoint`: Display spawnpoint position if set (also see configuration section) - `/spawn `: Teleports you or the player specified to the spawnpoint (requires `spawn` privilege, and `bring` privilege to teleport another player) - `/setspawn `: Sets the spawn to the position specified (in format `x, y, z`) or to your current location (requires `server` privilege) -__Note:__ If no spawnpoint is specified, the player will be told "No spawnpoint set!" +__Note:__ If no spawnpoint is specified and a player attempts to execute `/spawn`, he/she will be told "No spawnpoint set!" -Screenshot was taken at spawn on the awesome [HOMETOWN](https://forum.minetest.net/viewtopic.php?f=10&t=16699) server! +### Configuration +The different "variables" of SpawnPoint can be configured per-world using the `/spawnpoint` command. By default this command displays the spawnpoint, but when providing a setting name as well, the value of the setting is returned (assuming such a setting exists). If a setting name and value is provided, the setting is changed. Valid setting names are listed below. + +* `time`: Time before teleportation is completed (if `0` teleportation is immediate) +* `do_not_move`: Whether a player should be required to not move to allow teleportation to be successful + +Screenshot was taken at spawn on the awesome [HOMETOWN](https://forum.minetest.net/viewtopic.php?f=10&t=16699) server! \ No newline at end of file diff --git a/init.lua b/init.lua index 138b00b..c2daf68 100644 --- a/init.lua +++ b/init.lua @@ -2,9 +2,6 @@ spawnpoint = {} -spawnpoint.time = tonumber(minetest.setting_get("spawnpoint.time")) or 3 -spawnpoint.do_not_move = not not minetest.setting_get("spawnpoint.do_not_move") or true - local path = minetest.get_worldpath().."/spawnpoint.conf" -- [function] Log @@ -54,18 +51,30 @@ end function spawnpoint.load() local res = io.open(path, "r") if res then - res = res:read("*all") - if res ~= "" then - spawnpoint.pos = minetest.string_to_pos(res) + res = res:read("*all"):split("\n", true) + + spawnpoint.time = tonumber(res[1]) or 3 + spawnpoint.do_not_move = not not res[2] or true + + if res[3] then + spawnpoint.pos = minetest.string_to_pos(res[3]) end + else + spawnpoint.time = 3 + spawnpoint.do_not_move = true end end -- [function] Save function spawnpoint.save() + local str = tostring(spawnpoint.time).. + "\n"..tostring(spawnpoint.do_not_move) or "" + if spawnpoint.pos then - io.open(path, "w"):write(minetest.pos_to_string(spawnpoint.pos)) + str = str.."\n"..minetest.pos_to_string(spawnpoint.pos) end + + io.open(path, "w"):write(str) end -- [function] Set @@ -220,15 +229,41 @@ minetest.register_chatcommand("spawn", { end, }) --- [register cmd] Get spawn +-- [register cmd] Manage spawnpoint minetest.register_chatcommand("spawnpoint", { - description = "Get SpawnPoint information", + description = "Get/Set SpawnPoint information", func = function(name, param) - local pos = "Not set!" - if spawnpoint.pos then - pos = minetest.pos_to_string(spawnpoint.pos) - end + if not param or param == "" then + local pos = "Not set!" + if spawnpoint.pos then + pos = minetest.pos_to_string(spawnpoint.pos) + end - return true, "SpawnPoint Position: "..pos + return true, "SpawnPoint Position: "..pos + elseif minetest.check_player_privs(minetest.get_player_by_name(name), {server=true}) then + local p = param:split(" ") + + if p[1] == "time" then + local num = tonumber(p[2]) + + if not num then + return true, "SpawnPoint->time: "..spawnpoint.time + elseif num == spawnpoint.time then + return false, "Time already set to "..p[2].."!" + else + spawnpoint.time = num + return true, "Set time to "..tostring(num) + end + elseif p[1] == "do_not_move" then + local move = minetest.is_yes(p[2]) + minetest.log("action", dump(p[2])..", "..dump(move)) + if move == nil then + return true, "SpawnPoint->do_not_move: "..tostring(spawnpoint.do_not_move) + else + spawnpoint.do_not_move = move + return true, "Set do_not_move to "..tostring(move) + end + end + end end, })