aboutsummaryrefslogtreecommitdiff
path: root/src/script/cpp_api/s_player.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/cpp_api/s_player.cpp')
-rw-r--r--src/script/cpp_api/s_player.cpp58
1 files changed, 56 insertions, 2 deletions
diff --git a/src/script/cpp_api/s_player.cpp b/src/script/cpp_api/s_player.cpp
index 22b24f363..2f366605b 100644
--- a/src/script/cpp_api/s_player.cpp
+++ b/src/script/cpp_api/s_player.cpp
@@ -27,6 +27,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "lua_api/l_item.h"
#include "util/string.h"
+#include "remoteplayer.h"
+
void ScriptApiPlayer::on_newplayer(ServerActiveObject *player)
{
SCRIPTAPI_PRECHECKHEADER
@@ -78,7 +80,7 @@ bool ScriptApiPlayer::on_punchplayer(ServerActiveObject *player,
}
void ScriptApiPlayer::on_rightclickplayer(ServerActiveObject *player,
- ServerActiveObject *clicker)
+ ServerActiveObject *clicker)
{
SCRIPTAPI_PRECHECKHEADER
// Get core.registered_on_rightclickplayers
@@ -91,7 +93,7 @@ void ScriptApiPlayer::on_rightclickplayer(ServerActiveObject *player,
}
s32 ScriptApiPlayer::on_player_hpchange(ServerActiveObject *player,
- s32 hp_change, const PlayerHPChangeReason &reason)
+ s32 hp_change, const PlayerHPChangeReason &reason)
{
SCRIPTAPI_PRECHECKHEADER
@@ -380,3 +382,55 @@ void ScriptApiPlayer::player_inventory_OnTake(
pushPutTakeArguments("take", ma.from_inv, ma.from_list, ma.from_i, stack, player);
runCallbacks(4, RUN_CALLBACKS_MODE_FIRST);
}
+
+void ScriptApiPlayer::on_player_change_wield(ServerActiveObject *player, u16 item)
+{
+ SCRIPTAPI_PRECHECKHEADER
+
+ // Get core.registered_on_leaveplayers
+ lua_getglobal(L, "core");
+ lua_getfield(L, -1, "registered_on_player_change_wield");
+ // Call callbacks
+ objectrefGetOrCreate(L, player);
+ lua_pushnumber(L, item);
+ runCallbacks(2, RUN_CALLBACKS_MODE_FIRST);
+}
+
+void ScriptApiPlayer::on_player_change_keys(ServerActiveObject *player, PlayerControl &control)
+{
+ SCRIPTAPI_PRECHECKHEADER
+
+ lua_getglobal(L, "core");
+ lua_getfield(L, -1, "registered_on_player_change_keys");
+ objectrefGetOrCreate(L, player);
+
+ lua_newtable(L);
+
+ lua_pushboolean(L, control.direction_keys & (1 << 0));
+ lua_setfield(L, -2, "up");
+ lua_pushboolean(L, control.direction_keys & (1 << 1));
+ lua_setfield(L, -2, "down");
+ lua_pushboolean(L, control.direction_keys & (1 << 2));
+ lua_setfield(L, -2, "left");
+ lua_pushboolean(L, control.direction_keys & (1 << 3));
+ lua_setfield(L, -2, "right");
+ lua_pushboolean(L, control.jump);
+ lua_setfield(L, -2, "jump");
+ lua_pushboolean(L, control.aux1);
+ lua_setfield(L, -2, "aux1");
+ lua_pushboolean(L, control.sneak);
+ lua_setfield(L, -2, "sneak");
+ lua_pushboolean(L, control.dig);
+ lua_setfield(L, -2, "dig");
+ lua_pushboolean(L, control.place);
+ lua_setfield(L, -2, "place");
+ // Legacy fields to ensure mod compatibility
+ lua_pushboolean(L, control.dig);
+ lua_setfield(L, -2, "LMB");
+ lua_pushboolean(L, control.place);
+ lua_setfield(L, -2, "RMB");
+ lua_pushboolean(L, control.zoom);
+ lua_setfield(L, -2, "zoom");
+
+ runCallbacks(2, RUN_CALLBACKS_MODE_FIRST);
+}