diff --git a/src/logic/scripting/api_lua.cpp b/src/logic/scripting/api_lua.cpp index 7799055a..d39796ac 100644 --- a/src/logic/scripting/api_lua.cpp +++ b/src/logic/scripting/api_lua.cpp @@ -1,6 +1,10 @@ #include "api_lua.h" #include "scripting.h" +#include + +#include "../../physics/Hitbox.h" +#include "../../objects/Player.h" #include "../../world/Level.h" #include "../../content/Content.h" #include "../../voxels/Block.h" @@ -54,6 +58,23 @@ int l_get_block(lua_State* L) { return 1; } +int l_get_player_pos(lua_State* L) { + glm::vec3 pos = scripting::level->player->hitbox->position; + lua_pushnumber(L, pos.x); + lua_pushnumber(L, pos.y); + lua_pushnumber(L, pos.z); + return 3; +} + +int l_set_player_pos(lua_State* L) { + double x = lua_tonumber(L, 1); + double y = lua_tonumber(L, 2); + double z = lua_tonumber(L, 3); + scripting::level->player->hitbox->position = glm::vec3(x, y, z); + return 0; +} + + #define lua_addfunc(L, FUNC, NAME) (lua_pushcfunction(L, FUNC),\ lua_setglobal(L, NAME)) @@ -64,4 +85,6 @@ void apilua::create_funcs(lua_State* L) { lua_addfunc(L, l_is_solid_at, "is_solid_at"); lua_addfunc(L, l_set_block, "set_block"); lua_addfunc(L, l_get_block, "get_block"); + lua_addfunc(L, l_get_player_pos, "get_player_pos"); + lua_addfunc(L, l_set_player_pos, "set_player_pos"); }