mirror of
https://github.com/minetest-mods/throwing.git
synced 2025-01-09 09:40:26 +01:00
Add a sound a delay to the bow
This commit is contained in:
parent
000c16d292
commit
094613eb29
@ -50,6 +50,8 @@ Definition: definition table, containing:
|
||||
Default is false.
|
||||
* cooldown: bow cooldown. Default is setting throwing.bow_cooldown
|
||||
* function spawn_arrow_entity(position, arrow, player): defaults to throwing.spawn_arrow_entity
|
||||
* sound: sound to be played when the bow is used
|
||||
* delay: delay before throwing the arrow
|
||||
]]
|
||||
|
||||
-- Example:
|
||||
|
9
init.lua
9
init.lua
@ -340,11 +340,16 @@ function throwing.register_bow(name, def)
|
||||
|
||||
local index = (def.throw_itself and user:get_wield_index()) or user:get_wield_index()+1
|
||||
local res, new_stack = def.allow_shot(user, user:get_inventory():get_stack("main", index), index)
|
||||
-- Throw itself?
|
||||
if not res then
|
||||
return new_stack or itemstack
|
||||
end
|
||||
|
||||
-- Sound
|
||||
if def.sound then
|
||||
minetest.sound_play(def.sound, {to_player=user:get_player_name()})
|
||||
end
|
||||
|
||||
minetest.after(def.delay or 0, function()
|
||||
-- Shoot arrow
|
||||
if shoot_arrow(itemstack, user, def.throw_itself, new_stack) then
|
||||
if not minetest.setting_getbool("creative_mode") then
|
||||
@ -362,6 +367,8 @@ function throwing.register_bow(name, def)
|
||||
elseif cooldown > 0 then
|
||||
meta:set_int("cooldown", os.time() + cooldown)
|
||||
end
|
||||
user:get_inventory():set_stack("main", user:get_wield_index(), itemstack)
|
||||
end)
|
||||
return itemstack
|
||||
end
|
||||
minetest.register_tool(name, def)
|
||||
|
Loading…
Reference in New Issue
Block a user