Crossbow fixes and tweaks

This commit is contained in:
epCode 2021-02-15 12:37:46 -08:00
parent 9307e06df5
commit 86f988890d
9 changed files with 15 additions and 7 deletions

View File

@ -64,7 +64,6 @@ mcl_bows.shoot_arrow = function(arrow_item, pos, dir, yaw, shooter, power, damag
le._startpos = pos le._startpos = pos
le._knockback = knockback le._knockback = knockback
le._collectable = collectable le._collectable = collectable
minetest.sound_play("mcl_bows_bow_shoot", {pos=pos, max_hear_distance=16}, true)
if shooter ~= nil and shooter:is_player() then if shooter ~= nil and shooter:is_player() then
if obj:get_luaentity().player == "" then if obj:get_luaentity().player == "" then
obj:get_luaentity().player = shooter obj:get_luaentity().player = shooter
@ -120,6 +119,7 @@ local player_shoot_arrow = function(itemstack, player, power, damage, is_critica
local dir = player:get_look_dir() local dir = player:get_look_dir()
local yaw = player:get_look_horizontal() local yaw = player:get_look_horizontal()
minetest.sound_play("mcl_bows_bow_shoot", {pos=playerpos, max_hear_distance=16}, true)
mcl_bows.shoot_arrow(arrow_itemstring, {x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, dir, yaw, player, power, damage, is_critical, player:get_wielded_item(), not infinity_used) mcl_bows.shoot_arrow(arrow_itemstring, {x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, dir, yaw, player, power, damage, is_critical, player:get_wielded_item(), not infinity_used)
return true return true
end end

View File

@ -60,7 +60,6 @@ mcl_bows.shoot_arrow = function(arrow_item, pos, dir, yaw, shooter, power, damag
le._startpos = pos le._startpos = pos
le._knockback = knockback le._knockback = knockback
le._collectable = collectable le._collectable = collectable
minetest.sound_play("mcl_bows_bow_shoot", {pos=pos, max_hear_distance=16}, true)
if shooter ~= nil and shooter:is_player() then if shooter ~= nil and shooter:is_player() then
if obj:get_luaentity().player == "" then if obj:get_luaentity().player == "" then
obj:get_luaentity().player = shooter obj:get_luaentity().player = shooter
@ -95,6 +94,7 @@ local player_shoot_arrow = function(itemstack, player, power, damage, is_critica
local dir = player:get_look_dir() local dir = player:get_look_dir()
local yaw = player:get_look_horizontal() local yaw = player:get_look_horizontal()
minetest.sound_play("mcl_bows_crossbow_shoot", {pos=playerpos, max_hear_distance=16}, true)
mcl_bows.shoot_arrow("mcl_bows:arrow", {x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, dir, yaw, player, power, damage, is_critical, player:get_wielded_item(), not infinity_used) mcl_bows.shoot_arrow("mcl_bows:arrow", {x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, dir, yaw, player, power, damage, is_critical, player:get_wielded_item(), not infinity_used)
return true return true
end end
@ -104,8 +104,8 @@ minetest.register_tool("mcl_bows:crossbow", {
description = S("Crossbow"), description = S("Crossbow"),
_tt_help = S("Launches arrows"), _tt_help = S("Launches arrows"),
_doc_items_longdesc = S("Crossbows are ranged weapons to shoot arrows at your foes.").."\n".. _doc_items_longdesc = S("Crossbows are ranged weapons to shoot arrows at your foes.").."\n"..
S("The speed and damage of the arrow increases the longer you charge. The regular damage of the arrow is between 1 and 9. At full charge, there's also a 20% of a critical hit, dealing 10 damage instead."), S("The speed and damage of the arrow increases the longer you charge. The regular damage of the arrow is between 1 and 9. At full charge, there's also a 20% of a critical hit, dealing 11 damage instead."),
_doc_items_usagehelp = S("To use the crossbow, you first need to have at least one arrow anywhere in your inventory (unless in Creative Mode). Hold down the right mouse button to charge, release to shoot."), _doc_items_usagehelp = S("To use the crossbow, you first need to have at least one arrow anywhere in your inventory (unless in Creative Mode). Hold down the right mouse button to charge, and wait for arrow to load. when the Crossbow is loaded, you will be able to tap right click to fire"),
_doc_items_durability = BOW_DURABILITY, _doc_items_durability = BOW_DURABILITY,
inventory_image = "mcl_bows_crossbow.png", inventory_image = "mcl_bows_crossbow.png",
wield_scale = { x = 1.8, y = 1.8, z = 1 }, wield_scale = { x = 1.8, y = 1.8, z = 1 },
@ -300,6 +300,7 @@ controls.register_on_press(function(player, key)
end) end)
controls.register_on_hold(function(player, key, time) controls.register_on_hold(function(player, key, time)
playerpos = player:get_pos()
arrow_stack = get_arrow(player) arrow_stack = get_arrow(player)
local name = player:get_player_name() local name = player:get_player_name()
local creative = minetest.is_creative_enabled(name) local creative = minetest.is_creative_enabled(name)
@ -312,8 +313,10 @@ controls.register_on_hold(function(player, key, time)
local enchanted = mcl_enchanting.is_enchanted(wielditem:get_name()) local enchanted = mcl_enchanting.is_enchanted(wielditem:get_name())
if enchanted then if enchanted then
wielditem:set_name("mcl_bows:crossbow_0_enchanted") wielditem:set_name("mcl_bows:crossbow_0_enchanted")
minetest.sound_play("mcl_bows_crossbow_drawback_0", {pos=playerpos, max_hear_distance=16}, true)
else else
wielditem:set_name("mcl_bows:crossbow_0") wielditem:set_name("mcl_bows:crossbow_0")
minetest.sound_play("mcl_bows_crossbow_drawback_0", {pos=playerpos, max_hear_distance=16}, true)
end end
player:set_wielded_item(wielditem) player:set_wielded_item(wielditem)
bow_load[name] = minetest.get_us_time() bow_load[name] = minetest.get_us_time()
@ -322,12 +325,16 @@ controls.register_on_hold(function(player, key, time)
if player:get_wield_index() == bow_index[name] then if player:get_wield_index() == bow_index[name] then
if type(bow_load[name]) == "number" then if type(bow_load[name]) == "number" then
if wielditem:get_name() == "mcl_bows:crossbow_0" and minetest.get_us_time() - bow_load[name] >= BOW_CHARGE_TIME_HALF then if wielditem:get_name() == "mcl_bows:crossbow_0" and minetest.get_us_time() - bow_load[name] >= BOW_CHARGE_TIME_HALF then
minetest.sound_play("mcl_bows_crossbow_drawback_1", {pos=playerpos, max_hear_distance=16}, true)
wielditem:set_name("mcl_bows:crossbow_1") wielditem:set_name("mcl_bows:crossbow_1")
elseif wielditem:get_name() == "mcl_bows:crossbow_0_enchanted" and minetest.get_us_time() - bow_load[name] >= BOW_CHARGE_TIME_HALF then elseif wielditem:get_name() == "mcl_bows:crossbow_0_enchanted" and minetest.get_us_time() - bow_load[name] >= BOW_CHARGE_TIME_HALF then
minetest.sound_play("mcl_bows_crossbow_drawback_1", {pos=playerpos, max_hear_distance=16}, true)
wielditem:set_name("mcl_bows:crossbow_1_enchanted") wielditem:set_name("mcl_bows:crossbow_1_enchanted")
elseif wielditem:get_name() == "mcl_bows:crossbow_1" and minetest.get_us_time() - bow_load[name] >= BOW_CHARGE_TIME_FULL then elseif wielditem:get_name() == "mcl_bows:crossbow_1" and minetest.get_us_time() - bow_load[name] >= BOW_CHARGE_TIME_FULL then
minetest.sound_play("mcl_bows_crossbow_drawback_2", {pos=playerpos, max_hear_distance=16}, true)
wielditem:set_name("mcl_bows:crossbow_2") wielditem:set_name("mcl_bows:crossbow_2")
if minetest.get_us_time() - bow_load[name] >= 60000 then if minetest.get_us_time() - bow_load[name] >= 1000000 then
minetest.sound_play("mcl_bows_crossbow_load", {pos=playerpos, max_hear_distance=16}, true)
wielditem:set_name("mcl_bows:loaded_crossbow") wielditem:set_name("mcl_bows:loaded_crossbow")
local arrow_stack, arrow_stack_id = get_arrow(player) local arrow_stack, arrow_stack_id = get_arrow(player)
local arrow_itemstring local arrow_itemstring
@ -358,6 +365,7 @@ controls.register_on_hold(function(player, key, time)
end end
end end
elseif wielditem:get_name() == "mcl_bows:crossbow_1_enchanted" and minetest.get_us_time() - bow_load[name] >= BOW_CHARGE_TIME_FULL then elseif wielditem:get_name() == "mcl_bows:crossbow_1_enchanted" and minetest.get_us_time() - bow_load[name] >= BOW_CHARGE_TIME_FULL then
minetest.sound_play("mcl_bows_crossbow_drawback_2", {pos=playerpos, max_hear_distance=16}, true)
wielditem:set_name("mcl_bows:crossbow_2_enchanted") wielditem:set_name("mcl_bows:crossbow_2_enchanted")
if minetest.get_us_time() - bow_load[name] >= 60000 then if minetest.get_us_time() - bow_load[name] >= 60000 then
wielditem:set_name("mcl_bows:loaded_crossbow_enchanted") wielditem:set_name("mcl_bows:loaded_crossbow_enchanted")

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 567 B

After

Width:  |  Height:  |  Size: 565 B

View File

@ -51,7 +51,7 @@ minetest.register_globalstep(function(dtime)
else else
playerphysics.remove_physics_factor(player, "speed", "mcl_playerplus:crossbow_walking") playerphysics.remove_physics_factor(player, "speed", "mcl_playerplus:crossbow_walking")
end end
if controls.sneak and player:get_attach() == nil then if controls.sneak and player:get_attach() == nil then
-- controls head pitch when sneaking -- controls head pitch when sneaking
player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch+36,0,0)) player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch+36,0,0))
@ -62,7 +62,7 @@ minetest.register_globalstep(function(dtime)
-- controls head pitch when swiming -- controls head pitch when swiming
player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch+90,0,0)) player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch+90,0,0))
-- sets eye height, and nametag color accordingly -- sets eye height, and nametag color accordingly
player:set_properties({collisionbox = {-0.35,1,-0.35,0.35,1.8,0.35}, eye_height = 1.65, nametag_color = { r = 225, b = 225, a = 225, g = 225 }}) player:set_properties({collisionbox = {-0.35,0,-0.35,0.35,0.8,0.35}, eye_height = 0.65, nametag_color = { r = 225, b = 225, a = 225, g = 225 }})
else else
-- controls head pitch when not sneaking -- controls head pitch when not sneaking