From db64f3f1df880f6d78761a43cf77305efc8fb399 Mon Sep 17 00:00:00 2001 From: WilLiam12 <65061739+WilLiam12-teddy@users.noreply.github.com> Date: Sat, 18 Jul 2020 18:38:50 -0300 Subject: [PATCH] new change. --- init.lua | 91 ++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 25 deletions(-) diff --git a/init.lua b/init.lua index 89793f4..7bea660 100644 --- a/init.lua +++ b/init.lua @@ -1,37 +1,78 @@ +local have_banmod = minetest.get_modpath("xban2") +--local have_jailmod = minetest.get_modpath("jail") + + minetest.register_privilege("willadmin", { description = "Privilege required to use admin tools.", give_to_singleplayer = false }) +local function handle_tool(itemstack, player, pointed_thing, hitter_item) + if pointed_thing.type ~= "object" then + return + end + if not pointed_thing.ref:is_player() then + return + end + local hitter_name = player:get_player_name() + local punched_name = pointed_thing.ref:get_player_name() + local hitter_privs = minetest.get_player_privs(hitter_name) + print(hitter_item) + + if hitter_privs.willadmin then + if hitter_privs.kick == true and hitter_item == "kickstick" then + minetest.kick_player(punched_name) + return + elseif hitter_privs.ban == true and hitter_item == "banhammer" then + if have_banmod then + xban.ban_player(punched_name,hitter_name,nil,"You Were hit with the Banhammer." ) + else + minetest.ban_player(punched_name) + end + return +-- elseif hitter_privs.jail == true and hitter_item == "jailtool" then +-- --jail.jail(punched_name) +-- return + end + else + minetest.chat_send_player(hitter_name, "You need willadmin priv to use this tool.") + end +end + + +print("[willadmin] adding kickstick") minetest.register_craftitem("willadmin:kickstick", { description = "Kick Stick - click on the bad player.", - inventory_image = "kickstick.png" + inventory_image = "kickstick.png", + wield_image = "kickstick.png", + on_use = function(itemstack, player, pointed_thing) + handle_tool(itemstack, player, pointed_thing, "kickstick") + return itemstack + end, }) +print("[willadmin] adding banhammer") minetest.register_craftitem("willadmin:banhammer", { - description = "Ban Hammer - click on the bad player. (take care!)", - inventory_image = "banhammer.png" + description = "Ban Hammer - click on the bad player. (take care!)", + inventory_image = "banhammer.png", + wield_image = "banhammer.png", + on_use = function(itemstack, player, pointed_thing) + handle_tool(itemstack, player, pointed_thing, "banhammer") + return itemstack + end, }) -minetest.register_craftitem("willadmin:jailtool", { - description = "Jail Tool - click on the bad player.", - inventory_image = "jailtool.png" -}) - -minetest.register_on_punchplayer(function(player, hitter) - local hitter_name = hitter:get_player_name() - local punched_name = player:get_player_name() - local hitter_privs = minetest.get_player_privs(hitter_name) - local hitter_item = hitter:get_wielded_item():get_name() - print(hitter_item) - if hitter_privs.kick == true and hitter_item == "willadmin:kickstick" then - minetest.kick_player(punched_name) - return true - elseif hitter_privs.ban == true and hitter_item == "willadmin:banhammer" then - xban.ban_player(punched_name) - return true - elseif hitter_privs.jail == true and hitter_item == "willadmin:jailtool" then - jail.jail(punched_name) - return true - end -end) \ No newline at end of file +--if have_jailmod then +-- print("[willadmin] adding jailtool") +-- minetest.register_craftitem("willadmin:jailtool", { +-- description = "Jail Tool - click on the bad player.", +-- inventory_image = "jailtool.png", +-- wield_image = "jailtool.png", +-- on_use = function(itemstack, player, pointed_thing) +-- handle_tool(itemstack, player, pointed_thing, "jailtool") +-- return itemstack +-- end, +-- }) +--else +-- print("[willadmin] NOT adding jailtool - mod jail not found") +--end