From 26beddca610ce84c195a78d22af1fdd5a4ee27e1 Mon Sep 17 00:00:00 2001 From: HybridDog Date: Sat, 24 Jan 2015 14:27:23 +0100 Subject: [PATCH] Admin has super weapons --- shooter.conf.example | 4 ++++ shooter.lua | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/shooter.conf.example b/shooter.conf.example index 54c6282..89cc064 100644 --- a/shooter.conf.example +++ b/shooter.conf.example @@ -2,6 +2,10 @@ -- Global Constants (defaults) +-- Enable admin super weapons +-- This lets admins shoot guns automatically after 2 seconds without munition. +SHOOTER_ADMIN_WEAPONS = false + -- Enable node destruction with explosives SHOOTER_ENABLE_BLASTING = true diff --git a/shooter.lua b/shooter.lua index aefad27..d3c3c44 100644 --- a/shooter.lua +++ b/shooter.lua @@ -7,6 +7,7 @@ shooter = { reload_time = 0, } +SHOOTER_ADMIN_WEAPONS = false SHOOTER_ENABLE_BLASTING = false SHOOTER_ENABLE_CROSSBOW = true SHOOTER_ENABLE_GUNS = true @@ -38,7 +39,8 @@ SHOOTER_ENTITIES = { "mobs:dungeon_master", } -if minetest.is_singleplayer() == true then +local singleplayer = minetest.is_singleplayer() +if singleplayer then SHOOTER_ENABLE_BLASTING = true SHOOTER_ALLOW_ENTITIES = true SHOOTER_ALLOW_PLAYERS = false @@ -203,7 +205,9 @@ function shooter:process_round(round) end end +shooter.registered_weapons = shooter.registered_weapons or {} function shooter:register_weapon(name, def) + shooter.registered_weapons[name] = def local shots = def.shots or 1 local wear = math.ceil(65534 / def.rounds) local max_wear = (def.rounds - 1) * wear @@ -427,3 +431,32 @@ function shooter:blast(pos, radius, fleshy, distance, user) end end +if not singleplayer and SHOOTER_ADMIN_WEAPONS then + local timer = 0 + local shooting = false + minetest.register_globalstep(function(dtime) + if not shooting then + timer = timer+dtime + if timer < 2 then + return + end + timer = 0 + end + shooting = false + for _,player in pairs(minetest.get_connected_players()) do + if player:get_player_control().LMB then + local name = player:get_player_name() + if minetest.check_player_privs(name, {server=true}) then + local spec = shooter.registered_weapons[player:get_wielded_item():get_name()] + if spec then + spec = spec.spec + shooter.shots[name] = false + spec.name = name + shooter:fire_weapon(player, {}, spec) + shooting = true + end + end + end + end + end) +end