scripting: get_player_pos, set_player_pos

This commit is contained in:
MihailRis 2023-12-29 00:46:26 +03:00
parent 2c75a0bee4
commit d2a40d31a4

View File

@ -1,6 +1,10 @@
#include "api_lua.h"
#include "scripting.h"
#include <glm/glm.hpp>
#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");
}