add /eval_reset to clear your personal environment

This commit is contained in:
whosit 2025-04-05 11:35:09 +03:00
parent 15ef934e3c
commit b91dc915fd
2 changed files with 25 additions and 2 deletions

View File

@ -1,7 +1,11 @@
## Adds `/eval` command
`/eval` takes lua code as argument and executes it. It will echo your command and show it's output and returned value.
Each player gets their own "global" environment so they can't interfere with other user's envs by accident (exposed as `cmd_eval.e[player_name]`).
`/eval` takes lua code as argument and executes it. It will echo your
command and show it's output and returned value. Each player gets
their own "global" environment so they can't interfere with other
user's envs by accident (exposed as `cmd_eval.e[player_name]`).
Type `/eval help` to see the built-in help.
## Some nice features:
### Expression/statement agnostic
@ -230,3 +234,9 @@ You can still resume it by typing `/eval_resume <text>` - the argument
text will be passed instead of the context of text area of the formspec.
### Resetting your personal environment
If your environment gets messed up, or you just want to get rid of the
variables you've stored, you can type:
`/eval_reset`

View File

@ -425,6 +425,19 @@ core.register_chatcommand("eval_resume",
)
core.register_chatcommand("eval_reset",
{
description = "Restore your environment by clearing all variables you assigned",
privs = { server = true },
func = function(player_name, param)
core.log("action", string.format("[cmd_eval] %s reset their environmet", player_name, dump(param)))
api.e[player_name] = nil
return true, orange_fmt("* Your environment has been reset to default.")
end
}
)
core.register_on_player_receive_fields(
function(player, formname, fields)
if formname == "cmd_eval:dump" or formname == "cmd_eval:input" then