aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_client.cpp
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2020-10-04 10:50:07 +0200
committerElias Fleckenstein <eliasfleckenstein@web.de>2020-10-04 10:50:07 +0200
commitb9f8f0a232d9d00a323084e0e4807b3e3469720d (patch)
tree564679fd09da5cb4ef7da82dde5b7d8d5c2d7aee /src/script/lua_api/l_client.cpp
parentaf085acbd32707576ff9e67c3b267ad6cf267288 (diff)
downloaddragonfireclient-b9f8f0a232d9d00a323084e0e4807b3e3469720d.tar.xz
The Robot Update
Diffstat (limited to 'src/script/lua_api/l_client.cpp')
-rw-r--r--src/script/lua_api/l_client.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp
index 5d0ccf2e0..b9a8f77a8 100644
--- a/src/script/lua_api/l_client.cpp
+++ b/src/script/lua_api/l_client.cpp
@@ -35,6 +35,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "map.h"
#include "util/string.h"
#include "nodedef.h"
+#include "client/keycode.h"
#define checkCSMRestrictionFlag(flag) \
( getClient(L)->checkCSMRestrictionFlag(CSMRestrictionFlags::flag) )
@@ -470,13 +471,31 @@ int ModApiClient::l_get_inventory(lua_State *L)
inventory_location.deSerialize(location);
inventory = client->getInventory(inventory_location);
push_inventory(L, inventory);
- } catch (SerializationError) {
+ } catch (SerializationError &) {
lua_pushnil(L);
}
return 1;
}
+// set_keypress(key_setting, pressed) -> returns true on success
+int ModApiClient::l_set_keypress(lua_State *L)
+{
+ std::string setting_name = "keymap_" + readParam<std::string>(L, 1);
+ bool pressed = lua_isboolean(L, 2) && readParam<bool>(L, 2);
+ try {
+ KeyPress keyCode = getKeySetting(setting_name.c_str());
+ if (pressed)
+ g_game->input->setKeypress(keyCode);
+ else
+ g_game->input->unsetKeypress(keyCode);
+ lua_pushboolean(L, true);
+ } catch (SettingNotFoundException &) {
+ lua_pushboolean(L, false);
+ }
+ return 1;
+}
+
void ModApiClient::Initialize(lua_State *L, int top)
{
API_FCT(get_current_modname);
@@ -508,4 +527,5 @@ void ModApiClient::Initialize(lua_State *L, int top)
API_FCT(place_node);
API_FCT(dig_node);
API_FCT(get_inventory);
+ API_FCT(set_keypress);
}