4 Commits
master ... v1.1

Author SHA1 Message Date
3c174db494 Update 1.1 2020-04-18 15:31:17 +02:00
00d86908d8 spears.conf example 2016-01-06 22:40:30 +01:00
5a214d3b44 1.0 rebalance 2016-01-06 22:25:23 +01:00
2c0ebde983 beta1 2016-01-06 22:05:49 +01:00
16 changed files with 57 additions and 129 deletions

0
README.txt Executable file → Normal file
View File

3
defaults.lua Executable file → Normal file
View File

@ -1,5 +1,6 @@
DISABLE_STONE_SPEAR = false
DISABLE_STEEL_SPEAR = false
DISABLE_COPPER_SPEAR = false
DISABLE_BRONZE_SPEAR = false
DISABLE_DIAMOND_SPEAR = false
DISABLE_OBSIDIAN_SPEAR = false
DISABLE_MITHRIL_SPEAR = false

0
depends.txt Executable file → Normal file
View File

122
functions.lua Executable file → Normal file
View File

@ -3,35 +3,30 @@ function spears_shot (itemstack, player)
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()
local sp = 14
local sp = 16
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()
obj:get_luaentity().lastpos = {x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}
minetest.sound_play("spears_sound", {pos=playerpos})
obj:get_luaentity().wear = itemstack:get_wear()
return true
end
function spears_set_entity(kind, eq, toughness)
function spears_set_entity(spear_type, base_damage, toughness)
local SPEAR_ENTITY={
physical = false,
timer=0,
visual = "wielditem",
visual_size = {x=0.15, y=0.1},
textures = {"spears:spear_" .. kind},
textures = {"spears:spear_" .. spear_type},
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 stack = {name='spears:spear_' .. spear_type, wear=self.wear+65535/toughness}
local inv = puncher:get_inventory()
if inv:room_for_item("main", stack) then
inv:add_item("main", stack)
@ -41,111 +36,42 @@ function spears_set_entity(kind, eq, toughness)
end
end,
}
SPEAR_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+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
if self.lastpos.x~=nil then
if node.name ~= "air" and not (string.find(node.name, 'grass') and not string.find(node.name, 'dirt')) and not string.find(node.name, 'flowers:') and not string.find(node.name, 'farming:') then
self.object:remove()
if self.wear+65535/toughness < 65535 then
minetest.add_item(self.lastpos, {name='spears:spear_' .. spear_type, wear=self.wear+65535/toughness})
end
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
elseif self.timer>0.2 then
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1)
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, {
if obj:get_luaentity() ~= nil then
if obj:get_luaentity().name ~= "spears:spear_" .. spear_type .. "_entity" and obj:get_luaentity().name ~= "_builtin:item" then
local speed = vector.length(self.object:getvelocity())
local damage = (speed + base_damage)^1.12-20
obj:punch(self.object, 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
if self.wear+65535/toughness < 65535 then
minetest.add_item(self.lastpos, {name='spears:spear_' .. spear_type, wear=self.wear+65535/toughness})
end
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}
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
end
return SPEAR_ENTITY
end
function spears_is_player(name, obj)
return (obj:is_player() and obj:get_player_name() ~= name)
end
function spears_is_entity(obj)
return (obj:get_luaentity() ~= nil
and not string.find(obj:get_luaentity().name, "spears:")
and obj:get_luaentity().name ~= "__builtin:item"
and obj:get_luaentity().name ~= "gauges:hp_bar"
and obj:get_luaentity().name ~= "signs:text")
end
function spears_get_trajectoire(self, newpos)
if self.lastpos.x == nil then
return {newpos}
end
local coord = {}
local nx = (newpos["x"] - self.lastpos["x"])/3
local ny = (newpos["y"] - self.lastpos["y"])/3
local nz = (newpos["z"] - self.lastpos["z"])/3
if nx and ny and nz then
table.insert(coord, {x=self.lastpos["x"]+nx, y=self.lastpos["y"]+ny ,z=self.lastpos["z"]+nz })
table.insert(coord, {x=newpos["x"]-nx, y=newpos["y"]-ny ,z=newpos["z"]-nz })
end
table.insert(coord, newpos)
return coord
end
function spears_touch(pos, objpos)
local rx = pos.x - objpos.x
local ry = pos.y - (objpos.y+1)
local rz = pos.z - objpos.z
if (ry < 1 and ry > -1) and (rx < 0.4 and rx > -0.4) and (rz < 0.4 and rz > -0.4) then
return true
end
return false
end

8
init.lua Executable file → Normal file
View File

@ -15,11 +15,3 @@ dofile(minetest.get_modpath("spears").."/tools.lua")
if minetest.setting_get("log_mods") then
minetest.log("action", "spears loaded")
end
--alias
minetest.register_alias("throwing:spear_stone", "spears:spear_stone")
minetest.register_alias("throwing:spear_steel", "spears:spear_steel")
minetest.register_alias("throwing:spear_diamond", "spears:spear_diamond")
minetest.register_alias("throwing:spear_obsidian", "spears:spear_obsidian")
minetest.register_alias("throwing:spear_mithril", "spears:spear_mithril")

BIN
screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 KiB

BIN
sounds/spears_sound.ogg Executable file → Normal file

Binary file not shown.

6
spears.conf.example Normal file
View File

@ -0,0 +1,6 @@
DISABLE_STONE_SPEAR = true
DISABLE_STEEL_SPEAR = true
DISABLE_COPPER_SPEAR = true
DISABLE_BRONZE_SPEAR = true
DISABLE_DIAMOND_SPEAR = true
DISABLE_OBSIDIAN_SPEAR = true

Binary file not shown.

After

Width:  |  Height:  |  Size: 247 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 197 B

After

Width:  |  Height:  |  Size: 272 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 185 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 167 B

After

Width:  |  Height:  |  Size: 276 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 192 B

After

Width:  |  Height:  |  Size: 273 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 192 B

After

Width:  |  Height:  |  Size: 277 B

47
tools.lua Executable file → Normal file
View File

@ -1,10 +1,11 @@
function spears_register_spear(kind, desc, eq, toughness, material)
function spears_register_spear(spear_type, desc, base_damage, toughness, material)
minetest.register_tool("spears:spear_" .. kind, {
minetest.register_tool("spears:spear_" .. spear_type, {
description = desc .. " spear",
inventory_image = "spears_spear_" .. kind .. ".png",
wield_image = "spears_spear_" .. spear_type .. ".png",
inventory_image = "spears_spear_" .. spear_type .. ".png^[transform4",
wield_scale= {x=2,y=1,z=1},
on_drop = function(itemstack, user, pointed_thing)
on_secondary_use = function(itemstack, user, pointed_thing)
spears_shot(itemstack, user)
if not minetest.setting_getbool("creative_mode") then
itemstack:take_item()
@ -17,24 +18,23 @@ function spears_register_spear(kind, desc, eq, toughness, material)
groupcaps={
cracky = {times={[3]=2}, uses=toughness, maxlevel=1},
},
damage_groups = {fleshy=eq},
damage_groups = {fleshy=base_damage},
}
})
local SPEAR_ENTITY=spears_set_entity(kind, eq, toughness)
minetest.register_entity("spears:spear_" .. kind .. "_entity", SPEAR_ENTITY)
local SPEAR_ENTITY=spears_set_entity(spear_type, base_damage, toughness)
minetest.register_entity("spears:spear_" .. spear_type .. "_entity", SPEAR_ENTITY)
minetest.register_craft({
output = 'spears:spear_' .. kind,
output = 'spears:spear_' .. spear_type,
recipe = {
{'group:wood', 'group:wood', material},
}
})
minetest.register_craft({
output = 'spears:spear_' .. kind,
output = 'spears:spear_' .. spear_type,
recipe = {
{material, 'group:wood', 'group:wood'},
}
@ -42,22 +42,25 @@ function spears_register_spear(kind, desc, eq, toughness, material)
end
if not DISABLE_STONE_SPEAR then
spears_register_spear('stone', 'Stone (Hunter)', 3, 25, 'group:stone') --MFF crabman(28/09/2015) damage and wear
spears_register_spear('stone', 'Stone', 4, 20, 'group:stone')
end
if not DISABLE_STEEL_SPEAR then
spears_register_spear('steel', 'Steel (Hunter)', 4, 30, 'default:steel_ingot') --MFF crabman(28/09/2015) damage and wear
spears_register_spear('steel', 'Steel', 6, 30, 'default:steel_ingot')
end
if not DISABLE_DIAMOND_SPEAR then
spears_register_spear('diamond', 'Diamond (Hunter)', 7, 50, 'default:diamond') --MFF crabman(28/09/2015) damage and wear
if not DISABLE_COPPER_SPEAR then
spears_register_spear('copper', 'Copper', 5, 35, 'default:copper_ingot')
end
if not DISABLE_BRONZE_SPEAR then
spears_register_spear('bronze', 'Bronze', 6, 35, 'default:bronze_ingot')
end
if not DISABLE_OBSIDIAN_SPEAR then
spears_register_spear('obsidian', 'Obsidian (Hunter)', 5, 40, 'default:obsidian') --MFF crabman(28/09/2015) damage and wear
spears_register_spear('obsidian', 'Obsidian', 8, 30, 'default:obsidian')
end
if not DISABLE_MITHRIL_SPEAR then
spears_register_spear('mithril', 'Mithril (Hunter)', 8, 200, 'default:mithril_ingot') --MFF crabman(28/09/2015) damage and wear
if not DISABLE_DIAMOND_SPEAR then
spears_register_spear('diamond', 'Diamond', 8, 40, 'default:diamond')
end