2019-03-17 18:13:26 +00:00
|
|
|
--[[
|
|
|
|
Shooter Rocket Gun [shooter_rocket]
|
|
|
|
Copyright (C) 2013-2019 stujones11, Stuart Jones
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
]]--
|
|
|
|
|
2021-04-21 07:50:15 +00:00
|
|
|
local plcooldown = {}
|
|
|
|
local COOLDOWN = 5
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_on_leaveplayer(function(player)
|
|
|
|
plcooldown[player:get_player_name()] = nil
|
|
|
|
end)
|
|
|
|
|
2017-07-13 12:33:00 +00:00
|
|
|
minetest.register_craftitem("shooter_rocket:rocket", {
|
2014-07-26 20:18:10 +00:00
|
|
|
description = "Rocket",
|
|
|
|
stack_max = 1,
|
|
|
|
inventory_image = "shooter_rocket_inv.png",
|
|
|
|
})
|
|
|
|
|
2017-07-13 12:33:00 +00:00
|
|
|
minetest.register_entity("shooter_rocket:rocket_entity", {
|
2014-07-26 20:18:10 +00:00
|
|
|
physical = false,
|
|
|
|
timer = 0,
|
|
|
|
visual = "cube",
|
|
|
|
visual_size = {x=1/8, y=1/8},
|
|
|
|
textures = {
|
|
|
|
"shooter_bullet.png",
|
|
|
|
"shooter_bullet.png",
|
|
|
|
"shooter_bullet.png",
|
|
|
|
"shooter_bullet.png",
|
|
|
|
"shooter_bullet.png",
|
|
|
|
"shooter_bullet.png",
|
|
|
|
},
|
2019-03-15 17:55:37 +00:00
|
|
|
user = nil,
|
2014-07-26 20:18:10 +00:00
|
|
|
collisionbox = {0,0,0, 0,0,0},
|
|
|
|
on_activate = function(self, staticdata)
|
|
|
|
if staticdata == "expired" then
|
|
|
|
self.object:remove()
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
on_step = function(self, dtime)
|
|
|
|
self.timer = self.timer + dtime
|
|
|
|
if self.timer > 0.2 then
|
2019-03-15 17:55:37 +00:00
|
|
|
local pos = self.object:get_pos()
|
2015-12-16 18:18:23 +00:00
|
|
|
local above = {x=pos.x, y=pos.y + 1, z=pos.z}
|
2014-07-26 20:18:10 +00:00
|
|
|
if minetest.get_node(pos).name ~= "air" then
|
2019-03-15 17:55:37 +00:00
|
|
|
if self.user then
|
|
|
|
local player = minetest.get_player_by_name(self.user)
|
|
|
|
if player then
|
2019-03-16 19:33:08 +00:00
|
|
|
shooter.blast(above, 4, 50, 8, player)
|
2019-03-15 17:55:37 +00:00
|
|
|
end
|
|
|
|
end
|
2014-07-26 20:18:10 +00:00
|
|
|
self.object:remove()
|
|
|
|
end
|
|
|
|
self.timer = 0
|
|
|
|
end
|
|
|
|
end,
|
2019-03-19 19:23:23 +00:00
|
|
|
get_staticdata = function()
|
2014-07-26 20:18:10 +00:00
|
|
|
return "expired"
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2017-07-13 12:33:00 +00:00
|
|
|
minetest.register_tool("shooter_rocket:rocket_gun_loaded", {
|
2014-07-26 20:18:10 +00:00
|
|
|
description = "Rocket Gun",
|
|
|
|
inventory_image = "shooter_rocket_gun_loaded.png",
|
|
|
|
groups = {not_in_creative_inventory=1},
|
|
|
|
on_use = function(itemstack, user, pointed_thing)
|
2021-04-21 07:50:15 +00:00
|
|
|
if plcooldown[user:get_player_name()] ~= 0 then
|
2021-04-22 00:40:16 +00:00
|
|
|
hud_event.new(user:get_player_name(), {
|
|
|
|
name = "shooter_rocket:cooldown",
|
|
|
|
color = "0xC1FF44",
|
|
|
|
value = "Your rocket has a cooldown!"
|
|
|
|
})
|
2021-04-21 07:50:15 +00:00
|
|
|
else
|
2021-04-22 00:26:39 +00:00
|
|
|
if not minetest.settings:get_bool("creative_mode") then
|
2021-04-21 07:50:15 +00:00
|
|
|
itemstack:add_wear(65535 / 50)
|
2014-07-26 20:18:10 +00:00
|
|
|
end
|
2021-04-21 07:50:15 +00:00
|
|
|
itemstack = "shooter_rocket:rocket_gun 1 "..itemstack:get_wear()
|
|
|
|
if pointed_thing.type ~= "nothing" then
|
|
|
|
local pointed = minetest.get_pointed_thing_position(pointed_thing)
|
|
|
|
if vector.distance(user:get_pos(), pointed) < 8 then
|
|
|
|
shooter.blast(pointed, 2, 50, 7)
|
|
|
|
return itemstack
|
2014-07-26 20:18:10 +00:00
|
|
|
end
|
|
|
|
end
|
2021-04-21 07:50:15 +00:00
|
|
|
local pos = user:get_pos()
|
|
|
|
local dir = user:get_look_dir()
|
|
|
|
local yaw = user:get_look_horizontal()
|
|
|
|
if pos and dir and yaw then
|
|
|
|
pos.y = pos.y + user:get_properties().eye_height
|
|
|
|
local obj = minetest.add_entity(pos, "shooter_rocket:rocket_entity")
|
|
|
|
if obj then
|
|
|
|
minetest.sound_play("shooter_rocket_fire", {object=obj})
|
|
|
|
obj:set_velocity(vector.multiply(dir, 20))
|
|
|
|
obj:set_acceleration({x=dir.x * -3, y=-10, z=dir.z * -3})
|
|
|
|
obj:set_yaw(yaw + math.pi / 2)
|
|
|
|
local ent = obj:get_luaentity()
|
|
|
|
if ent then
|
|
|
|
ent.user = user:get_player_name()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
plcooldown[user:get_player_name()] = COOLDOWN
|
|
|
|
minetest.after(COOLDOWN, function(user)
|
|
|
|
if plcooldown[user:get_player_name()] then
|
2021-04-22 16:20:32 +00:00
|
|
|
plcooldown[user:get_player_name()] = nil
|
2021-04-21 07:50:15 +00:00
|
|
|
end
|
|
|
|
end, user)
|
2014-07-26 20:18:10 +00:00
|
|
|
end
|
|
|
|
return itemstack
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2017-07-13 12:33:00 +00:00
|
|
|
minetest.register_tool("shooter_rocket:rocket_gun", {
|
2014-07-26 20:18:10 +00:00
|
|
|
description = "Rocket Gun",
|
|
|
|
inventory_image = "shooter_rocket_gun.png",
|
2019-03-19 19:23:23 +00:00
|
|
|
on_use = function(itemstack, user)
|
2014-07-26 20:18:10 +00:00
|
|
|
local inv = user:get_inventory()
|
2017-07-13 12:33:00 +00:00
|
|
|
if inv:contains_item("main", "shooter_rocket:rocket") then
|
2014-07-26 20:18:10 +00:00
|
|
|
minetest.sound_play("shooter_reload", {object=user})
|
|
|
|
if not minetest.setting_getbool("creative_mode") then
|
2017-07-13 12:33:00 +00:00
|
|
|
inv:remove_item("main", "shooter_rocket:rocket 1")
|
2014-07-26 20:18:10 +00:00
|
|
|
end
|
2017-07-13 12:33:00 +00:00
|
|
|
itemstack = "shooter_rocket:rocket_gun_loaded 1 "..itemstack:get_wear()
|
2014-07-26 20:18:10 +00:00
|
|
|
else
|
|
|
|
minetest.sound_play("shooter_click", {object=user})
|
|
|
|
end
|
|
|
|
return itemstack
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2018-01-05 20:02:18 +00:00
|
|
|
if shooter.config.enable_crafting == true then
|
2014-07-26 20:18:10 +00:00
|
|
|
minetest.register_craft({
|
2017-07-13 12:33:00 +00:00
|
|
|
output = "shooter_rocket:rocket_gun",
|
2014-07-26 20:18:10 +00:00
|
|
|
recipe = {
|
|
|
|
{"default:bronze_ingot", "default:steel_ingot", "default:steel_ingot"},
|
|
|
|
{"", "", "default:diamond"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
minetest.register_craft({
|
2017-07-13 12:33:00 +00:00
|
|
|
output = "shooter_rocket:rocket",
|
2019-03-21 21:08:40 +00:00
|
|
|
type = "shapeless",
|
|
|
|
recipe = {"default:bronze_ingot", "shooter:gunpowder", "default:bronze_ingot"},
|
2014-07-26 20:18:10 +00:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2021-04-20 14:28:51 +00:00
|
|
|
local timer = 0
|
|
|
|
minetest.register_globalstep(function(dtime)
|
2021-04-20 15:34:11 +00:00
|
|
|
timer = timer + dtime
|
|
|
|
if timer >= 1 then
|
2021-04-20 15:32:25 +00:00
|
|
|
timer = 0
|
2021-04-20 15:34:11 +00:00
|
|
|
for _, player in ipairs(minetest.get_connected_players()) do
|
|
|
|
local name = player and player:get_player_name()
|
|
|
|
local wielditem = player:get_wielded_item()
|
|
|
|
if wielditem:get_name() == "shooter_rocket:rocket_gun_loaded" then
|
|
|
|
local wielditem = player:get_wielded_item()
|
2021-04-20 15:32:25 +00:00
|
|
|
physics.set(name, "shooter_rocket:physics", {
|
|
|
|
speed = 0.7
|
|
|
|
})
|
2021-04-20 15:34:11 +00:00
|
|
|
else
|
2021-04-20 15:32:25 +00:00
|
|
|
physics.remove(name, "shooter_rocket:physics")
|
|
|
|
end
|
2021-04-20 15:34:11 +00:00
|
|
|
end
|
|
|
|
end
|
2021-04-20 14:28:51 +00:00
|
|
|
end)
|
|
|
|
|
2017-07-13 12:33:00 +00:00
|
|
|
--Backwards compatibility
|
|
|
|
minetest.register_alias("shooter:rocket", "shooter_rocket:rocket")
|
|
|
|
minetest.register_alias("shooter:rocket_gun", "shooter_rocket:rocket_gun")
|
|
|
|
minetest.register_alias("shooter:rocket_gun_loaded", "shooter_rocket:rocket_gun_loaded")
|