2017-01-04 18:53:37 +01:00
|
|
|
# Throwing
|
|
|
|
|
|
|
|
## Developped by the Mynetest team
|
|
|
|
|
|
|
|
This mod is a new rewrite of the original throwing mod by PilzAdam. Compatible replacement for it.
|
|
|
|
|
|
|
|
## Configuration
|
|
|
|
|
2017-01-08 15:29:25 +01:00
|
|
|
The settings are the following:
|
2017-01-04 18:53:37 +01:00
|
|
|
```
|
|
|
|
throwing.enable_arrow = true
|
|
|
|
throwing.enable_golden_arrow = true
|
|
|
|
throwing.enable_fire_arrow = true
|
|
|
|
throwing.enable_teleport_arrow = true
|
|
|
|
throwing.enable_dig_arrow = true
|
|
|
|
throwing.enable_dig_arrow_admin = true
|
|
|
|
throwing.enable_build_arrow = true
|
2017-01-08 15:29:25 +01:00
|
|
|
|
|
|
|
throwing.velocity_factor = 19
|
|
|
|
throwing.horizontal_acceleration_factor = -3
|
|
|
|
throwing.vertical_acceleration = -10
|
2017-01-12 19:17:51 +01:00
|
|
|
|
|
|
|
throwing.allow_arrow_placing = false
|
2017-01-04 18:53:37 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
## API
|
|
|
|
|
|
|
|
There are two available functions in the mod API:
|
|
|
|
```lua
|
|
|
|
function throwing.register_bow(name, itemcraft, description, texture[, groups])
|
|
|
|
--[[
|
|
|
|
Name: Bow name (in second part of the itemstring).
|
|
|
|
Itemcraft: item used to craft the bow (nil if uncraftable).
|
|
|
|
Description: Description of the bow.
|
|
|
|
Texture: Texture of the bow, shown in inventory.
|
|
|
|
Groups: optional groups.
|
|
|
|
]]
|
|
|
|
|
|
|
|
-- Example:
|
|
|
|
throwing.register_bow("bow_stone", "default:cobble", "Stone Bow", "throwing_bow_stone.png")
|
|
|
|
|
|
|
|
|
2017-01-17 16:32:30 +01:00
|
|
|
function throwing.register_arrow(name, itemcraft, craft_quantity, description, tiles, on_hit_sound, on_hit[, on_throw[, groups]])
|
2017-01-04 18:53:37 +01:00
|
|
|
--[[
|
|
|
|
Name: Arrow name (in second part of the itemstring).
|
|
|
|
Itemcraft: item used to craft the arrow (nil if uncraftable).
|
|
|
|
Craft_quantity: quantity of arrows in the craft output.
|
|
|
|
Tiles: tiles of the arrow.
|
|
|
|
On_hit_sound: sound played when the arrow hits a node or an object (nil if no sound).
|
2017-01-17 16:32:30 +01:00
|
|
|
On_hit: callback function: on_hit(pos, last_pos, node, object, hitter, self) where:
|
2017-01-04 18:53:37 +01:00
|
|
|
* Pos: the position of the hitted node or object
|
|
|
|
* Last_pos: the last air node where the arrow was (used by the build_arrow, for example)
|
2017-01-17 16:32:30 +01:00
|
|
|
* Node and object: hit node or object. Either node or object is nil, depending
|
|
|
|
whether the arrow hit a node or an object (you should always check for that).
|
2017-01-04 18:53:37 +01:00
|
|
|
An object can be a player or a luaentity.
|
2017-01-17 16:32:30 +01:00
|
|
|
* Hitter: the ObjectRef of the player who threw the arrow.
|
|
|
|
* Self: the arrow entity table (it allows you to hack a lot!)
|
2017-01-12 20:49:42 +01:00
|
|
|
* When it fails, it should return:
|
|
|
|
false[, reason]
|
2017-01-17 16:32:30 +01:00
|
|
|
On_throw: option callback function: on_throw(pos, thrower, self) where:
|
|
|
|
* Pos: the position from where the arrow is throw (which a bit higher than the hitter position)
|
|
|
|
* Thrower: the ObjectRef of the thrower
|
|
|
|
* Self: the arrow entity table
|
|
|
|
* Should return false if the arrow should not be throw
|
2017-01-04 18:53:37 +01:00
|
|
|
]]
|
|
|
|
|
|
|
|
-- Examples:
|
|
|
|
throwing.register_arrow("arrow_gold", "default:gold_ingot", 16, "Golden Arrow",
|
|
|
|
{"throwing_arrow_gold.png", "throwing_arrow_gold.png", "throwing_arrow_gold_back.png", "throwing_arrow_gold_front.png", "throwing_arrow_gold_2.png", "throwing_arrow_gold.png"}, "throwing_arrow",
|
|
|
|
function(pos, last_pos, node, object, hitter)
|
|
|
|
if not object then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
object:punch(minetest.get_player_by_name(hitter), 1, {
|
|
|
|
full_punch_interval = 1,
|
|
|
|
damage_groups = {fleshy = 5}
|
|
|
|
})
|
|
|
|
end)
|
|
|
|
throwing.register_arrow("arrow_build", "default:obsidian_glass", 1, "Build Arrow",
|
|
|
|
{"throwing_arrow_build.png", "throwing_arrow_build.png", "throwing_arrow_build_back.png", "throwing_arrow_build_front.png", "throwing_arrow_build_2.png", "throwing_arrow_build.png"}, "throwing_build_arrow",
|
|
|
|
function(pos, last_pos, node, object, hitter)
|
|
|
|
if not node then
|
|
|
|
return
|
|
|
|
end
|
2017-01-12 20:49:42 +01:00
|
|
|
|
|
|
|
if minetest.is_protected(last_pos) then
|
|
|
|
return false, "Area is protected"
|
|
|
|
end
|
|
|
|
return minetest.place_node(last_pos, {name="default:obsidian_glass"})
|
2017-01-04 18:53:37 +01:00
|
|
|
end)
|
|
|
|
```
|