diff options
author | JDiaz <runspect@gmail.com> | 2021-01-11 18:03:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-11 18:03:31 +0100 |
commit | 08ee9794fbc0960a8aab1af21d34f40685809e75 (patch) | |
tree | eb6acad972eca4793159c95519b4deb6e05c9448 /src/script/cpp_api | |
parent | fcb3ed840a5e66e6d37b27effe30d8d723a7da59 (diff) | |
download | minetest-08ee9794fbc0960a8aab1af21d34f40685809e75.tar.gz minetest-08ee9794fbc0960a8aab1af21d34f40685809e75.tar.bz2 minetest-08ee9794fbc0960a8aab1af21d34f40685809e75.zip |
Implement on_rightclickplayer callback (#10775)
Co-authored-by: rubenwardy <rw@rubenwardy.com>
Diffstat (limited to 'src/script/cpp_api')
-rw-r--r-- | src/script/cpp_api/s_player.cpp | 13 | ||||
-rw-r--r-- | src/script/cpp_api/s_player.h | 1 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/script/cpp_api/s_player.cpp b/src/script/cpp_api/s_player.cpp index 712120c61..d3e6138dc 100644 --- a/src/script/cpp_api/s_player.cpp +++ b/src/script/cpp_api/s_player.cpp @@ -77,6 +77,19 @@ bool ScriptApiPlayer::on_punchplayer(ServerActiveObject *player, return readParam<bool>(L, -1); } +void ScriptApiPlayer::on_rightclickplayer(ServerActiveObject *player, + ServerActiveObject *clicker) +{ + SCRIPTAPI_PRECHECKHEADER + // Get core.registered_on_rightclickplayers + lua_getglobal(L, "core"); + lua_getfield(L, -1, "registered_on_rightclickplayers"); + // Call callbacks + objectrefGetOrCreate(L, player); + objectrefGetOrCreate(L, clicker); + runCallbacks(2, RUN_CALLBACKS_MODE_FIRST); +} + s32 ScriptApiPlayer::on_player_hpchange(ServerActiveObject *player, s32 hp_change, const PlayerHPChangeReason &reason) { diff --git a/src/script/cpp_api/s_player.h b/src/script/cpp_api/s_player.h index a337f975b..c0f141862 100644 --- a/src/script/cpp_api/s_player.h +++ b/src/script/cpp_api/s_player.h @@ -47,6 +47,7 @@ public: bool on_punchplayer(ServerActiveObject *player, ServerActiveObject *hitter, float time_from_last_punch, const ToolCapabilities *toolcap, v3f dir, s16 damage); + void on_rightclickplayer(ServerActiveObject *player, ServerActiveObject *clicker); s32 on_player_hpchange(ServerActiveObject *player, s32 hp_change, const PlayerHPChangeReason &reason); void on_playerReceiveFields(ServerActiveObject *player, |