add console.get(...) & add 'player' console variable

This commit is contained in:
MihailRis 2025-01-22 10:15:31 +03:00
parent 2e89cc14ee
commit 9c630645b4
4 changed files with 9 additions and 2 deletions

View File

@ -4,7 +4,7 @@ To work with the command interpreter, use the **console** library.
When sending a command via the standard console (core:console layout): When sending a command via the standard console (core:console layout):
1. the `allow-cheats` rule is checked 1. the `allow-cheats` rule is checked
2. the `pos.x|y|z`, `entity.id`, `entity.selected` variables are automatically set. 2. the `player`, `pos.x|y|z`, `entity.id`, `entity.selected` variables are automatically set.
3. the command handler is called - console.submit or the default one. 3. the command handler is called - console.submit or the default one.
The default handler calls console.execute, passing the result to the console.log call. The default handler calls console.execute, passing the result to the console.log call.

View File

@ -4,7 +4,7 @@
При отправке команды через стандартную консоль (макет core:console): При отправке команды через стандартную консоль (макет core:console):
1. проверяется правило `allow-cheats` 1. проверяется правило `allow-cheats`
2. автоматически устанавливаются переменные `pos.x|y|z`, `entity.id`, `entity.selected`. 2. автоматически устанавливаются переменные `player`, `pos.x|y|z`, `entity.id`, `entity.selected`.
3. вызывается обработчик команд - console.submit или по-умолчанию. 3. вызывается обработчик команд - console.submit или по-умолчанию.
Обработчик по-умолчанию вызывает console.execute, передавая результат в вызов console.log. Обработчик по-умолчанию вызывает console.execute, передавая результат в вызов console.log.

View File

@ -97,6 +97,7 @@ end)
function setup_variables() function setup_variables()
local pid = hud.get_player() local pid = hud.get_player()
local x,y,z = player.get_pos(pid) local x,y,z = player.get_pos(pid)
console.set("player", pid)
console.set('pos.x', x) console.set('pos.x', x)
console.set('pos.y', y) console.set('pos.y', y)
console.set('pos.z', z) console.set('pos.z', z)

View File

@ -43,6 +43,11 @@ static int l_execute(lua::State* L) {
} }
} }
static int l_get(lua::State* L) {
auto name = lua::require_string(L, 1);
return lua::pushvalue(L, (*engine->getCommandsInterpreter())[name]);
}
static int l_set(lua::State* L) { static int l_set(lua::State* L) {
auto name = lua::require_string(L, 1); auto name = lua::require_string(L, 1);
auto value = lua::tovalue(L, 2); auto value = lua::tovalue(L, 2);
@ -119,6 +124,7 @@ static int l_get_command_info(lua::State* L) {
const luaL_Reg consolelib[] = { const luaL_Reg consolelib[] = {
{"add_command", lua::wrap<l_add_command>}, {"add_command", lua::wrap<l_add_command>},
{"execute", lua::wrap<l_execute>}, {"execute", lua::wrap<l_execute>},
{"get", lua::wrap<l_get>},
{"set", lua::wrap<l_set>}, {"set", lua::wrap<l_set>},
{"get_commands_list", lua::wrap<l_get_commands_list>}, {"get_commands_list", lua::wrap<l_get_commands_list>},
{"get_command_info", lua::wrap<l_get_command_info>}, {"get_command_info", lua::wrap<l_get_command_info>},