diff options
author | Andrew Ward <rw@rubenwardy.com> | 2018-03-28 16:05:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-28 16:05:18 +0100 |
commit | dfc81983491417c5cd1c99d7db05e421c409379d (patch) | |
tree | 7b0457f0ff86f038cfad1a095d3ab0b6c44f2def /src/script/cpp_api/s_player.cpp | |
parent | 2323842dd3dd336b087ca3cf9756e0680b3a1244 (diff) | |
download | minetest-dfc81983491417c5cd1c99d7db05e421c409379d.tar.xz |
Add reasons to on_dieplayer and on_hpchange
Diffstat (limited to 'src/script/cpp_api/s_player.cpp')
-rw-r--r-- | src/script/cpp_api/s_player.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/script/cpp_api/s_player.cpp b/src/script/cpp_api/s_player.cpp index 578298e24..cc2b96d5e 100644 --- a/src/script/cpp_api/s_player.cpp +++ b/src/script/cpp_api/s_player.cpp @@ -36,16 +36,20 @@ void ScriptApiPlayer::on_newplayer(ServerActiveObject *player) runCallbacks(1, RUN_CALLBACKS_MODE_FIRST); } -void ScriptApiPlayer::on_dieplayer(ServerActiveObject *player) +void ScriptApiPlayer::on_dieplayer(ServerActiveObject *player, const PlayerHPChangeReason &reason) { SCRIPTAPI_PRECHECKHEADER - // Get core.registered_on_dieplayers + // Get callback table lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_dieplayers"); - // Call callbacks + + // Push arguments objectrefGetOrCreate(L, player); - runCallbacks(1, RUN_CALLBACKS_MODE_FIRST); + pushPlayerHPChangeReason(L, reason); + + // Run callbacks + runCallbacks(2, RUN_CALLBACKS_MODE_FIRST); } bool ScriptApiPlayer::on_punchplayer(ServerActiveObject *player, @@ -71,7 +75,7 @@ bool ScriptApiPlayer::on_punchplayer(ServerActiveObject *player, } s16 ScriptApiPlayer::on_player_hpchange(ServerActiveObject *player, - s16 hp_change) + s16 hp_change, const PlayerHPChangeReason &reason) { SCRIPTAPI_PRECHECKHEADER @@ -82,9 +86,13 @@ s16 ScriptApiPlayer::on_player_hpchange(ServerActiveObject *player, lua_getfield(L, -1, "registered_on_player_hpchange"); lua_remove(L, -2); + // Push arguments objectrefGetOrCreate(L, player); lua_pushnumber(L, hp_change); - PCALL_RES(lua_pcall(L, 2, 1, error_handler)); + pushPlayerHPChangeReason(L, reason); + + // Call callbacks + PCALL_RES(lua_pcall(L, 3, 1, error_handler)); hp_change = lua_tointeger(L, -1); lua_pop(L, 2); // Pop result and error handler return hp_change; |