Make /setspawn world specific (#67)
parent
7b0794d243
commit
357d3aaf8e
|
@ -1172,7 +1172,8 @@ core.register_chatcommand("spawn", {
|
||||||
if not player then
|
if not player then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
local spawnpoint = core.setting_get_pos("static_spawnpoint")
|
local spawnpoint = core.setting_get_pos("static_spawnpoint") or
|
||||||
|
core.get_world_spawnpoint()
|
||||||
if spawnpoint then
|
if spawnpoint then
|
||||||
player:set_pos(spawnpoint)
|
player:set_pos(spawnpoint)
|
||||||
return true, "Teleporting to spawn..."
|
return true, "Teleporting to spawn..."
|
||||||
|
@ -1190,9 +1191,20 @@ core.register_chatcommand("setspawn", {
|
||||||
if not player then
|
if not player then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
local pos = core.pos_to_string(player:get_pos(), 1)
|
|
||||||
core.settings:set("static_spawnpoint", pos)
|
-- Round the player's position to one decimal place
|
||||||
core.settings:write()
|
local pos = vector.apply(player:get_pos(), function(dir)
|
||||||
return true, "The spawn point are set to " .. pos
|
return math.floor(dir * 10 + 0.5) / 10
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Remove the static_spawnpoint setting if it exists
|
||||||
|
if core.settings:get("static_spawnpoint") then
|
||||||
|
core.settings:remove("static_spawnpoint")
|
||||||
|
core.settings:write()
|
||||||
|
end
|
||||||
|
|
||||||
|
core.set_world_spawnpoint(pos)
|
||||||
|
|
||||||
|
return true, "The spawn point has been set to " .. core.pos_to_string(pos)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
|
@ -25,7 +25,6 @@ dofile(gamepath .. "auth.lua")
|
||||||
dofile(commonpath .. "chatcommands.lua")
|
dofile(commonpath .. "chatcommands.lua")
|
||||||
dofile(gamepath .. "chat.lua")
|
dofile(gamepath .. "chat.lua")
|
||||||
dofile(commonpath .. "information_formspecs.lua")
|
dofile(commonpath .. "information_formspecs.lua")
|
||||||
dofile(gamepath .. "static_spawn.lua")
|
|
||||||
dofile(gamepath .. "detached_inventory.lua")
|
dofile(gamepath .. "detached_inventory.lua")
|
||||||
assert(loadfile(gamepath .. "falling.lua"))(builtin_shared)
|
assert(loadfile(gamepath .. "falling.lua"))(builtin_shared)
|
||||||
dofile(gamepath .. "features.lua")
|
dofile(gamepath .. "features.lua")
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
-- Minetest: builtin/static_spawn.lua
|
|
||||||
|
|
||||||
local static_spawnpoint_string = core.settings:get("static_spawnpoint")
|
|
||||||
if static_spawnpoint_string and
|
|
||||||
static_spawnpoint_string ~= "" and
|
|
||||||
not core.setting_get_pos("static_spawnpoint") then
|
|
||||||
error('The static_spawnpoint setting is invalid: "' ..
|
|
||||||
static_spawnpoint_string .. '"')
|
|
||||||
end
|
|
||||||
|
|
||||||
local function put_player_in_spawn(player_obj)
|
|
||||||
local static_spawnpoint = core.setting_get_pos("static_spawnpoint")
|
|
||||||
if not static_spawnpoint then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
core.log("action", "Moving " .. player_obj:get_player_name() ..
|
|
||||||
" to static spawnpoint at " .. core.pos_to_string(static_spawnpoint))
|
|
||||||
player_obj:set_pos(static_spawnpoint)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
core.register_on_newplayer(put_player_in_spawn)
|
|
||||||
core.register_on_respawnplayer(put_player_in_spawn)
|
|
|
@ -5283,6 +5283,12 @@ Environment access
|
||||||
* The spawn level returned is for a player spawn in unmodified terrain.
|
* The spawn level returned is for a player spawn in unmodified terrain.
|
||||||
* The spawn level is intentionally above terrain level to cope with
|
* The spawn level is intentionally above terrain level to cope with
|
||||||
full-node biome 'dust' nodes.
|
full-node biome 'dust' nodes.
|
||||||
|
* `minetest.set_world_spawnpoint([pos])`
|
||||||
|
* Sets the world-specific spawnpoint to pos (or `nil` to reset).
|
||||||
|
* If `static_spawnpoint` is specified in multicraft.conf, the
|
||||||
|
world-specific spawnpoint will be ignored.
|
||||||
|
* `minetest.get_world_spawnpoint()`
|
||||||
|
* Returns the world-specific spawnpoint.
|
||||||
|
|
||||||
Mod channels
|
Mod channels
|
||||||
------------
|
------------
|
||||||
|
|
|
@ -748,7 +748,7 @@ int ModApiEnvMod::l_get_objects_in_area(lua_State *L)
|
||||||
{
|
{
|
||||||
GET_ENV_PTR;
|
GET_ENV_PTR;
|
||||||
ScriptApiBase *script = getScriptApiBase(L);
|
ScriptApiBase *script = getScriptApiBase(L);
|
||||||
|
|
||||||
v3f minp = read_v3f(L, 1) * BS;
|
v3f minp = read_v3f(L, 1) * BS;
|
||||||
v3f maxp = read_v3f(L, 2) * BS;
|
v3f maxp = read_v3f(L, 2) * BS;
|
||||||
aabb3f box(minp, maxp);
|
aabb3f box(minp, maxp);
|
||||||
|
@ -1416,6 +1416,34 @@ int ModApiEnvMod::l_get_translated_string(lua_State * L)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get_world_spawnpoint()
|
||||||
|
int ModApiEnvMod::l_get_world_spawnpoint(lua_State * L)
|
||||||
|
{
|
||||||
|
GET_ENV_PTR;
|
||||||
|
|
||||||
|
v3f spawnpoint;
|
||||||
|
if (!env->getWorldSpawnpoint(spawnpoint))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
push_v3f(L, spawnpoint);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set_world_spawnpoint(spawnpoint)
|
||||||
|
int ModApiEnvMod::l_set_world_spawnpoint(lua_State * L)
|
||||||
|
{
|
||||||
|
GET_ENV_PTR;
|
||||||
|
|
||||||
|
if (lua_isnil(L, 1)) {
|
||||||
|
env->resetWorldSpawnpoint();
|
||||||
|
} else {
|
||||||
|
const v3f spawnpoint = read_v3f(L, 1);
|
||||||
|
env->setWorldSpawnpoint(spawnpoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void ModApiEnvMod::Initialize(lua_State *L, int top)
|
void ModApiEnvMod::Initialize(lua_State *L, int top)
|
||||||
{
|
{
|
||||||
API_FCT(set_node);
|
API_FCT(set_node);
|
||||||
|
@ -1466,6 +1494,8 @@ void ModApiEnvMod::Initialize(lua_State *L, int top)
|
||||||
API_FCT(forceload_block);
|
API_FCT(forceload_block);
|
||||||
API_FCT(forceload_free_block);
|
API_FCT(forceload_free_block);
|
||||||
API_FCT(get_translated_string);
|
API_FCT(get_translated_string);
|
||||||
|
API_FCT(get_world_spawnpoint);
|
||||||
|
API_FCT(set_world_spawnpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModApiEnvMod::InitializeClient(lua_State *L, int top)
|
void ModApiEnvMod::InitializeClient(lua_State *L, int top)
|
||||||
|
|
|
@ -114,7 +114,7 @@ private:
|
||||||
|
|
||||||
// get_objects_inside_radius(pos, radius)
|
// get_objects_inside_radius(pos, radius)
|
||||||
static int l_get_objects_inside_radius(lua_State *L);
|
static int l_get_objects_inside_radius(lua_State *L);
|
||||||
|
|
||||||
// get_objects_in_area(pos, minp, maxp)
|
// get_objects_in_area(pos, minp, maxp)
|
||||||
static int l_get_objects_in_area(lua_State *L);
|
static int l_get_objects_in_area(lua_State *L);
|
||||||
|
|
||||||
|
@ -198,6 +198,12 @@ private:
|
||||||
// Get a string translated server side
|
// Get a string translated server side
|
||||||
static int l_get_translated_string(lua_State * L);
|
static int l_get_translated_string(lua_State * L);
|
||||||
|
|
||||||
|
// Get the world-specific spawnpoint
|
||||||
|
static int l_get_world_spawnpoint(lua_State *L);
|
||||||
|
|
||||||
|
// Set the world-specific spawnpoint
|
||||||
|
static int l_set_world_spawnpoint(lua_State *L);
|
||||||
|
|
||||||
/* Helpers */
|
/* Helpers */
|
||||||
|
|
||||||
static void collectNodeIds(lua_State *L, int idx,
|
static void collectNodeIds(lua_State *L, int idx,
|
||||||
|
|
|
@ -2970,7 +2970,11 @@ void Server::RespawnPlayer(session_t peer_id)
|
||||||
bool repositioned = m_script->on_respawnplayer(playersao);
|
bool repositioned = m_script->on_respawnplayer(playersao);
|
||||||
if (!repositioned) {
|
if (!repositioned) {
|
||||||
// setPos will send the new position to client
|
// setPos will send the new position to client
|
||||||
playersao->setPos(findSpawnPos());
|
const v3f pos = findSpawnPos();
|
||||||
|
actionstream << "Moving " << playersao->getPlayer()->getName() <<
|
||||||
|
" to spawnpoint at (" << pos.X << ", " << pos.Y << ", " <<
|
||||||
|
pos.Z << ")" << std::endl;
|
||||||
|
playersao->setPos(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
SendPlayerHP(peer_id);
|
SendPlayerHP(peer_id);
|
||||||
|
@ -3816,7 +3820,8 @@ v3f Server::findSpawnPos()
|
||||||
{
|
{
|
||||||
ServerMap &map = m_env->getServerMap();
|
ServerMap &map = m_env->getServerMap();
|
||||||
v3f nodeposf;
|
v3f nodeposf;
|
||||||
if (g_settings->getV3FNoEx("static_spawnpoint", nodeposf))
|
if (g_settings->getV3FNoEx("static_spawnpoint", nodeposf) ||
|
||||||
|
m_env->getWorldSpawnpoint(nodeposf))
|
||||||
return nodeposf * BS;
|
return nodeposf * BS;
|
||||||
|
|
||||||
bool is_good = false;
|
bool is_good = false;
|
||||||
|
|
|
@ -648,6 +648,10 @@ void ServerEnvironment::saveMeta()
|
||||||
args.set("lbm_introduction_times",
|
args.set("lbm_introduction_times",
|
||||||
m_lbm_mgr.createIntroductionTimesString());
|
m_lbm_mgr.createIntroductionTimesString());
|
||||||
args.setU64("day_count", m_day_count);
|
args.setU64("day_count", m_day_count);
|
||||||
|
|
||||||
|
if (m_has_world_spawnpoint)
|
||||||
|
args.setV3F("static_spawnpoint", m_world_spawnpoint);
|
||||||
|
|
||||||
args.writeLines(ss);
|
args.writeLines(ss);
|
||||||
|
|
||||||
if(!fs::safeWriteToFile(path, ss.str()))
|
if(!fs::safeWriteToFile(path, ss.str()))
|
||||||
|
@ -721,6 +725,8 @@ void ServerEnvironment::loadMeta()
|
||||||
|
|
||||||
m_day_count = args.exists("day_count") ?
|
m_day_count = args.exists("day_count") ?
|
||||||
args.getU64("day_count") : 0;
|
args.getU64("day_count") : 0;
|
||||||
|
|
||||||
|
m_has_world_spawnpoint = args.getV3FNoEx("static_spawnpoint", m_world_spawnpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -374,6 +374,21 @@ public:
|
||||||
*/
|
*/
|
||||||
void loadDefaultMeta();
|
void loadDefaultMeta();
|
||||||
|
|
||||||
|
bool getWorldSpawnpoint(v3f &spawnpoint) {
|
||||||
|
if (m_has_world_spawnpoint)
|
||||||
|
spawnpoint = m_world_spawnpoint;
|
||||||
|
return m_has_world_spawnpoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setWorldSpawnpoint(const v3f &spawnpoint) {
|
||||||
|
m_world_spawnpoint = spawnpoint;
|
||||||
|
m_has_world_spawnpoint = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void resetWorldSpawnpoint() {
|
||||||
|
m_has_world_spawnpoint = false;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static PlayerDatabase *openPlayerDatabase(const std::string &name,
|
static PlayerDatabase *openPlayerDatabase(const std::string &name,
|
||||||
const std::string &savedir, const Settings &conf);
|
const std::string &savedir, const Settings &conf);
|
||||||
|
@ -485,5 +500,8 @@ private:
|
||||||
std::vector<std::string> m_compat_player_models;
|
std::vector<std::string> m_compat_player_models;
|
||||||
bool m_compat_send_original_model;
|
bool m_compat_send_original_model;
|
||||||
|
|
||||||
|
v3f m_world_spawnpoint = v3f(0.f, 0.f, 0.f);
|
||||||
|
bool m_has_world_spawnpoint = false;
|
||||||
|
|
||||||
ServerActiveObject* createSAO(ActiveObjectType type, v3f pos, const std::string &data);
|
ServerActiveObject* createSAO(ActiveObjectType type, v3f pos, const std::string &data);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue