aboutsummaryrefslogtreecommitdiff
path: root/src
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 /src
parentda71e86633d0b27cd02d7aac9fdac625d141ca13 (diff)
downloadminetest-f195db2d140a7b4f2f2fbc438680c9d5e23a0d6d.tar.gz
minetest-f195db2d140a7b4f2f2fbc438680c9d5e23a0d6d.tar.bz2
minetest-f195db2d140a7b4f2f2fbc438680c9d5e23a0d6d.zip
Add API function to invoke player respawn
closes #12272
Diffstat (limited to 'src')
-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
4 files changed, 25 insertions, 3 deletions
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);