update spears mod

This commit is contained in:
crabman77 2015-11-25 22:20:20 +01:00
parent 339ce86020
commit 332fe79f89
3 changed files with 107 additions and 192 deletions

View File

@ -6,102 +6,8 @@ How to install:
http://wiki.minetest.com/wiki/Installing_Mods
How to use the mod:
Spear work similarly to other tools such as swords, even if being a little slower. Moreover, a spear can be thrown using the drop key ('Q') or
Spear work similarly to other tools such as swords, even if being a little slower. Moreover, a spear can be thrown using the drop key ('Q') or placed on a node using the place key ('right click'); they have also limited digging capabilities.
License:
This mod was originally published by Jeija and reworked by PilzAdam
Sourcecode: LGPLv2.1 (see http://www.gnu.org/licenses/lgpl-2.1.html)
Grahpics & sounds: CC-BY 3.0 (see http://creativecommons.org/licenses/by/3.0/legalcode)
Changelog:
Update 1.4.1:
- Fixed spears not retaining wear
- Improved textures
- Torch arrows have light trail
Update 1.4:
- Added spears, capable of melee and ranged attacks
- Improved arrows textures
Update 1.3:
- Added automated arbalest, the ultimate weapon
- New arbalest texture coherent with steel color
Update 1.2:
- Added arbalest
- Defaults initialized
Update 1.1:
- Added crossbow
- Code shrink
- Offensive arrows go through flora's and farming's
- Small fixes
Update 1.0:
- Definitive reload, unload and shot system based on tool metadata, new global functions, no more "throw" privilege
- New textures for loaded bows
- Fireworks arrows to celebrate!
Update 1.0rc2:
- Fixed "compare nil with number" due to self.break not being retained
- Filled conf.example's list
- Added Royal bow
Update 1.0rc1:
- Added longbow and removed golden bow, definitive bow set for stable release. Feature freeze
- Fixed torch arrow recipe, thanks to Excalibur Zero
- Removed config.lua, configuration now goes int throwing.config, see example
Update 0.9.8:
- New damage calculation for offensive arrows based on arrow's speed and material. Beware that dependency is more than linear for both, so that differences between arrows will be enhanced if they're shot at higher speed.
- Fixed bug that blocked ability to shot after shooting with empty arrow stack.
- Removed annoying debug symbols
Update 0.9.7:
- Added visual feedback for reload
- Fixed reload for players who die while reloading and for multiplayer
- Changed license for the code to LGPLv2
Update 0.9.6:
- Any bow and arrow is now deactivable under config.lua, which won't be overwritten
- Changed license for media to CC-BY
Update 0.9.5:
- Added shell arrows
- Revised sounds and some textures
- General balancing of bow's statistics
Update 0.9.4:
- New bow texture
- Made recipes coherent
Update 0.9.3:
- Added symmetric recipes, fixed golden bow recipe
- Adjusted few parameters
Update 0.9.2:
- Added a chance to break for many arrows, so they don't last forever and outclass any other tool
- Build and torch arrows won't build on fluids and torches any more, build arrows won't place torches
- TNT arrow digs instead if removing blocks, eventual indestructible nodes are safe
- Added golden bow with possible new bow style
- Changed the (bit OP) composite bow resistance and new recipe
- New teleport arrow recipe, cheaper but single use
Update 0.9.1:
- Good improvement for torch arrows, now they always attach and are often turned to the right direction
- Git repository will make things nicer
Update 0.9:
- Now bows have reload times! They depend on weight and quality, anyway no more machine-gun-style shell swarms
- Fixed build arrow behavior, now it placed and consumes the node from the slot [b]right next to the arrow[/b] or drops the item beside it if not a node; no more disappearing nor 'CONTENT_IGNORE' errors
- Code cleanup and rationalization
Update 0.8.1:
- Fixed wrong texture reference which made some arrows get a bad color during flight.
- Now bows have different stiffness besides wear resistances, which means that they shot arrows at different initial speed and learning to hit the target will become even harder.
Get rid of the old .env: API
Added new bows and new offensive, utility and harmful arrows (these are just my categories, they're not present into the code at all).
Removed stone bow, at least as long as somebody discovers an elastic rock ;)
Non-exploding arrows won't disappear any more after hitting target.
Grahpics & sounds: CC-BY 3.0 (see http://creativecommons.org/licenses/by/3.0/legalcode)

View File

@ -1,11 +1,13 @@
function spears_shot (itemstack, player)
local spear = itemstack:get_name() .. '_entity'
local playerpos = player:getpos()
local obj = minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, spear)
local dir = player:get_look_dir()
obj:setvelocity({x=dir.x*14, y=dir.y*14, z=dir.z*14})
obj:setacceleration({x=-dir.x*.5, y=-9.8, z=-dir.z*.5})
local sp = 14
local dr = .3
local gravity = 9.8
obj:setvelocity({x=dir.x*sp, y=dir.y*sp, z=dir.z*sp})
obj:setacceleration({x=-dir.x*dr, y=-gravity, z=-dir.z*dr})
obj:setyaw(player:get_look_yaw()+math.pi)
obj:get_luaentity().wear = itemstack:get_wear()
obj:get_luaentity().player = player:get_player_name()
@ -14,6 +16,98 @@ function spears_shot (itemstack, player)
return true
end
function spears_set_entity(kind, eq, toughness)
local SPEAR_ENTITY={
physical = false,
visual = "wielditem",
visual_size = {x=0.15, y=0.1},
textures = {"spears:spear_" .. kind},
lastpos={},
collisionbox = {0,0,0,0,0,0},
player = "",
wear = 0,
on_punch = function(self, puncher)
if puncher then
if puncher:is_player() then
local stack = {name='spears:spear_' .. kind, wear=self.wear+65535/toughness}
local inv = puncher:get_inventory()
if inv:room_for_item("main", stack) then
inv:add_item("main", stack)
self.object:remove()
end
end
end
end,
}
SPEAR_ENTITY.on_step = function(self, dtime)
local pos = self.object:getpos()
local node = minetest.get_node(pos)
if not self.wear then
self.object:remove()
return
end
local newpos = self.object:getpos()
if self.lastpos.x ~= nil then
for _, pos in pairs(spears_get_trajectoire(self, newpos)) do
local node = minetest.get_node(pos)
if node.name ~= "air"
and not string.find(node.name, 'water_')
and not (string.find(node.name, 'grass') and not string.find(node.name, 'dirt'))
and not (string.find(node.name, 'farming:') and not string.find(node.name, 'soil'))
and not string.find(node.name, 'flowers:')
and not string.find(node.name, 'fire:') then
if self.wear+65535/toughness < 65535 then
local spear_item = minetest.add_item(self.lastpos, {name='spears:spear_' .. kind, wear=self.wear+65535/toughness})
if spear_item then
spear_item:get_luaentity().item_drop_min_tstamp = minetest.get_us_time() + 3000000
end
end
self.object:remove()
return
end
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
for k, obj in pairs(objs) do
local objpos = obj:getpos()
if spears_is_player(self.player, obj) or spears_is_entity(obj) then
if spears_touch(pos, objpos) then
local puncher = self.object
if self.player and minetest.get_player_by_name(self.player) then
puncher = minetest.get_player_by_name(self.player)
end
--local speed = vector.length(self.object:getvelocity()) --MFF crabman(28/09/2015) damage valeur equal eq
local damage = eq --((speed + eq +5)^1.2)/10 --MFF crabman(28/09/2015) damage valeur equal eq
obj:punch(puncher, 1.0, {
full_punch_interval=1.0,
damage_groups={fleshy=damage},
}, nil)
if self.wear+65535/toughness < 65535 then
local spear_item = minetest.add_item(self.lastpos, {name='spears:spear_' .. kind, wear=self.wear+65535/toughness})
if spear_item then
spear_item:get_luaentity().item_drop_min_tstamp = minetest.get_us_time() + 3000000
end
end
self.object:remove()
return
end
end
end
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
end
end
self.lastpos={x=newpos.x, y=newpos.y, z=newpos.z}
end
return SPEAR_ENTITY
end
function spears_is_player(name, obj)
return (obj:is_player() and obj:get_player_name() ~= name)
end
@ -26,6 +120,8 @@ function spears_is_entity(obj)
and obj:get_luaentity().name ~= "signs:text")
end
function spears_get_trajectoire(self, newpos)
if self.lastpos.x == nil then
return {newpos}

View File

@ -1,10 +1,9 @@
function spears_register_spear(kind, desc, eq, toughness, craft)
function spears_register_spear(kind, desc, eq, toughness, material)
minetest.register_tool("spears:spear_" .. kind, {
description = desc .. " spear",
inventory_image = "spears_spear_" .. kind .. ".png",
wield_scale= {x=2,y=1,z=1},
on_drop = function(itemstack, user, pointed_thing)
spears_shot(itemstack, user)
if not minetest.setting_getbool("creative_mode") then
@ -22,108 +21,22 @@ function spears_register_spear(kind, desc, eq, toughness, craft)
}
})
--minetest.register_node("spears:spear_" .. kind .. "_box", {
--drawtype = "nodebox",
--node_box = {
--type = "fixed",
--fixed = {
---- Shaft
--{-60/16, -2/16, 2/16, 4, 1/16, -1/16},
----Spitze
--{-4, -1/16, 1/16, -62/16, 0, 0},
--{-62/16, -1.5/16, 1.5/16, -60/16, 0.5/16, -0.5/16},
--}
--},
--tiles = {"spears_spear_box.png"},
--groups = {not_in_creative_inventory=1},
--})
local SPEAR_ENTITY={
physical = false,
visual = "wielditem",
visual_size = {x=0.15, y=0.1},
textures = {"spears:spear_" .. kind},
lastpos={},
collisionbox = {0,0,0,0,0,0},
player = "",
wear = 0,
on_punch = function(self, puncher)
if puncher then
if puncher:is_player() then
local stack = {name='spears:spear_' .. kind, wear=self.wear+65535/toughness}
local inv = puncher:get_inventory()
if inv:room_for_item("main", stack) then
inv:add_item("main", stack)
self.object:remove()
end
end
end
end,
}
SPEAR_ENTITY.on_step = function(self, dtime)
local pos = self.object:getpos()
local node = minetest.get_node(pos)
if not self.wear then
self.object:remove()
return
end
local newpos = self.object:getpos()
if self.lastpos.x ~= nil then
for _, pos in pairs(spears_get_trajectoire(self, newpos)) do
local node = minetest.get_node(pos)
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
for k, obj in pairs(objs) do
local objpos = obj:getpos()
if spears_is_player(self.player, obj) or spears_is_entity(obj) then
if spears_touch(pos, objpos) then
local puncher = self.object
if self.player and minetest.get_player_by_name(self.player) then
puncher = minetest.get_player_by_name(self.player)
end
--local speed = vector.length(self.object:getvelocity()) --MFF crabman(28/09/2015) damage valeur equal eq
local damage = eq --((speed + eq +5)^1.2)/10 --MFF crabman(28/09/2015) damage valeur equal eq
obj:punch(puncher, 1.0, {
full_punch_interval=1.0,
damage_groups={fleshy=damage},
}, nil)
minetest.add_item(self.lastpos, {name='spears:spear_' .. kind, wear=self.wear+65535/toughness})
self.object:remove()
return
end
end
end
if node.name ~= "air"
and not string.find(node.name, 'water_')
and not (string.find(node.name, 'grass') and not string.find(node.name, 'dirt'))
and not (string.find(node.name, 'farming:') and not string.find(node.name, 'soil'))
and not string.find(node.name, 'flowers:')
and not string.find(node.name, 'fire:') then
minetest.add_item(self.lastpos, {name='spears:spear_' .. kind, wear=self.wear+65535/toughness})
self.object:remove()
return
end
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
end
end
self.lastpos={x=newpos.x, y=newpos.y, z=newpos.z}
end
local SPEAR_ENTITY=spears_set_entity(kind, eq, toughness)
minetest.register_entity("spears:spear_" .. kind .. "_entity", SPEAR_ENTITY)
minetest.register_craft({
output = 'spears:spear_' .. kind .. ' 4',
output = 'spears:spear_' .. kind,
recipe = {
{'group:wood', 'group:wood', craft},
{'group:wood', 'group:wood', material},
}
})
minetest.register_craft({
output = 'spears:spear_' .. kind .. ' 4',
output = 'spears:spear_' .. kind,
recipe = {
{craft, 'group:wood', 'group:wood'},
{material, 'group:wood', 'group:wood'},
}
})
end