mirror of
https://github.com/minetest-mods/throwing.git
synced 2025-01-10 02:00:27 +01:00
Add a cooldown
This commit is contained in:
parent
5f94a6b27d
commit
1be6638b56
@ -22,6 +22,8 @@ throwing.vertical_acceleration = -10
|
|||||||
|
|
||||||
throwing.allow_arrow_placing = false
|
throwing.allow_arrow_placing = false
|
||||||
throwing.arrow_teleport_in_protected = true
|
throwing.arrow_teleport_in_protected = true
|
||||||
|
|
||||||
|
throwing.bow_cooldown = 0.2
|
||||||
```
|
```
|
||||||
|
|
||||||
## API
|
## API
|
||||||
@ -45,6 +47,7 @@ Definition: definition table, containing:
|
|||||||
* throw_itself (optional): whether the bow should throw itself instead of the arrow next to it in the inventory.
|
* throw_itself (optional): whether the bow should throw itself instead of the arrow next to it in the inventory.
|
||||||
If present, allow_shot is ignored.
|
If present, allow_shot is ignored.
|
||||||
Default is false.
|
Default is false.
|
||||||
|
* cooldown: bow cooldown. Default is setting throwing.bow_cooldown
|
||||||
]]
|
]]
|
||||||
|
|
||||||
-- Example:
|
-- Example:
|
||||||
|
22
init.lua
22
init.lua
@ -292,6 +292,8 @@ end
|
|||||||
|
|
||||||
|
|
||||||
---------- Bows -----------
|
---------- Bows -----------
|
||||||
|
local bow_cooldown = {}
|
||||||
|
|
||||||
function throwing.register_bow(name, def)
|
function throwing.register_bow(name, def)
|
||||||
if not string.find(name, ":") then
|
if not string.find(name, ":") then
|
||||||
name = throwing.modname..":"..name
|
name = throwing.modname..":"..name
|
||||||
@ -302,23 +304,39 @@ function throwing.register_bow(name, def)
|
|||||||
return throwing.is_arrow(itemstack)
|
return throwing.is_arrow(itemstack)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def.inventory_image = def.texture
|
if not def.inventory_image then
|
||||||
def.textre = nil
|
def.inventory_image = def.texture
|
||||||
|
end
|
||||||
def.on_use = function(itemstack, user, pointed_thing)
|
def.on_use = function(itemstack, user, pointed_thing)
|
||||||
|
-- Cooldown
|
||||||
|
local meta = itemstack:get_meta()
|
||||||
|
local cooldown = def.cooldown or tonumber(minetest.settings:get("throwing.bow_cooldown")) or 0.2
|
||||||
|
|
||||||
|
if cooldown > 0 and meta:get_int("cooldown") > os.time() then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Throw itself?
|
||||||
if not def.throw_itself and not def.allow_shot(user, user:get_inventory():get_stack("main", user:get_wield_index()+1)) then
|
if not def.throw_itself and not def.allow_shot(user, user:get_inventory():get_stack("main", user:get_wield_index()+1)) then
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Shoot arrow
|
||||||
if shoot_arrow(itemstack, user, def.throw_itself) then
|
if shoot_arrow(itemstack, user, def.throw_itself) then
|
||||||
if not minetest.setting_getbool("creative_mode") then
|
if not minetest.setting_getbool("creative_mode") then
|
||||||
itemstack:add_wear(65535 / (def.uses or 50))
|
itemstack:add_wear(65535 / (def.uses or 50))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
if def.throw_itself then
|
if def.throw_itself then
|
||||||
-- This is a bug. If we return ItemStack(nil), the player punches the entity,
|
-- This is a bug. If we return ItemStack(nil), the player punches the entity,
|
||||||
-- and if the entity if a __builtin:item, it gets back to his inventory.
|
-- and if the entity if a __builtin:item, it gets back to his inventory.
|
||||||
minetest.after(0.1, function()
|
minetest.after(0.1, function()
|
||||||
user:get_inventory():remove_item("main", itemstack)
|
user:get_inventory():remove_item("main", itemstack)
|
||||||
end)
|
end)
|
||||||
|
elseif cooldown > 0 then
|
||||||
|
meta:set_int("cooldown", os.time() + cooldown)
|
||||||
end
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user