mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-11 05:51:51 +00:00
scripting: get_player_pos, set_player_pos
This commit is contained in:
parent
2c75a0bee4
commit
d2a40d31a4
1 changed files with 23 additions and 0 deletions
|
|
@ -1,6 +1,10 @@
|
||||||
#include "api_lua.h"
|
#include "api_lua.h"
|
||||||
#include "scripting.h"
|
#include "scripting.h"
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
#include "../../physics/Hitbox.h"
|
||||||
|
#include "../../objects/Player.h"
|
||||||
#include "../../world/Level.h"
|
#include "../../world/Level.h"
|
||||||
#include "../../content/Content.h"
|
#include "../../content/Content.h"
|
||||||
#include "../../voxels/Block.h"
|
#include "../../voxels/Block.h"
|
||||||
|
|
@ -54,6 +58,23 @@ int l_get_block(lua_State* L) {
|
||||||
return 1;
|
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),\
|
#define lua_addfunc(L, FUNC, NAME) (lua_pushcfunction(L, FUNC),\
|
||||||
lua_setglobal(L, NAME))
|
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_is_solid_at, "is_solid_at");
|
||||||
lua_addfunc(L, l_set_block, "set_block");
|
lua_addfunc(L, l_set_block, "set_block");
|
||||||
lua_addfunc(L, l_get_block, "get_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");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue