diff options
Diffstat (limited to 'src/script/cpp_api')
-rw-r--r-- | src/script/cpp_api/s_env.cpp | 18 | ||||
-rw-r--r-- | src/script/cpp_api/s_env.h | 3 |
2 files changed, 21 insertions, 0 deletions
diff --git a/src/script/cpp_api/s_env.cpp b/src/script/cpp_api/s_env.cpp index b0de675ec..ee3783bb9 100644 --- a/src/script/cpp_api/s_env.cpp +++ b/src/script/cpp_api/s_env.cpp @@ -58,6 +58,24 @@ void ScriptApiEnv::environment_Step(float dtime) } } +void ScriptApiEnv::player_event(ServerActiveObject* player, std::string type) +{ + SCRIPTAPI_PRECHECKHEADER + + // Get minetest.registered_playerevents + lua_getglobal(L, "minetest"); + lua_getfield(L, -1, "registered_playerevents"); + + // Call callbacks + objectrefGetOrCreate(player); // player + lua_pushstring(L,type.c_str()); // event type + try { + script_run_callbacks(L, 2, RUN_CALLBACKS_MODE_FIRST); + } catch (LuaError &e) { + getServer()->setAsyncFatalError(e.what()); + } +} + void ScriptApiEnv::environment_OnMapgenInit(MapgenParams *mgparams) { SCRIPTAPI_PRECHECKHEADER diff --git a/src/script/cpp_api/s_env.h b/src/script/cpp_api/s_env.h index 51cf15036..33bd81ab3 100644 --- a/src/script/cpp_api/s_env.h +++ b/src/script/cpp_api/s_env.h @@ -37,6 +37,9 @@ public: // After initializing mapgens void environment_OnMapgenInit(MapgenParams *mgparams); + //called on player event + void player_event(ServerActiveObject* player, std::string type); + void initializeEnvironment(ServerEnvironment *env); }; |