From 93c087997fe4140aee12c4c42232669008bce45f Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Thu, 21 Feb 2019 03:36:02 +0100 Subject: [PATCH] Add /lightning command --- mods/ENVIRONMENT/lightning/init.lua | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/mods/ENVIRONMENT/lightning/init.lua b/mods/ENVIRONMENT/lightning/init.lua index 207c4d1ae2..e3792f7e20 100644 --- a/mods/ENVIRONMENT/lightning/init.lua +++ b/mods/ENVIRONMENT/lightning/init.lua @@ -230,3 +230,33 @@ minetest.after(5, function(dtime) lightning.interval_high), lightning.strike) end end) + +minetest.register_chatcommand("lightning", { + params = "[ ]", + description = "Let lightning strike at the specified position or yourself", + privs = { maphack = true }, + func = function(name, param) + local pos = {} + pos.x, pos.y, pos.z = string.match(param, "^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$") + pos.x = tonumber(pos.x) + pos.y = tonumber(pos.y) + pos.z = tonumber(pos.z) + if not (pos.x and pos.y and pos.z) then + pos = nil + end + if name == "" and pos == nil then + return false, "No position specified and unknown player" + end + if pos then + lightning.strike(pos) + else + local player = minetest.get_player_by_name(name) + if player then + lightning.strike(player:get_pos()) + else + return false, "No position specified and unknown player" + end + end + return true + end, +})