From b91dc915fd7837c08a3190636493df7fdef710cd Mon Sep 17 00:00:00 2001 From: whosit Date: Sat, 5 Apr 2025 11:35:09 +0300 Subject: [PATCH] add /eval_reset to clear your personal environment --- README.md | 14 ++++++++++++-- init.lua | 13 +++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 042335a..ebcc77b 100644 --- a/README.md +++ b/README.md @@ -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 ` - 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` diff --git a/init.lua b/init.lua index f030ab4..324beec 100644 --- a/init.lua +++ b/init.lua @@ -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