diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/script/cpp_api/s_player.cpp | 13 | ||||
-rw-r--r-- | src/script/cpp_api/s_player.h | 1 | ||||
-rw-r--r-- | src/server/player_sao.cpp | 5 | ||||
-rw-r--r-- | src/server/player_sao.h | 2 |
4 files changed, 20 insertions, 1 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, diff --git a/src/server/player_sao.cpp b/src/server/player_sao.cpp index 232c6a01d..c1b1401e6 100644 --- a/src/server/player_sao.cpp +++ b/src/server/player_sao.cpp @@ -456,6 +456,11 @@ u16 PlayerSAO::punch(v3f dir, return hitparams.wear; } +void PlayerSAO::rightClick(ServerActiveObject *clicker) +{ + m_env->getScriptIface()->on_rightclickplayer(this, clicker); +} + void PlayerSAO::setHP(s32 hp, const PlayerHPChangeReason &reason) { if (hp == (s32)m_hp) diff --git a/src/server/player_sao.h b/src/server/player_sao.h index 3e178d4fc..6aee8d5aa 100644 --- a/src/server/player_sao.h +++ b/src/server/player_sao.h @@ -111,7 +111,7 @@ public: u16 punch(v3f dir, const ToolCapabilities *toolcap, ServerActiveObject *puncher, float time_from_last_punch); - void rightClick(ServerActiveObject *clicker) {} + void rightClick(ServerActiveObject *clicker); void setHP(s32 hp, const PlayerHPChangeReason &reason); void setHPRaw(u16 hp) { m_hp = hp; } s16 readDamage(); |