aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2022-05-25 19:29:11 +0200
committersfan5 <sfan5@live.de>2022-05-29 14:00:19 +0200
commitf195db2d140a7b4f2f2fbc438680c9d5e23a0d6d (patch)
treeaf2e07480ea04277ed2a8d16af42e9e86526f8fe
parentda71e86633d0b27cd02d7aac9fdac625d141ca13 (diff)
downloadminetest-f195db2d140a7b4f2f2fbc438680c9d5e23a0d6d.tar.gz
minetest-f195db2d140a7b4f2f2fbc438680c9d5e23a0d6d.tar.bz2
minetest-f195db2d140a7b4f2f2fbc438680c9d5e23a0d6d.zip
Add API function to invoke player respawn
closes #12272
-rw-r--r--doc/lua_api.txt2
-rw-r--r--src/script/lua_api/l_object.cpp17
-rw-r--r--src/script/lua_api/l_object.h3
-rw-r--r--src/server.cpp5
-rw-r--r--src/server.h3
5 files changed, 27 insertions, 3 deletions
diff --git a/doc/lua_api.txt b/doc/lua_api.txt
index 882c9c54c..15a067a5e 100644
--- a/doc/lua_api.txt
+++ b/doc/lua_api.txt
@@ -7099,6 +7099,8 @@ object you are working with still exists.
* `intensity` sets the intensity of the shadows from 0 (no shadows, default) to 1 (blackness)
* `get_lighting()`: returns the current state of lighting for the player.
* Result is a table with the same fields as `light_definition` in `set_lighting`.
+* `respawn()`: Respawns the player using the same mechanism as the death screen,
+ including calling on_respawnplayer callbacks.
`PcgRandom`
-----------
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index 39b19364e..37ba1521a 100644
--- a/src/script/lua_api/l_object.cpp
+++ b/src/script/lua_api/l_object.cpp
@@ -2323,6 +2323,21 @@ int ObjectRef::l_get_lighting(lua_State *L)
return 1;
}
+// respawn(self)
+int ObjectRef::l_respawn(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ ObjectRef *ref = checkobject(L, 1);
+ RemotePlayer *player = getplayer(ref);
+ if (player == nullptr)
+ return 0;
+
+ getServer(L)->RespawnPlayer(player->getPeerId());
+ lua_pushboolean(L, true);
+ return 1;
+}
+
+
ObjectRef::ObjectRef(ServerActiveObject *object):
m_object(object)
{}
@@ -2478,5 +2493,7 @@ luaL_Reg ObjectRef::methods[] = {
luamethod(ObjectRef, set_minimap_modes),
luamethod(ObjectRef, set_lighting),
luamethod(ObjectRef, get_lighting),
+ luamethod(ObjectRef, respawn),
+
{0,0}
};
diff --git a/src/script/lua_api/l_object.h b/src/script/lua_api/l_object.h
index 3e4e6681a..b36bab492 100644
--- a/src/script/lua_api/l_object.h
+++ b/src/script/lua_api/l_object.h
@@ -382,4 +382,7 @@ private:
// get_lighting(self)
static int l_get_lighting(lua_State *L);
+
+ // respawn(self)
+ static int l_respawn(lua_State *L);
};
diff --git a/src/server.cpp b/src/server.cpp
index b6330c96a..c775f5d07 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -2784,9 +2784,10 @@ void Server::RespawnPlayer(session_t peer_id)
<< playersao->getPlayer()->getName()
<< " respawns" << std::endl;
- playersao->setHP(playersao->accessObjectProperties()->hp_max,
+ const auto *prop = playersao->accessObjectProperties();
+ playersao->setHP(prop->hp_max,
PlayerHPChangeReason(PlayerHPChangeReason::RESPAWN));
- playersao->setBreath(playersao->accessObjectProperties()->breath_max);
+ playersao->setBreath(prop->breath_max);
bool repositioned = m_script->on_respawnplayer(playersao);
if (!repositioned) {
diff --git a/src/server.h b/src/server.h
index 71f692e87..a9c5bcb5f 100644
--- a/src/server.h
+++ b/src/server.h
@@ -336,6 +336,8 @@ public:
void setLighting(RemotePlayer *player, const Lighting &lighting);
+ void RespawnPlayer(session_t peer_id);
+
/* con::PeerHandler implementation. */
void peerAdded(con::Peer *peer);
void deletingPeer(con::Peer *peer, bool timeout);
@@ -529,7 +531,6 @@ private:
*/
void HandlePlayerDeath(PlayerSAO* sao, const PlayerHPChangeReason &reason);
- void RespawnPlayer(session_t peer_id);
void DeleteClient(session_t peer_id, ClientDeletionReason reason);
void UpdateCrafting(RemotePlayer *player);
bool checkInteractDistance(RemotePlayer *player, const f32 d, const std::string &what);