Update init.lua
This commit is contained in:
parent
8b0900ac82
commit
1a42bcd1e0
1 changed files with 45 additions and 25 deletions
|
@ -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.
|
||||
]]--
|
||||
|
||||
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", {
|
||||
description = "Rocket",
|
||||
stack_max = 1,
|
||||
|
@ -70,33 +81,43 @@ 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 not minetest.setting_getbool("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
|
||||
if plcooldown[user:get_player_name()] ~= 0 then
|
||||
minetest.chat_send_player(user:get_player_name(), "Your rocket has a cooldown!")
|
||||
else
|
||||
if not minetest.setting_getbool("creative_mode") then
|
||||
itemstack:add_wear(65535 / 50)
|
||||
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()
|
||||
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
|
||||
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
|
||||
return itemstack
|
||||
end,
|
||||
|
@ -159,4 +180,3 @@ end)
|
|||
minetest.register_alias("shooter:rocket", "shooter_rocket:rocket")
|
||||
minetest.register_alias("shooter:rocket_gun", "shooter_rocket:rocket_gun")
|
||||
minetest.register_alias("shooter:rocket_gun_loaded", "shooter_rocket:rocket_gun_loaded")
|
||||
|
||||
|
|
Loading…
Reference in a new issue