diff options
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/cpp_api/s_internal.h | 1 | ||||
-rw-r--r-- | src/script/cpp_api/s_player.cpp | 24 | ||||
-rw-r--r-- | src/script/cpp_api/s_player.h | 5 |
3 files changed, 30 insertions, 0 deletions
diff --git a/src/script/cpp_api/s_internal.h b/src/script/cpp_api/s_internal.h index 10ee1a7de..9999a584a 100644 --- a/src/script/cpp_api/s_internal.h +++ b/src/script/cpp_api/s_internal.h @@ -61,3 +61,4 @@ bool* m_variable; StackUnroller stack_unroller(L); #endif /* S_INTERNAL_H_ */ + diff --git a/src/script/cpp_api/s_player.cpp b/src/script/cpp_api/s_player.cpp index 81bfd4505..d56766824 100644 --- a/src/script/cpp_api/s_player.cpp +++ b/src/script/cpp_api/s_player.cpp @@ -19,6 +19,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "cpp_api/s_player.h" #include "cpp_api/s_internal.h" +#include "common/c_converter.h" +#include "common/c_content.h" #include "util/string.h" void ScriptApiPlayer::on_newplayer(ServerActiveObject *player) @@ -45,6 +47,28 @@ void ScriptApiPlayer::on_dieplayer(ServerActiveObject *player) script_run_callbacks(L, 1, RUN_CALLBACKS_MODE_FIRST); } +bool ScriptApiPlayer::on_punchplayer(ServerActiveObject *player, + ServerActiveObject *hitter, + float time_from_last_punch, + const ToolCapabilities *toolcap, + v3f dir, + s16 damage) +{ + SCRIPTAPI_PRECHECKHEADER + // Get core.registered_on_punchplayers + lua_getglobal(L, "core"); + lua_getfield(L, -1, "registered_on_punchplayers"); + // Call callbacks + objectrefGetOrCreate(L, player); + objectrefGetOrCreate(L, hitter); + lua_pushnumber(L, time_from_last_punch); + push_tool_capabilities(L, *toolcap); + push_v3f(L, dir); + lua_pushnumber(L, damage); + script_run_callbacks(L, 6, RUN_CALLBACKS_MODE_OR); + return lua_toboolean(L, -1); +} + bool ScriptApiPlayer::on_respawnplayer(ServerActiveObject *player) { SCRIPTAPI_PRECHECKHEADER diff --git a/src/script/cpp_api/s_player.h b/src/script/cpp_api/s_player.h index c77d397c4..a0f764cd5 100644 --- a/src/script/cpp_api/s_player.h +++ b/src/script/cpp_api/s_player.h @@ -23,7 +23,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #include <map> #include "cpp_api/s_base.h" +#include "irr_v3d.h" +struct ToolCapabilities; class ScriptApiPlayer : virtual public ScriptApiBase @@ -38,6 +40,9 @@ public: void on_joinplayer(ServerActiveObject *player); void on_leaveplayer(ServerActiveObject *player); void on_cheat(ServerActiveObject *player, const std::string &cheat_type); + bool on_punchplayer(ServerActiveObject *player, + ServerActiveObject *hitter, float time_from_last_punch, + const ToolCapabilities *toolcap, v3f dir, s16 damage); void on_playerReceiveFields(ServerActiveObject *player, const std::string &formname, |