forked from mtcontrib/throwing
1.1.2 fixed reloading and dependencies
This commit is contained in:
parent
65e0074427
commit
3a0ac8614a
|
@ -1,5 +1,6 @@
|
|||
default
|
||||
bucket
|
||||
fire
|
||||
farming
|
||||
tnt
|
||||
dye
|
||||
bucket?
|
||||
fire?
|
||||
tnt?
|
||||
|
|
|
@ -2,6 +2,20 @@
|
|||
--~ Shot and reload system
|
||||
--~
|
||||
|
||||
local players = {}
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local playerName = player:get_player_name()
|
||||
players[playerName] = {
|
||||
reloading=false,
|
||||
}
|
||||
end)
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
local playerName = player:get_player_name()
|
||||
players[playerName] = nil
|
||||
end)
|
||||
|
||||
function throwing_shoot_arrow (itemstack, player, stiffness, is_cross)
|
||||
local arrow = itemstack:get_metadata()
|
||||
itemstack:set_metadata("")
|
||||
|
@ -43,6 +57,8 @@ function throwing_unload (itemstack, player, unloaded, wear)
|
|||
end
|
||||
|
||||
function throwing_reload (itemstack, player, pos, is_cross, loaded)
|
||||
local playerName = player:get_player_name()
|
||||
players[playerName]['reloading'] = false
|
||||
if itemstack:get_name() == player:get_wielded_item():get_name() then
|
||||
if (pos.x == player:getpos().x and pos.y == player:getpos().y and pos.z == player:getpos().z) or not is_cross then
|
||||
local wear = itemstack:get_wear()
|
||||
|
@ -58,3 +74,60 @@ function throwing_reload (itemstack, player, pos, is_cross, loaded)
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Bows and crossbows
|
||||
|
||||
function throwing_register_bow (name, desc, scale, stiffness, reload_time, toughness, is_cross, craft)
|
||||
minetest.register_tool("throwing:" .. name, {
|
||||
description = desc,
|
||||
inventory_image = "throwing_" .. name .. ".png",
|
||||
wield_scale = scale,
|
||||
stack_max = 1,
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
local pos = user:getpos()
|
||||
local playerName = user:get_player_name()
|
||||
if not players[playerName]['reloading'] then
|
||||
players[playerName]['reloading'] = true
|
||||
minetest.after(reload_time, throwing_reload, itemstack, user, pos, is_cross, "throwing:" .. name .. "_loaded")
|
||||
end
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_tool("throwing:" .. name .. "_loaded", {
|
||||
description = desc,
|
||||
inventory_image = "throwing_" .. name .. "_loaded.png",
|
||||
wield_scale = scale,
|
||||
stack_max = 1,
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
local wear = itemstack:get_wear()
|
||||
if not minetest.setting_getbool("creative_mode") then
|
||||
wear = wear + (65535/toughness)
|
||||
end
|
||||
local unloaded = "throwing:" .. name
|
||||
throwing_shoot_arrow(itemstack, user, stiffness, is_cross)
|
||||
minetest.after(0.01, throwing_unload, itemstack, user, unloaded, wear)
|
||||
return itemstack
|
||||
end,
|
||||
on_drop = function(itemstack, dropper, pointed_thing)
|
||||
local wear = itemstack:get_wear()
|
||||
local unloaded = "throwing:" .. name
|
||||
minetest.after(0.01, throwing_unload, itemstack, dropper, unloaded, wear)
|
||||
end,
|
||||
groups = {not_in_creative_inventory=1},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'throwing:' .. name,
|
||||
recipe = craft
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'throwing:' .. name,
|
||||
recipe = {
|
||||
{craft[1][3], craft[1][2], craft[1][1]},
|
||||
{craft[2][3], craft[2][2], craft[2][1]},
|
||||
{craft[3][3], craft[3][2], craft[3][1]},
|
||||
}
|
||||
})
|
||||
end
|
||||
|
|
10
init.lua
10
init.lua
|
@ -27,7 +27,7 @@ dofile(minetest.get_modpath("throwing").."/tools.lua")
|
|||
|
||||
dofile(minetest.get_modpath("throwing").."/standard_arrows.lua")
|
||||
|
||||
if not DISABLE_FIRE_ARROW then
|
||||
if minetest.get_modpath('fire') and minetest.get_modpath('bucket') and not DISABLE_FIRE_ARROW then
|
||||
dofile(minetest.get_modpath("throwing").."/fire_arrow.lua")
|
||||
end
|
||||
|
||||
|
@ -43,7 +43,7 @@ if not DISABLE_BUILD_ARROW then
|
|||
dofile(minetest.get_modpath("throwing").."/build_arrow.lua")
|
||||
end
|
||||
|
||||
if not DISABLE_TNT_ARROW then
|
||||
if minetest.get_modpath('fire') and minetest.get_modpath('tnt') not DISABLE_TNT_ARROW then
|
||||
dofile(minetest.get_modpath("throwing").."/tnt_arrow.lua")
|
||||
end
|
||||
|
||||
|
@ -51,11 +51,13 @@ if not DISABLE_TORCH_ARROW then
|
|||
dofile(minetest.get_modpath("throwing").."/torch_arrow.lua")
|
||||
end
|
||||
|
||||
if not DISABLE_SHELL_ARROW then
|
||||
if minetest.get_modpath('tnt') and not DISABLE_SHELL_ARROW then
|
||||
dofile(minetest.get_modpath("throwing").."/shell_arrow.lua")
|
||||
end
|
||||
|
||||
dofile(minetest.get_modpath("throwing").."/fireworks_arrows.lua")
|
||||
if minetest.get_modpath('tnt') then
|
||||
dofile(minetest.get_modpath("throwing").."/fireworks_arrows.lua")
|
||||
end
|
||||
|
||||
if minetest.setting_get("log_mods") then
|
||||
minetest.log("action", "throwing loaded")
|
||||
|
|
|
@ -15,6 +15,9 @@
|
|||
# DISABLE_ROYAL_BOW = true
|
||||
#
|
||||
#
|
||||
# DISABLE_CROSSBOW = true
|
||||
#
|
||||
#
|
||||
# DISABLE_BUILD_ARROW = true
|
||||
#
|
||||
#
|
||||
|
@ -39,6 +42,9 @@
|
|||
# DISABLE_TELEPORT_ARROW = true
|
||||
#
|
||||
#
|
||||
# DISABLE_FIRE_ARROW = true
|
||||
#
|
||||
#
|
||||
# DISABLE_TNT_ARROW = true
|
||||
#
|
||||
#
|
||||
|
|
51
tools.lua
51
tools.lua
|
@ -1,54 +1,3 @@
|
|||
function throwing_register_bow (name, desc, scale, stiffness, reload_time, toughness, is_cross, craft)
|
||||
minetest.register_tool("throwing:" .. name, {
|
||||
description = desc,
|
||||
inventory_image = "throwing_" .. name .. ".png",
|
||||
wield_scale = scale,
|
||||
stack_max = 1,
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
local pos = user:getpos()
|
||||
minetest.after(reload_time, throwing_reload, itemstack, user, pos, is_cross, "throwing:" .. name .. "_loaded")
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_tool("throwing:" .. name .. "_loaded", {
|
||||
description = desc,
|
||||
inventory_image = "throwing_" .. name .. "_loaded.png",
|
||||
wield_scale = scale,
|
||||
stack_max = 1,
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
local wear = itemstack:get_wear()
|
||||
if not minetest.setting_getbool("creative_mode") then
|
||||
wear = wear + (65535/toughness)
|
||||
end
|
||||
local unloaded = "throwing:" .. name
|
||||
throwing_shoot_arrow(itemstack, user, stiffness, is_cross)
|
||||
minetest.after(0.01, throwing_unload, itemstack, user, unloaded, wear)
|
||||
return itemstack
|
||||
end,
|
||||
on_drop = function(itemstack, dropper, pointed_thing)
|
||||
local wear = itemstack:get_wear()
|
||||
local unloaded = "throwing:" .. name
|
||||
minetest.after(0.01, throwing_unload, itemstack, dropper, unloaded, wear)
|
||||
end,
|
||||
groups = {not_in_creative_inventory=1},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'throwing:' .. name,
|
||||
recipe = craft
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'throwing:' .. name,
|
||||
recipe = {
|
||||
{craft[1][3], craft[1][2], craft[1][1]},
|
||||
{craft[2][3], craft[2][2], craft[2][1]},
|
||||
{craft[3][3], craft[3][2], craft[3][1]},
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
if not DISABLE_WOODEN_BOW then
|
||||
throwing_register_bow ('bow_wood', 'Wooden bow', {x=1, y=1, z=0.5}, 11, 0.8, 50, false, {
|
||||
{'', 'default:stick', ''},
|
||||
|
|
Loading…
Reference in New Issue
Block a user