From 61c3ab64c4b0be41febdb6d1eaa6e92382005eda Mon Sep 17 00:00:00 2001 From: zmv7 <72821250+zmv7@users.noreply.github.com> Date: Thu, 3 Feb 2022 15:43:20 +0500 Subject: [PATCH] Add files via upload --- README.md | 57 ++++++++++++ description.txt | 1 + init.lua | 243 ++++++++++++++++++++++++++++++++++++++++++++++++ mod.conf | 1 + 4 files changed, 302 insertions(+) create mode 100644 README.md create mode 100644 description.txt create mode 100644 init.lua create mode 100644 mod.conf diff --git a/README.md b/README.md new file mode 100644 index 0000000..f6ef175 --- /dev/null +++ b/README.md @@ -0,0 +1,57 @@ +# Player tools 1.4 [playertools] +This mod adds some player-related server commands and privileges to Minetest. +Most commands are little helper tools, useful for modders and for messing +around, but they aren’t really suitable for serious gameplay. Some commands +are informational. The commands allow players to change their health, clear +their inventory, set their player physics, and other stuff. +The privileges are created for the health, physics and hotbar-related commands +and are named “`heal`”, “`physics`” and “`hotbar`”, respectively. + +## List of commands +### No privileges required + +* `/whoami`: Shows your name in a chat message. +* `/ip`: Shows your IP address in a chat message. +* `/pulverizeall`: Destroys all items in your player inventory and crafting grid. +* `/killme`: Kills yourself. + +### “`hotbar`” privilege required + +* `/hotbar <1...32>`: Sets the number of slots in your hotbar. + +### “`heal`” privilege and damage required + +* `/sethp ` Sets your health to specified number. +* `/setbreath `: Sets your breath to specified breath points. + + +### “`physics`” privilege required + +* `/setspeed []`: Sets your movement speed to `` (default: 1). +* `/setgravity []`: Sets your gravity to `` (default: 1). +* `/setjump []`: Sets your jump height to `` (default: 1). + +These commands directly edit the player’s physics parameters. + + +## Installation +You can either install the player tools as an ordinary mod or as a builtin, +but please don’t do both. Installing it as a mod is very easy, but you have +to activate the mod explicitly for each map. Installing it as builtin is easy +and the player tools are automatically available for every server you start. + +To install it as a mod, just drop this folder into the `mods/` directory of your +Minetest data folder. + +To install it as builtin do this: +(For version 0.4.9) +Rename the file “`init.lua`” to “`mod_playertools.lua`” and move it to `/builtin/`. +Then edit the file `/builtin/builtin.lua`. Add the following line of text at the +end of the file: + + dofile(modpath.."/mod_playertools.lua") + +Save the file; you’re finished! The next time you start a server the player tools are available. + +## License +This mod is free software, licensed under the MIT License. diff --git a/description.txt b/description.txt new file mode 100644 index 0000000..646768a --- /dev/null +++ b/description.txt @@ -0,0 +1 @@ +Some useful server commands for players. diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..e38ccaf --- /dev/null +++ b/init.lua @@ -0,0 +1,243 @@ +--[[ privileges ]] +if(minetest.setting_getbool("enable_damage") == true) then + minetest.register_privilege("heal", { + description = "Allows player to set own health and breath with /sethp, and /setbreath", + give_to_singleplayer = false + }) +end +minetest.register_privilege("physics", { + description = "Allows player to set own gravity, jump height and movement speed with /setgravity, /setjump and /setspeed, respectively", + give_to_singleplayer = false +}) +minetest.register_privilege("hotbar", { + description = "Allows player to set the number of slots of the hotbar with /hotbar", + give_to_singleplayer = false +}) + +--[[ informational commands ]] +minetest.register_chatcommand("whoami", { + params = "", + description = "Shows your player name", + privs = {}, + func = function(name) + minetest.chat_send_player(name, "Your player name is "..name) + end, +}) + +minetest.register_chatcommand("ip", { + params = "[]", + description = "Shows your or another player's IP address", + privs = {}, + func = function(name, param) + if param == "" then + minetest.chat_send_player(name, "Your IP address is "..minetest.get_player_ip(name)) + else + if not minetest.check_player_privs(name, "server") then + return minetest.chat_send_player(name,"You are not have server priv") + end + local pname = minetest.get_player_by_name(param) + if pname then + minetest.chat_send_player(name, "IP address of "..param.." is "..minetest.get_player_ip(param)) + else return false, "Invalid player" + end + end +end +}) + +--[[ HUD commands ]] +minetest.register_chatcommand("hotbar", { + params = "", + privs = {hotbar=true}, + description = "Set hotbar size", + func = function(name, param) + local player = minetest.get_player_by_name(name) + if not player then + return false, "No player." + end + local size = tonumber(param) + if not size then + return false, "Missing or incorrect size parameter!" + end + local ok = player:hud_set_hotbar_itemcount(size) player:hud_set_hotbar_image("") + if ok then + return true + else + return false, "Invalid item count!" + end + end, +}) + + +minetest.register_chatcommand("zoomfov", { + params = "[]", + privs = {physics=true}, + description = "Set or display your zoom_fov", + func = function(name, param) + local player = minetest.get_player_by_name(name) + if not player then + return false, "No player." + end + if param == "" then + local fov = player:get_properties().zoom_fov + return true, "zoom_fov = "..tostring(fov) + end + local fov = tonumber(param) + if not fov then + return false, "Missing or incorrect zoom_fov parameter!" + end + player:set_properties({zoom_fov = fov}) + fov = player:get_properties().zoom_fov + return true, "zoom_fov = "..tostring(fov) + end, +}) + +--[[ health and breath commands ]] + +if(minetest.setting_getbool("enable_damage") == true) then + minetest.register_chatcommand("sethp", { + params = "", + privs = {heal=true}, + description = "Set your health", + func = function(name, param) + local player = minetest.get_player_by_name(name) + if not player then + return false, "No player." + end + local hp = tonumber(param) + if not hp then + return false, "Missing or incorrect hp parameter!" + end + player:set_hp(hp) + return true + end, +}) + minetest.register_chatcommand("setbreath", { + params = "", + description = "Sets your breath to specified breath points", + privs = {heal=true}, + func = function(name, breath) + local player = minetest.get_player_by_name(name) + if not player then + return + end + if breath == "" then + minetest.chat_send_player(name, "You did not specify the parameter.") + return + end + if type(tonumber(breath)) ~= "number" then + minetest.chat_send_player(name, "This is not a number.") + return + end + local bp = math.max(0, tonumber(breath)) -- ensure minimum value of 0 + player:set_breath(bp) + end, + }) + + minetest.register_chatcommand("killme", { + params = "", + description = "Kills yourself", + func = function(name, param) + local player = minetest.get_player_by_name(name) + if not player then + return + end + player:set_hp(0) + end, + }) +end + +--[[ Player physics commands ]] + +-- speed +minetest.register_chatcommand("setspeed", { + params = "[]", + description = "Sets your movement speed to (default: 1)", + privs={physics=true}, + func = function(name, speed) + local player = minetest.get_player_by_name(name) + if not player then + return + end + if speed == "" then + speed=1 + end + if type(tonumber(speed)) ~= "number" then + minetest.chat_send_player(name, "This is not a number.") + return + end + + player:set_physics_override(tonumber(speed), nil, nil) + end, +}) + +-- gravity +minetest.register_chatcommand("setgravity", { + params = "[]", + description = "Sets your gravity to (default: 1)", + privs={physics=true}, + func = function(name, gravity) + local player = minetest.get_player_by_name(name) + if not player then + return + end + if gravity == "" then + gravity=1 + end + if type(tonumber(gravity)) ~= "number" then + minetest.chat_send_player(name, "This is not a number.") + return + end + player:set_physics_override(nil, nil, tonumber(gravity)) + end, +}) + +-- jump height +minetest.register_chatcommand("setjump", { + params = "[]", + description = "Sets your jump height to (default: 1)", + privs = {physics=true}, + func = function(name, jump_height) + local player = minetest.get_player_by_name(name) + if not player then + return + end + if jump_height == "" then + jump_height=1 + end + if type(tonumber(jump_height)) ~= "number" then + minetest.chat_send_player(name, "This is not a number.") + return + end + player:set_physics_override(nil, jump_height, nil) + end, +}) + +minetest.register_chatcommand("pulverizeall", { + params = "[]", + description = "Remove all items in your or player's inventory and crafting grid", + func = function(name, param) + if param == "" then + local player = minetest.get_player_by_name(name) + if not player then + return + end + local inv = player:get_inventory() + inv:set_list("main", {}) + inv:set_list("craft", {}) + return true, "Your stuff pulverized" + else + if not minetest.check_player_privs(name, "server") then + return minetest.chat_send_player(name,"You are not have server priv") + end + local pname = minetest.get_player_by_name(param) + if pname then + local inv = pname:get_inventory() + inv:set_list("main", {}) + inv:set_list("craft", {}) + return true, "Pulverized "..param.."'s stuff" + else + return false, "Invalid player" + end + end + end, +}) \ No newline at end of file diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..5127061 --- /dev/null +++ b/mod.conf @@ -0,0 +1 @@ +name = playertools