libentities: add get_hitbox that returns a hitbox from entity definition
This commit is contained in:
parent
803981e2a8
commit
7f5bc41835
@ -50,6 +50,11 @@ entities.get_all_in_box(pos: vec3, size: vec3) -> array<int>
|
|||||||
-- center - center of the area
|
-- center - center of the area
|
||||||
-- radius - radius of the area
|
-- radius - radius of the area
|
||||||
entities.get_all_in_radius(center: vec3, radius: number) -> array<int>
|
entities.get_all_in_radius(center: vec3, radius: number) -> array<int>
|
||||||
|
|
||||||
|
|
||||||
|
-- Returns a float array representing hitbox size from entity definition
|
||||||
|
entities.get_hitbox(uid: int)->array<int>
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
|
|||||||
@ -50,6 +50,9 @@ entities.get_all_in_box(pos: vec3, size: vec3) -> array<int>
|
|||||||
-- center - центр области
|
-- center - центр области
|
||||||
-- radius - радиус области
|
-- radius - радиус области
|
||||||
entities.get_all_in_radius(center: vec3, radius: number) -> array<int>
|
entities.get_all_in_radius(center: vec3, radius: number) -> array<int>
|
||||||
|
|
||||||
|
-- Возвращает массив флотов хитбокса из определения сущности
|
||||||
|
entities.get_hitbox(uid: int)->array<int>
|
||||||
```
|
```
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
|
|||||||
@ -53,6 +53,20 @@ static int l_get_def(lua::State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_get_hitbox(lua::State* L){
|
||||||
|
if (auto def = require_entity_def(L)) {
|
||||||
|
lua::createtable(L, 3, 0);
|
||||||
|
lua::pushnumber(L, def->hitbox.x);
|
||||||
|
lua::rawseti(L, 1);
|
||||||
|
lua::pushnumber(L, def->hitbox.y);
|
||||||
|
lua::rawseti(L, 2);
|
||||||
|
lua::pushnumber(L, def->hitbox.z);
|
||||||
|
lua::rawseti(L, 3);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int l_spawn(lua::State* L) {
|
static int l_spawn(lua::State* L) {
|
||||||
auto level = controller->getLevel();
|
auto level = controller->getLevel();
|
||||||
auto defname = lua::tostring(L, 1);
|
auto defname = lua::tostring(L, 1);
|
||||||
@ -214,6 +228,7 @@ const luaL_Reg entitylib[] = {
|
|||||||
{"get_def", lua::wrap<l_get_def>},
|
{"get_def", lua::wrap<l_get_def>},
|
||||||
{"defs_count", lua::wrap<l_defs_count>},
|
{"defs_count", lua::wrap<l_defs_count>},
|
||||||
{"spawn", lua::wrap<l_spawn>},
|
{"spawn", lua::wrap<l_spawn>},
|
||||||
|
{"get_hitbox", lua::wrap<l_get_hitbox>},
|
||||||
{"despawn", lua::wrap<l_despawn>},
|
{"despawn", lua::wrap<l_despawn>},
|
||||||
{"get_skeleton", lua::wrap<l_get_skeleton>},
|
{"get_skeleton", lua::wrap<l_get_skeleton>},
|
||||||
{"set_skeleton", lua::wrap<l_set_skeleton>},
|
{"set_skeleton", lua::wrap<l_set_skeleton>},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user