Improve shooter_rocket
This commit is contained in:
parent
0bf4ba1219
commit
378c2c200e
3 changed files with 138 additions and 37 deletions
|
@ -57,6 +57,8 @@ Adds simple hand grenades.
|
|||
|
||||
**Depends:** shooter
|
||||
|
||||
**Optional Depends:** physics (from capturetheflag)
|
||||
|
||||
<img align="left" width="32" height="32" src="https://raw.githubusercontent.com/stujones11/shooter/master/shooter_rocket/textures/shooter_rocket_gun_loaded.png">
|
||||
Adds rocket missiles and launching gun.
|
||||
|
||||
|
|
|
@ -43,9 +43,7 @@ minetest.register_entity("shooter_rocket:rocket_entity", {
|
|||
self.object:remove()
|
||||
end
|
||||
end,
|
||||
on_step = function(self, dtime)
|
||||
self.timer = self.timer + dtime
|
||||
if self.timer > 0.2 then
|
||||
on_step = function(self)
|
||||
local pos = self.object:get_pos()
|
||||
local above = {x=pos.x, y=pos.y + 1, z=pos.z}
|
||||
if minetest.get_node(pos).name ~= "air" then
|
||||
|
@ -57,19 +55,116 @@ minetest.register_entity("shooter_rocket:rocket_entity", {
|
|||
end
|
||||
self.object:remove()
|
||||
end
|
||||
self.timer = 0
|
||||
end
|
||||
end,
|
||||
get_staticdata = function()
|
||||
return "expired"
|
||||
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", {
|
||||
description = "Rocket Gun",
|
||||
inventory_image = "shooter_rocket_gun_loaded.png",
|
||||
groups = {not_in_creative_inventory=1},
|
||||
on_place = on_rclick,
|
||||
on_secondary_use = on_rclick,
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
if not minetest.get_modpath("physics") then
|
||||
scoped[user:get_player_name()] = true
|
||||
end
|
||||
if scoped[user:get_player_name()] then
|
||||
if not minetest.setting_getbool("creative_mode") then
|
||||
itemstack:add_wear(65535 / 50)
|
||||
end
|
||||
|
@ -99,12 +194,15 @@ minetest.register_tool("shooter_rocket:rocket_gun_loaded", {
|
|||
end
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_tool("shooter_rocket:rocket_gun", {
|
||||
description = "Rocket Gun",
|
||||
inventory_image = "shooter_rocket_gun.png",
|
||||
on_place = on_rclick,
|
||||
on_secondary_use = on_rclick,
|
||||
on_use = function(itemstack, user)
|
||||
local inv = user:get_inventory()
|
||||
if inv:contains_item("main", "shooter_rocket:rocket") then
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
name = shooter_rocket
|
||||
description = Adds rocket missiles and launching gun
|
||||
depends = shooter
|
||||
optional_depends = physics
|
||||
|
|
Loading…
Reference in a new issue