Update init.lua

This commit is contained in:
olliy 2021-04-21 12:50:15 +05:00 committed by GitHub
parent 8b0900ac82
commit 1a42bcd1e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -17,6 +17,17 @@ 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_joinplayer(function(player)
plcooldown[player:get_player_name()] = 0
end)
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,
@ -70,33 +81,43 @@ minetest.register_tool("shooter_rocket:rocket_gun_loaded", {
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_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
if not minetest.setting_getbool("creative_mode") then if plcooldown[user:get_player_name()] ~= 0 then
itemstack:add_wear(65535 / 50) minetest.chat_send_player(user:get_player_name(), "Your rocket has a cooldown!")
end else
itemstack = "shooter_rocket:rocket_gun 1 "..itemstack:get_wear() if not minetest.setting_getbool("creative_mode") then
if pointed_thing.type ~= "nothing" then itemstack:add_wear(65535 / 50)
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
end itemstack = "shooter_rocket:rocket_gun 1 "..itemstack:get_wear()
local pos = user:get_pos() if pointed_thing.type ~= "nothing" then
local dir = user:get_look_dir() local pointed = minetest.get_pointed_thing_position(pointed_thing)
local yaw = user:get_look_horizontal() if vector.distance(user:get_pos(), pointed) < 8 then
if pos and dir and yaw then shooter.blast(pointed, 2, 50, 7)
pos.y = pos.y + user:get_properties().eye_height return itemstack
local obj = minetest.add_entity(pos, "shooter_rocket:rocket_entity")
if obj then
minetest.sound_play("shooter_rocket_fire", {object=obj})
obj:set_velocity(vector.multiply(dir, 20))
obj:set_acceleration({x=dir.x * -3, y=-10, z=dir.z * -3})
obj:set_yaw(yaw + math.pi / 2)
local ent = obj:get_luaentity()
if ent then
ent.user = user:get_player_name()
end end
end end
local pos = user:get_pos()
local dir = user:get_look_dir()
local yaw = user:get_look_horizontal()
if pos and dir and yaw then
pos.y = pos.y + user:get_properties().eye_height
local obj = minetest.add_entity(pos, "shooter_rocket:rocket_entity")
if obj then
minetest.sound_play("shooter_rocket_fire", {object=obj})
obj:set_velocity(vector.multiply(dir, 20))
obj:set_acceleration({x=dir.x * -3, y=-10, z=dir.z * -3})
obj:set_yaw(yaw + math.pi / 2)
local ent = obj:get_luaentity()
if ent then
ent.user = user:get_player_name()
end
end
end
plcooldown[user:get_player_name()] = COOLDOWN
minetest.after(COOLDOWN, function(user)
if plcooldown[user:get_player_name()] then
plcooldown[user:get_player_name()] = 0
end
end, user)
end end
return itemstack return itemstack
end, end,
@ -159,4 +180,3 @@ end)
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")