diff --git a/static_spawn/init.lua b/static_spawn/init.lua index 8e0716a..ba49560 100644 --- a/static_spawn/init.lua +++ b/static_spawn/init.lua @@ -1,69 +1,103 @@ -- twi_mods/static_spawn/init.lua --[[ Copyright (C) 2014-2021 AndrejIT, spfar, mightyjoe781 Copyright (C) 2024 1F616EMO This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ]] S = minetest.get_translator("spawn") minetest.register_chatcommand("spawn", { description = S("Teleport to spawnpoint"), privs = { home = true }, func = function(name) local player = minetest.get_player_by_name(name) if not player then return false, S("Player object not found.") end local spawn_pos = minetest.setting_get_pos("static_spawnpoint") if not spawn_pos then return false, S("Spawn point not set. Consult moderators to set a proper static spawnpoint.") end player:set_pos(spawn_pos) return true, S("Teleported to Spawn!") end }) minetest.register_chatcommand("setspawn", { description = S("Override the static spawnpoint"), privs = { server = true }, param = "[]", func = function(name, param) if param == "" then local player = minetest.get_player_by_name(name) if not player then return false, S("Player object not found.") end param = minetest.pos_to_string(player:get_pos(), 0) else local pos = core.string_to_pos(param) if not pos then return false, S("Invalid position given.") end param = minetest.pos_to_string(pos) end minetest.settings:set("static_spawnpoint", param) return true, S("Static spawnpoint set to @1.", param) end }) + +local last_shouted_spawn = {} + +beerchat.register_on_chat_message(function(name, message) + local player = minetest.get_player_by_name(name) + local spawn_pos = minetest.setting_get_pos("static_spawnpoint") + if not (player and spawn_pos) then return end + message = string.trim(message) + message = string.lower(message) + + if message == "spawn" then + local now = os.time() + if last_shouted_spawn[name] + and now - last_shouted_spawn[name] < 30 then + player:set_pos(spawn_pos) + last_shouted_spawn[name] = nil + else + last_shouted_spawn[name] = now + end + minetest.after(0, function() + if minetest.get_player_by_name(name) then + minetest.chat_send_player(name, minetest.colorize("orange", + S("Tips! Put a slash (/) before \"spawn\" (i.e. /spawn) to teleport back Spawn instantly."))) + end + end) + else + last_shouted_spawn[name] = nil + end +end) + +minetest.register_on_leaveplayer(function(player) + local name = player:get_player_name() + last_shouted_spawn[name] = nil +end) diff --git a/static_spawn/locale/template.txt b/static_spawn/locale/template.txt index aaa0b9c..b71bd18 100644 --- a/static_spawn/locale/template.txt +++ b/static_spawn/locale/template.txt @@ -1,10 +1,11 @@ # textdomain: static_spawn ##[ init.lua ]## Teleport to spawnpoint= Player object not found.= Spawn point not set. Consult moderators to set a proper static spawnpoint.= Teleported to Spawn!= Override the static spawnpoint= Invalid position given.= Static spawnpoint set to @1.= +Tips! Put a slash (/) before "spawn" (i.e. /spawn) to teleport back Spawn instantly.= diff --git a/static_spawn/mod.conf b/static_spawn/mod.conf index 6e03886..0e6fb26 100644 --- a/static_spawn/mod.conf +++ b/static_spawn/mod.conf @@ -1 +1,2 @@ -name = static_spawn \ No newline at end of file +name = static_spawn +depends = beerchat