summaryrefslogtreecommitdiff
path: root/src/scriptapi.cpp
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2012-01-06 00:12:33 +0200
committerPerttu Ahola <celeron55@gmail.com>2012-01-06 00:12:33 +0200
commit4f2c1e36a10ee00c6779a02dd4441fa680fb3497 (patch)
tree5987efecaf095260f72e91b69a3d215b699db205 /src/scriptapi.cpp
parentbc743ca7ced997e75ee72b8f493f6ffb14879aad (diff)
downloadminetest-4f2c1e36a10ee00c6779a02dd4441fa680fb3497.tar.gz
minetest-4f2c1e36a10ee00c6779a02dd4441fa680fb3497.tar.bz2
minetest-4f2c1e36a10ee00c6779a02dd4441fa680fb3497.zip
Implement minetest.register_on_dieplayer()
Diffstat (limited to 'src/scriptapi.cpp')
-rw-r--r--src/scriptapi.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp
index 35b597337..8321a4529 100644
--- a/src/scriptapi.cpp
+++ b/src/scriptapi.cpp
@@ -3638,6 +3638,32 @@ void scriptapi_on_newplayer(lua_State *L, ServerActiveObject *player)
// value removed, keep key for next iteration
}
}
+
+void scriptapi_on_dieplayer(lua_State *L, ServerActiveObject *player)
+{
+ realitycheck(L);
+ assert(lua_checkstack(L, 20));
+ StackUnroller stack_unroller(L);
+
+ // Get minetest.registered_on_dieplayers
+ lua_getglobal(L, "minetest");
+ lua_getfield(L, -1, "registered_on_dieplayers");
+ luaL_checktype(L, -1, LUA_TTABLE);
+ int table = lua_gettop(L);
+ // Foreach
+ lua_pushnil(L);
+ while(lua_next(L, table) != 0){
+ // key at index -2 and value at index -1
+ luaL_checktype(L, -1, LUA_TFUNCTION);
+ // Call function
+ objectref_get_or_create(L, player);
+ if(lua_pcall(L, 1, 0, 0))
+ script_error(L, "error: %s", lua_tostring(L, -1));
+ // value removed, keep key for next iteration
+ }
+}
+
+
bool scriptapi_on_respawnplayer(lua_State *L, ServerActiveObject *player)
{
realitycheck(L);