2019-03-17 18:13:26 +00:00
|
|
|
--[[
|
|
|
|
Shooter Grenade [shooter_grenade]
|
|
|
|
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.
|
|
|
|
]]--
|
|
|
|
|
2017-07-13 12:33:00 +00:00
|
|
|
minetest.register_entity("shooter_grenade:grenade_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_grenade.png",
|
|
|
|
"shooter_grenade.png",
|
|
|
|
"shooter_grenade.png",
|
|
|
|
"shooter_grenade.png",
|
|
|
|
"shooter_grenade.png",
|
|
|
|
"shooter_grenade.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}
|
|
|
|
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, 2, 25, 5, 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,
|
|
|
|
get_staticdata = function(self)
|
|
|
|
return "expired"
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2017-07-13 12:33:00 +00:00
|
|
|
minetest.register_tool("shooter_grenade:grenade", {
|
2014-07-26 20:18:10 +00:00
|
|
|
description = "Grenade",
|
|
|
|
inventory_image = "shooter_hand_grenade.png",
|
|
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
|
|
if not minetest.setting_getbool("creative_mode") then
|
2019-03-15 17:55:37 +00:00
|
|
|
itemstack:clear()
|
2014-07-26 20:18:10 +00:00
|
|
|
end
|
|
|
|
if pointed_thing.type ~= "nothing" then
|
|
|
|
local pointed = minetest.get_pointed_thing_position(pointed_thing)
|
2019-03-15 17:55:37 +00:00
|
|
|
if vector.distance(user:get_pos(), pointed) < 8 then
|
2019-03-16 19:33:08 +00:00
|
|
|
shooter.blast(pointed, 1, 25, 5)
|
2014-07-26 20:18:10 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
2019-03-15 17:55:37 +00:00
|
|
|
local pos = user:get_pos()
|
2014-07-26 20:18:10 +00:00
|
|
|
local dir = user:get_look_dir()
|
2019-03-15 17:55:37 +00:00
|
|
|
local yaw = user:get_look_horizontal()
|
2014-07-26 20:18:10 +00:00
|
|
|
if pos and dir then
|
2019-03-15 17:55:37 +00:00
|
|
|
pos.y = pos.y + shooter.config.camera_height
|
2017-07-13 12:33:00 +00:00
|
|
|
local obj = minetest.add_entity(pos, "shooter_grenade:grenade_entity")
|
2014-07-26 20:18:10 +00:00
|
|
|
if obj then
|
2019-03-15 17:55:37 +00:00
|
|
|
minetest.sound_play("shooter_throw", {object=obj})
|
|
|
|
obj:set_velocity(vector.multiply(dir, 15))
|
|
|
|
obj:set_acceleration({x=dir.x * -3, y=-10, z=dir.z * -3})
|
|
|
|
obj:set_yaw(yaw + math.pi / 2)
|
2014-07-26 20:18:10 +00:00
|
|
|
local ent = obj:get_luaentity()
|
|
|
|
if ent then
|
2019-03-15 17:55:37 +00:00
|
|
|
ent.user = user:get_player_name()
|
2014-07-26 20:18:10 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
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_grenade:grenade",
|
2014-07-26 20:18:10 +00:00
|
|
|
recipe = {
|
|
|
|
{"tnt:gunpowder", "default:steel_ingot"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2017-07-13 12:33:00 +00:00
|
|
|
--Backwards compatibility
|
|
|
|
minetest.register_alias("shooter:grenade", "shooter_grenade:grenade")
|