Change rocket mechanics
This commit is contained in:
parent
4733f7e6c7
commit
bb8775c3bb
1 changed files with 31 additions and 33 deletions
|
@ -17,15 +17,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
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)
|
||||
local ROCKET_COOLDOWN = 6
|
||||
local RELOAD_TIME = 2
|
||||
|
||||
minetest.register_craftitem("shooter_rocket:rocket", {
|
||||
description = "Rocket",
|
||||
description = "Single-use Rocket",
|
||||
stack_max = 1,
|
||||
inventory_image = "shooter_rocket_inv.png",
|
||||
})
|
||||
|
@ -77,24 +73,15 @@ minetest.register_tool("shooter_rocket:rocket_gun_loaded", {
|
|||
inventory_image = "shooter_rocket_gun_loaded.png",
|
||||
groups = {not_in_creative_inventory=1},
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
if plcooldown[user:get_player_name()] then
|
||||
hud_event.new(user:get_player_name(), {
|
||||
name = "shooter_rocket:cooldown",
|
||||
color = "0xC1FF44",
|
||||
value = "Your rocket has a cooldown!"
|
||||
})
|
||||
else
|
||||
if not minetest.settings:get_bool("creative_mode") then
|
||||
itemstack:add_wear(65535 / 50)
|
||||
end
|
||||
itemstack = "shooter_rocket:rocket_gun 1 "..itemstack:get_wear()
|
||||
if pointed_thing.type ~= "nothing" then
|
||||
local pointed = minetest.get_pointed_thing_position(pointed_thing)
|
||||
if vector.distance(user:get_pos(), pointed) < 8 then
|
||||
shooter.blast(pointed, 2, 50, 7)
|
||||
return itemstack
|
||||
end
|
||||
end
|
||||
if pointed_thing.type == "nothing" then
|
||||
itemstack = "shooter_rocket:rocket_gun 1 "..(65535 - 6000)
|
||||
ctf_classes.update_wear.start_update(
|
||||
user:get_player_name(),
|
||||
"shooter_rocket:rocket_gun",
|
||||
65535/RELOAD_TIME,
|
||||
true
|
||||
)
|
||||
|
||||
local pos = user:get_pos()
|
||||
local dir = user:get_look_dir()
|
||||
local yaw = user:get_look_horizontal()
|
||||
|
@ -113,12 +100,6 @@ minetest.register_tool("shooter_rocket:rocket_gun_loaded", {
|
|||
end
|
||||
end
|
||||
end
|
||||
plcooldown[username] = COOLDOWN
|
||||
minetest.after(COOLDOWN, function(user)
|
||||
if plcooldown[username] then
|
||||
plcooldown[username] = nil
|
||||
end
|
||||
end, user)
|
||||
end
|
||||
return itemstack
|
||||
end,
|
||||
|
@ -129,12 +110,29 @@ minetest.register_tool("shooter_rocket:rocket_gun", {
|
|||
inventory_image = "shooter_rocket_gun.png",
|
||||
on_use = function(itemstack, user)
|
||||
local inv = user:get_inventory()
|
||||
if inv:contains_item("main", "shooter_rocket:rocket") then
|
||||
local pos, stack = ctf_classes.update_wear.find_item(inv, "ctf_classes:rocket")
|
||||
|
||||
if itemstack:get_wear() ~= 0 then
|
||||
return
|
||||
elseif pos and stack:get_wear() == 0 then
|
||||
minetest.sound_play("shooter_reload", {object=user})
|
||||
|
||||
stack:set_wear(65535 - 6000)
|
||||
inv:set_stack("main", pos, stack)
|
||||
ctf_classes.update_wear.start_update(
|
||||
user:get_player_name(),
|
||||
"ctf_classes:rocket",
|
||||
65535/ROCKET_COOLDOWN,
|
||||
true
|
||||
)
|
||||
|
||||
itemstack = "shooter_rocket:rocket_gun_loaded 1 "
|
||||
elseif inv:contains_item("main", "shooter_rocket:rocket") then
|
||||
minetest.sound_play("shooter_reload", {object=user})
|
||||
if not minetest.settings:get_bool("creative_mode") then
|
||||
inv:remove_item("main", "shooter_rocket:rocket 1")
|
||||
end
|
||||
itemstack = "shooter_rocket:rocket_gun_loaded 1 "..itemstack:get_wear()
|
||||
itemstack = "shooter_rocket:rocket_gun_loaded 1 "
|
||||
else
|
||||
minetest.sound_play("shooter_click", {object=user})
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue