Compare commits

...

14 commits

Author SHA1 Message Date
philipmi
41d4b6c62a Update README.md 2021-05-24 21:44:58 +02:00
philipmi
0ee98344cf Merge branch 'olliy1or-patch-1' of https://github.com/olliy1or/shooter
 Conflicts:
	shooter_rocket/init.lua
	shooter_rocket/mod.conf
2021-05-24 21:42:08 +02:00
olliy
38bab6ea38
UpDaTe 2021-04-22 21:21:58 +05:00
olliy
13e981799e
Update shooter_rocket/init.lua
Co-authored-by: LoneWolfHT <lonewolf04361@gmail.com>
2021-04-22 21:20:32 +05:00
olliy
fc5c6dc502
Update shooter_rocket/init.lua
Co-authored-by: LoneWolfHT <lonewolf04361@gmail.com>
2021-04-22 21:20:06 +05:00
LoneWolfHT
5354ef82db
Update mod.conf 2021-04-22 07:55:52 -07:00
olliy
bb4195efa6
add hud_event to depends 2021-04-22 05:47:51 +05:00
olliy
2050ebc1d7
use HUD instead of sending a message 2021-04-22 05:40:16 +05:00
olliy
8667bb31c0
Update shooter_rocket/init.lua
Co-authored-by: David Leal <halfpacho@gmail.com>
2021-04-22 05:26:39 +05:00
olliy
1a42bcd1e0
Update init.lua 2021-04-21 12:50:15 +05:00
olliy
8b0900ac82
clean up 2021-04-20 20:34:11 +05:00
olliy
a76b52247a
Update init.lua 2021-04-20 20:32:25 +05:00
olliy
a97d88bf08
Update init.lua 2021-04-20 19:52:07 +05:00
olliy
0bdc630241
slow player down while holding loaded rocket 2021-04-20 19:28:51 +05:00
3 changed files with 58 additions and 118 deletions

View file

@ -55,9 +55,7 @@ Adds simple hand grenades.
[mod] Rocket Launcher [shooter_rocket] [mod] Rocket Launcher [shooter_rocket]
-------------------------------------- --------------------------------------
**Depends:** shooter **Depends:** shooter, hud_events, physics
**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"> <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. Adds rocket missiles and launching gun.

View file

@ -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,7 +50,9 @@ 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)
self.timer = self.timer + dtime
if self.timer > 0.2 then
local pos = self.object:get_pos() local pos = self.object:get_pos()
local above = {x=pos.x, y=pos.y + 1, z=pos.z} local above = {x=pos.x, y=pos.y + 1, z=pos.z}
if minetest.get_node(pos).name ~= "air" then if minetest.get_node(pos).name ~= "air" then
@ -55,116 +64,26 @@ minetest.register_entity("shooter_rocket:rocket_entity", {
end end
self.object:remove() self.object:remove()
end end
self.timer = 0
end
end, end,
get_staticdata = function() get_staticdata = function()
return "expired" return "expired"
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
plcooldown[username] = COOLDOWN
minetest.after(COOLDOWN, function(user)
if plcooldown[username] then
plcooldown[username] = nil
end
end, user)
end
return itemstack return itemstack
end
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")

View file

@ -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