Merge branch 'olliy1or-patch-1' of https://github.com/olliy1or/shooter
Conflicts: shooter_rocket/init.lua shooter_rocket/mod.conf
This commit is contained in:
commit
0ee98344cf
2 changed files with 57 additions and 115 deletions
|
@ -17,6 +17,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
|
local plcooldown = {}
|
||||||
|
local COOLDOWN = 5
|
||||||
|
|
||||||
|
minetest.register_on_leaveplayer(function(player)
|
||||||
|
plcooldown[player:get_player_name()] = nil
|
||||||
|
end)
|
||||||
|
|
||||||
minetest.register_craftitem("shooter_rocket:rocket", {
|
minetest.register_craftitem("shooter_rocket:rocket", {
|
||||||
description = "Rocket",
|
description = "Rocket",
|
||||||
stack_max = 1,
|
stack_max = 1,
|
||||||
|
@ -43,17 +50,21 @@ minetest.register_entity("shooter_rocket:rocket_entity", {
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
on_step = function(self)
|
on_step = function(self, dtime)
|
||||||
local pos = self.object:get_pos()
|
self.timer = self.timer + dtime
|
||||||
local above = {x=pos.x, y=pos.y + 1, z=pos.z}
|
if self.timer > 0.2 then
|
||||||
if minetest.get_node(pos).name ~= "air" then
|
local pos = self.object:get_pos()
|
||||||
if self.user then
|
local above = {x=pos.x, y=pos.y + 1, z=pos.z}
|
||||||
local player = minetest.get_player_by_name(self.user)
|
if minetest.get_node(pos).name ~= "air" then
|
||||||
if player then
|
if self.user then
|
||||||
shooter.blast(above, 4, 50, 8, player)
|
local player = minetest.get_player_by_name(self.user)
|
||||||
|
if player then
|
||||||
|
shooter.blast(above, 4, 50, 8, player)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
self.object:remove()
|
||||||
end
|
end
|
||||||
self.object:remove()
|
self.timer = 0
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
get_staticdata = function()
|
get_staticdata = function()
|
||||||
|
@ -61,110 +72,18 @@ minetest.register_entity("shooter_rocket:rocket_entity", {
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
--- Scope functions taken from sniper_rifles mod
|
|
||||||
|
|
||||||
------------------
|
|
||||||
-- Private data --
|
|
||||||
------------------
|
|
||||||
|
|
||||||
-- Keep track of players who are scoping in, and their wielded item
|
|
||||||
local scoped = {}
|
|
||||||
|
|
||||||
-- Timer for scope-check globalstep
|
|
||||||
local timer = 0.2
|
|
||||||
|
|
||||||
local physics_overrides = {
|
|
||||||
speed = 0.3,
|
|
||||||
jump = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
-------------
|
|
||||||
-- Helpers --
|
|
||||||
-------------
|
|
||||||
|
|
||||||
local function show_scope(name, item_name)
|
|
||||||
local player = minetest.get_player_by_name(name)
|
|
||||||
if not player then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
scoped[name] = item_name
|
|
||||||
player:set_fov(1.1, true)
|
|
||||||
physics.set(name, "shooter_rocket:scoping", physics_overrides)
|
|
||||||
player:hud_set_flags({ wielditem = false })
|
|
||||||
end
|
|
||||||
|
|
||||||
local function hide_scope(name)
|
|
||||||
local player = minetest.get_player_by_name(name)
|
|
||||||
if not player then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
scoped[name] = nil
|
|
||||||
player:set_fov(0)
|
|
||||||
physics.remove(name, "shooter_rocket:scoping")
|
|
||||||
player:hud_set_flags({ wielditem = true })
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
local function on_rclick(item, placer, pointed_thing)
|
|
||||||
local name = placer:get_player_name()
|
|
||||||
|
|
||||||
-- Prioritize on "un-scoping", if player is using the scope
|
|
||||||
if not scoped[name] and pointed_thing.type == "node" then
|
|
||||||
return minetest.item_place(item, placer, pointed_thing)
|
|
||||||
end
|
|
||||||
|
|
||||||
if scoped[name] then
|
|
||||||
hide_scope(name)
|
|
||||||
else
|
|
||||||
-- Remove _loaded suffix added to item name by shooter
|
|
||||||
local item_name = item:get_name():gsub("_loaded", "")
|
|
||||||
show_scope(name, item_name)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
------------------
|
|
||||||
-- Scope-check --
|
|
||||||
------------------
|
|
||||||
|
|
||||||
-- Hide scope if currently wielded item is not the same item
|
|
||||||
-- player wielded when scoping
|
|
||||||
|
|
||||||
local time = 0
|
|
||||||
if minetest.get_modpath("physics") then
|
|
||||||
minetest.register_globalstep(function(dtime)
|
|
||||||
time = time + dtime
|
|
||||||
if time < timer then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
time = 0
|
|
||||||
for name, original_item in pairs(scoped) do
|
|
||||||
local player = minetest.get_player_by_name(name)
|
|
||||||
if not player then
|
|
||||||
scoped[name] = nil
|
|
||||||
else
|
|
||||||
local wielded_item = player:get_wielded_item():get_name():gsub("_loaded", "")
|
|
||||||
if wielded_item ~= original_item then
|
|
||||||
hide_scope(name)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.register_tool("shooter_rocket:rocket_gun_loaded", {
|
minetest.register_tool("shooter_rocket:rocket_gun_loaded", {
|
||||||
description = "Rocket Gun",
|
description = "Rocket Gun",
|
||||||
inventory_image = "shooter_rocket_gun_loaded.png",
|
inventory_image = "shooter_rocket_gun_loaded.png",
|
||||||
groups = {not_in_creative_inventory=1},
|
groups = {not_in_creative_inventory=1},
|
||||||
on_place = on_rclick,
|
|
||||||
on_secondary_use = on_rclick,
|
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
if not minetest.get_modpath("physics") then
|
if plcooldown[user:get_player_name()] then
|
||||||
scoped[user:get_player_name()] = true
|
hud_event.new(user:get_player_name(), {
|
||||||
end
|
name = "shooter_rocket:cooldown",
|
||||||
if scoped[user:get_player_name()] then
|
color = "0xC1FF44",
|
||||||
|
value = "Your rocket has a cooldown!"
|
||||||
|
})
|
||||||
|
else
|
||||||
if not minetest.setting_getbool("creative_mode") then
|
if not minetest.setting_getbool("creative_mode") then
|
||||||
itemstack:add_wear(65535 / 50)
|
itemstack:add_wear(65535 / 50)
|
||||||
end
|
end
|
||||||
|
@ -179,6 +98,7 @@ minetest.register_tool("shooter_rocket:rocket_gun_loaded", {
|
||||||
local pos = user:get_pos()
|
local pos = user:get_pos()
|
||||||
local dir = user:get_look_dir()
|
local dir = user:get_look_dir()
|
||||||
local yaw = user:get_look_horizontal()
|
local yaw = user:get_look_horizontal()
|
||||||
|
local username = user:get_player_name()
|
||||||
if pos and dir and yaw then
|
if pos and dir and yaw then
|
||||||
pos.y = pos.y + user:get_properties().eye_height
|
pos.y = pos.y + user:get_properties().eye_height
|
||||||
local obj = minetest.add_entity(pos, "shooter_rocket:rocket_entity")
|
local obj = minetest.add_entity(pos, "shooter_rocket:rocket_entity")
|
||||||
|
@ -189,20 +109,24 @@ minetest.register_tool("shooter_rocket:rocket_gun_loaded", {
|
||||||
obj:set_yaw(yaw + math.pi / 2)
|
obj:set_yaw(yaw + math.pi / 2)
|
||||||
local ent = obj:get_luaentity()
|
local ent = obj:get_luaentity()
|
||||||
if ent then
|
if ent then
|
||||||
ent.user = user:get_player_name()
|
ent.user = username
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return itemstack
|
plcooldown[username] = COOLDOWN
|
||||||
|
minetest.after(COOLDOWN, function(user)
|
||||||
|
if plcooldown[username] then
|
||||||
|
plcooldown[username] = nil
|
||||||
|
end
|
||||||
|
end, user)
|
||||||
end
|
end
|
||||||
|
return itemstack
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_tool("shooter_rocket:rocket_gun", {
|
minetest.register_tool("shooter_rocket:rocket_gun", {
|
||||||
description = "Rocket Gun",
|
description = "Rocket Gun",
|
||||||
inventory_image = "shooter_rocket_gun.png",
|
inventory_image = "shooter_rocket_gun.png",
|
||||||
on_place = on_rclick,
|
|
||||||
on_secondary_use = on_rclick,
|
|
||||||
on_use = function(itemstack, user)
|
on_use = function(itemstack, user)
|
||||||
local inv = user:get_inventory()
|
local inv = user:get_inventory()
|
||||||
if inv:contains_item("main", "shooter_rocket:rocket") then
|
if inv:contains_item("main", "shooter_rocket:rocket") then
|
||||||
|
@ -233,9 +157,28 @@ if shooter.config.enable_crafting == true then
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local timer = 0
|
||||||
|
minetest.register_globalstep(function(dtime)
|
||||||
|
timer = timer + dtime
|
||||||
|
if timer >= 1 then
|
||||||
|
timer = 0
|
||||||
|
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()
|
||||||
|
physics.set(name, "shooter_rocket:physics", {
|
||||||
|
speed = 0.7
|
||||||
|
})
|
||||||
|
else
|
||||||
|
physics.remove(name, "shooter_rocket:physics")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
--Backwards compatibility
|
--Backwards compatibility
|
||||||
minetest.register_alias("shooter:rocket", "shooter_rocket:rocket")
|
minetest.register_alias("shooter:rocket", "shooter_rocket:rocket")
|
||||||
minetest.register_alias("shooter:rocket_gun", "shooter_rocket:rocket_gun")
|
minetest.register_alias("shooter:rocket_gun", "shooter_rocket:rocket_gun")
|
||||||
minetest.register_alias("shooter:rocket_gun_loaded", "shooter_rocket:rocket_gun_loaded")
|
minetest.register_alias("shooter:rocket_gun_loaded", "shooter_rocket:rocket_gun_loaded")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
name = shooter_rocket
|
name = shooter_rocket
|
||||||
description = Adds rocket missiles and launching gun
|
description = Adds rocket missiles and launching gun
|
||||||
depends = shooter
|
depends = shooter, hud_events, physics
|
||||||
optional_depends = physics
|
|
||||||
|
|
Loading…
Reference in a new issue