2019-03-17 18:13:26 +00:00
|
|
|
--[[
|
|
|
|
Shooter Grapple Hook [shooter_hook]
|
|
|
|
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.
|
|
|
|
]]--
|
|
|
|
|
2014-07-26 20:18:10 +00:00
|
|
|
local function throw_hook(itemstack, user, vel)
|
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 and yaw then
|
|
|
|
if not minetest.setting_getbool("creative_mode") then
|
2019-03-15 17:55:37 +00:00
|
|
|
itemstack:add_wear(65535 / 100)
|
2014-07-26 20:18:10 +00:00
|
|
|
end
|
|
|
|
pos.y = pos.y + 1.5
|
2017-07-13 12:33:00 +00:00
|
|
|
local obj = minetest.add_entity(pos, "shooter_hook:hook")
|
2014-07-26 20:18:10 +00:00
|
|
|
if obj then
|
|
|
|
minetest.sound_play("shooter_throw", {object=obj})
|
2019-03-15 17:55:37 +00:00
|
|
|
obj:set_velocity(vector.multiply(dir, vel))
|
|
|
|
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
|
|
|
ent.itemstack = itemstack
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-13 12:33:00 +00:00
|
|
|
minetest.register_entity("shooter_hook:hook", {
|
2014-07-26 20:18:10 +00:00
|
|
|
physical = true,
|
|
|
|
timer = 0,
|
|
|
|
visual = "wielditem",
|
|
|
|
visual_size = {x=1/2, y=1/2},
|
2017-07-13 12:33:00 +00:00
|
|
|
textures = {"shooter_hook:grapple_hook"},
|
2019-03-15 17:55:37 +00:00
|
|
|
user = nil,
|
2014-07-26 20:18:10 +00:00
|
|
|
itemstack = "",
|
|
|
|
collisionbox = {-1/4,-1/4,-1/4, 1/4,1/4,1/4},
|
|
|
|
on_activate = function(self, staticdata)
|
|
|
|
self.object:set_armor_groups({fleshy=0})
|
|
|
|
if staticdata == "expired" then
|
|
|
|
self.object:remove()
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
on_step = function(self, dtime)
|
2019-03-15 17:55:37 +00:00
|
|
|
if not self.user then
|
2014-07-26 20:18:10 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
self.timer = self.timer + dtime
|
|
|
|
if self.timer > 0.25 then
|
2019-03-15 17:55:37 +00:00
|
|
|
local pos = self.object:get_pos()
|
2014-07-26 20:18:10 +00:00
|
|
|
local below = {x=pos.x, y=pos.y - 1, z=pos.z}
|
|
|
|
local node = minetest.get_node(below)
|
|
|
|
if node.name ~= "air" then
|
2019-03-15 17:55:37 +00:00
|
|
|
self.object:set_velocity({x=0, y=-10, z=0})
|
|
|
|
self.object:set_acceleration({x=0, y=0, z=0})
|
2014-07-26 20:18:10 +00:00
|
|
|
if minetest.get_item_group(node.name, "liquid") == 0 and
|
|
|
|
minetest.get_node(pos).name == "air" then
|
2019-03-15 17:55:37 +00:00
|
|
|
local player = minetest.get_player_by_name(self.user)
|
|
|
|
if player then
|
2019-03-19 19:23:23 +00:00
|
|
|
player:move_to(pos)
|
2019-03-15 17:55:37 +00:00
|
|
|
end
|
2014-07-26 20:18:10 +00:00
|
|
|
end
|
|
|
|
if minetest.get_item_group(node.name, "lava") == 0 then
|
|
|
|
minetest.add_item(pos, self.itemstack)
|
|
|
|
end
|
|
|
|
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_hook:grapple_hook", {
|
2014-07-26 20:18:10 +00:00
|
|
|
description = "Grappling Hook",
|
|
|
|
inventory_image = "shooter_hook.png",
|
|
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
|
|
if pointed_thing.type ~= "nothing" then
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
throw_hook(itemstack, user, 14)
|
|
|
|
return ""
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2017-07-13 12:33:00 +00:00
|
|
|
minetest.register_tool("shooter_hook:grapple_gun", {
|
2014-07-26 20:18:10 +00:00
|
|
|
description = "Grappling Gun",
|
|
|
|
inventory_image = "shooter_hook_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()
|
2019-03-19 19:23:23 +00:00
|
|
|
if inv:contains_item("main", "shooter_hook:grapple_hook") and
|
2014-07-26 20:18:10 +00:00
|
|
|
inv:contains_item("main", "tnt:gunpowder") then
|
|
|
|
inv:remove_item("main", "tnt:gunpowder")
|
|
|
|
minetest.sound_play("shooter_reload", {object=user})
|
2017-07-13 12:33:00 +00:00
|
|
|
local stack = inv:remove_item("main", "shooter_hook:grapple_hook")
|
|
|
|
itemstack = "shooter_hook:grapple_gun_loaded 1 "..stack:get_wear()
|
2014-07-26 20:18:10 +00:00
|
|
|
else
|
|
|
|
minetest.sound_play("shooter_click", {object=user})
|
|
|
|
end
|
|
|
|
return itemstack
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2017-07-13 12:33:00 +00:00
|
|
|
minetest.register_tool("shooter_hook:grapple_gun_loaded", {
|
2014-07-26 20:18:10 +00:00
|
|
|
description = "Grappling Gun",
|
|
|
|
inventory_image = "shooter_hook_gun_loaded.png",
|
|
|
|
groups = {not_in_creative_inventory=1},
|
|
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
|
|
if pointed_thing.type ~= "nothing" then
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
minetest.sound_play("shooter_pistol", {object=user})
|
2017-07-13 12:33:00 +00:00
|
|
|
itemstack = ItemStack("shooter_hook:grapple_hook 1 "..itemstack:get_wear())
|
2014-07-26 20:18:10 +00:00
|
|
|
throw_hook(itemstack, user, 20)
|
2017-07-13 12:33:00 +00:00
|
|
|
return "shooter_hook:grapple_gun"
|
2014-07-26 20:18:10 +00:00
|
|
|
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_hook:grapple_hook",
|
2014-07-26 20:18:10 +00:00
|
|
|
recipe = {
|
|
|
|
{"default:steel_ingot", "default:steel_ingot", "default:diamond"},
|
|
|
|
{"default:steel_ingot", "default:steel_ingot", ""},
|
|
|
|
{"default:diamond", "", "default:steel_ingot"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
minetest.register_craft({
|
2017-07-13 12:33:00 +00:00
|
|
|
output = "shooter_hook:grapple_gun",
|
2014-07-26 20:18:10 +00:00
|
|
|
recipe = {
|
|
|
|
{"", "default:steel_ingot", "default:steel_ingot"},
|
|
|
|
{"", "", "default:diamond"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2017-07-13 12:33:00 +00:00
|
|
|
--Backwards compatibility
|
|
|
|
minetest.register_alias("shooter:grapple_hook", "shooter_hook:grapple_hook")
|
|
|
|
minetest.register_alias("shooter:grapple_gun", "shooter_hook:grapple_gun")
|
|
|
|
minetest.register_alias("shooter:grapple_gun_loaded", "shooter_hook:grapple_gun_loaded")
|