1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-12-24 01:30:38 +01:00

improve/debug throwing mod

This commit is contained in:
crabman77 2015-07-31 03:53:31 +02:00
parent 678715707e
commit 0edff51305
6 changed files with 186 additions and 162 deletions

View File

@ -45,50 +45,52 @@ local THROWING_ARROW_ENTITY={
THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime
local pos = self.object:getpos()
local node = minetest.get_node(pos)
if 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
if obj:get_luaentity() ~= nil then
if obj:get_luaentity().name ~= "throwing:arrow_build_entity" and obj:get_luaentity().name ~= "__builtin:item" then
if self.inventory and self.stack and not minetest.setting_getbool("creative_mode") then
self.inventory:remove_item("main", {name=self.stack:get_name()})
local newpos = self.object:getpos()
for _, pos in pairs(get_trajectoire(self, newpos)) do
local node = minetest.get_node(pos)
if 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
if obj:get_luaentity() ~= nil then
if obj:get_luaentity().name ~= "throwing:arrow_build_entity" and obj:get_luaentity().name ~= "__builtin:item" then
if self.inventory and self.stack and not minetest.setting_getbool("creative_mode") then
self.inventory:remove_item("main", {name=self.stack:get_name()})
end
if self.stack then
minetest.add_item(pos, {name=self.stack:get_name()})
end
local toughness = 0.95
if math.random() < toughness then
minetest.add_item(pos, 'throwing:arrow_build')
else
minetest.add_item(pos, 'default:stick')
end
self.object:remove()
return
end
if self.stack then
end
end
end
if self.lastpos.x~= nil then
if node.name ~= "air" then
if self.inventory and self.stack and not minetest.setting_getbool("creative_mode") then
self.inventory:remove_item("main", {name=self.stack:get_name()})
end
if self.stack then
if not minetest.is_protected(self.lastpos, self.player) and not string.find(node.name, "water_") and not string.find(node.name, "lava") and not string.find(node.name, "torch") and self.stack:get_definition().type == "node" and self.stack:get_name() ~= "default:torch" then
minetest.place_node(self.lastpos, {name=self.stack:get_name()})
else
minetest.add_item(self.lastpos, {name=self.stack:get_name()})
end
local toughness = 0.95
if math.random() < toughness then
minetest.add_item(self.lastpos, 'throwing:arrow_build')
else
minetest.add_item(self.lastpos, 'default:stick')
end
self.object:remove()
return
end
minetest.add_item(self.lastpos, 'default:shovel_steel')
self.object:remove()
return
end
end
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
end
if self.lastpos.x~=nil then
if node.name ~= "air" then
if self.inventory and self.stack and not minetest.setting_getbool("creative_mode") then
self.inventory:remove_item("main", {name=self.stack:get_name()})
end
if self.stack then
if not minetest.is_protected(self.lastpos, self.player) and not string.find(node.name, "water") and not string.find(node.name, "lava") and not string.find(node.name, "torch") and self.stack:get_definition().type == "node" and self.stack:get_name() ~= "default:torch" then
minetest.place_node(self.lastpos, {name=self.stack:get_name()})
else
minetest.add_item(self.lastpos, {name=self.stack:get_name()})
end
end
minetest.add_item(self.lastpos, 'default:shovel_steel')
self.object:remove()
end
end
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
self.lastpos={x=newpos.x, y=newpos.y, z=newpos.z}
end
minetest.register_entity("throwing:arrow_build_entity", THROWING_ARROW_ENTITY)

View File

@ -40,45 +40,43 @@ local THROWING_ARROW_ENTITY={
player = "",
}
THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime
local pos = self.object:getpos()
local node = minetest.get_node(pos)
if 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
if obj:get_luaentity() ~= nil then
if obj:get_luaentity().name ~= "throwing:arrow_dig_entity" and obj:get_luaentity().name ~= "__builtin:item" then
local damage = 1.5
obj:punch(self.object, 1.0, {
full_punch_interval=1.0,
damage_groups={fleshy=damage},
}, nil)
if math.random(0,100) % 2 == 0 then -- 50% of chance to drop //MFF (Mg|07/27/15)
minetest.add_item(self.lastpos, "throwing:arrow_dig")
local newpos = self.object:getpos()
for _, pos in pairs(get_trajectoire(self, newpos)) do
local node = minetest.get_node(pos)
if 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
if obj:get_luaentity() ~= nil then
if obj:get_luaentity().name ~= "throwing:arrow_dig_entity" and obj:get_luaentity().name ~= "__builtin:item" then
local damage = 1.5
obj:punch(self.object, 1.0, {
full_punch_interval=1.0,
damage_groups={fleshy=damage},
}, nil)
if math.random(0,100) % 2 == 0 then -- 50% of chance to drop //MFF (Mg|07/27/15)
minetest.add_item(pos, "throwing:arrow_dig")
end
self.object:remove()
return
end
self.object:remove()
return
end
end
end
end
if self.lastpos.x~=nil then
if node.name ~= "air" and not string.find(node.name, "water") then
if node.name ~= "air" and not string.find(node.name, "water_") then
if node.name ~= "ignore" and minetest.get_item_group(node.name, "unbreakable") == 0
and not minetest.is_protected(self.lastpos, self.player)
and node.diggable ~= false
and areas:canInteract(pos, "") then
and not minetest.is_protected(pos, self.player)
and node.diggable ~= false then
minetest.set_node(pos, {name = "air"})
minetest.add_item(self.lastpos, node.name)
minetest.add_item(pos, node.name)
end
self.object:remove()
return
end
end
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
self.lastpos={x=newpos.x, y=newpos.y, z=newpos.z}
end
minetest.register_entity("throwing:arrow_dig_entity", THROWING_ARROW_ENTITY)

View File

@ -42,45 +42,47 @@ local THROWING_ARROW_ENTITY={
THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime
local pos = self.object:getpos()
local node = minetest.get_node(pos)
local newpos = self.object:getpos()
for _, pos in pairs(get_trajectoire(self, newpos)) do
local node = minetest.get_node(pos)
if self.timer>0.2 then
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
for k, obj in pairs(objs) do
if obj:get_luaentity() ~= nil then
if obj:get_luaentity().name ~= "throwing:arrow_fire_entity" and obj:get_luaentity().name ~= "__builtin:item" then
local damage = 4
obj:punch(self.object, 1.0, {
full_punch_interval=1.0,
damage_groups={fleshy=damage},
}, nil)
if math.random(0,100) % 2 == 0 then -- 50% of chance to drop //MFF (Mg|07/27/15)
minetest.add_item(self.lastpos, 'default:stick')
if self.timer>0.2 then
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
for k, obj in pairs(objs) do
if obj:get_luaentity() ~= nil then
if obj:get_luaentity().name ~= "throwing:arrow_fire_entity" and obj:get_luaentity().name ~= "__builtin:item" then
local damage = 4
obj:punch(self.object, 1.0, {
full_punch_interval=1.0,
damage_groups={fleshy=damage},
}, nil)
if math.random(0,100) % 2 == 0 then -- 50% of chance to drop //MFF (Mg|07/27/15)
minetest.add_item(pos, 'default:stick')
end
self.object:remove()
return
end
self.object:remove()
return
end
end
end
if self.lastpos.x~=nil then
if node.name ~= "air" and node.name ~= "throwing:light" then
minetest.set_node(self.lastpos, {name="fire:basic_flame"})
self.object:remove()
return
end
if math.floor(self.lastpos.x+0.5) ~= math.floor(pos.x+0.5) or math.floor(self.lastpos.y+0.5) ~= math.floor(pos.y+0.5) or math.floor(self.lastpos.z+0.5) ~= math.floor(pos.z+0.5) then
if minetest.get_node(self.lastpos).name == "throwing:light" then
minetest.remove_node(self.lastpos)
end
if minetest.get_node(pos).name == "air" then
minetest.set_node(pos, {name="throwing:light"})
end
end
end
end
if self.lastpos.x~=nil then
if node.name ~= "air" and node.name ~= "throwing:light" then
minetest.set_node(self.lastpos, {name="fire:basic_flame"})
self.object:remove()
return
end
if math.floor(self.lastpos.x+0.5) ~= math.floor(pos.x+0.5) or math.floor(self.lastpos.y+0.5) ~= math.floor(pos.y+0.5) or math.floor(self.lastpos.z+0.5) ~= math.floor(pos.z+0.5) then
if minetest.get_node(self.lastpos).name == "throwing:light" then
minetest.remove_node(self.lastpos)
end
if minetest.get_node(pos).name == "air" then
minetest.set_node(pos, {name="throwing:light"})
end
end
end
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
self.lastpos={x=newpos.x, y=newpos.y, z=newpos.z}
end
minetest.register_entity("throwing:arrow_fire_entity", THROWING_ARROW_ENTITY)

View File

@ -16,6 +16,24 @@ minetest.register_on_leaveplayer(function(player)
players[playerName] = nil
end)
function get_trajectoire(self, newpos)
if self.lastpos.x == nil then
return {newpos}
end
local coord = {}
local nx = (self.lastpos["x"] - newpos["x"])/3
local ny = (self.lastpos["y"] - newpos["y"])/3
local nz = (self.lastpos["z"] - newpos["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 throwing_shoot_arrow (itemstack, player, stiffness, is_cross)
if not player then return end
local arrow = itemstack:get_metadata()

View File

@ -44,45 +44,46 @@ function throwing_register_arrow_standard (kind, desc, eq, toughness, craft)
THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime
local pos = self.object:getpos()
local node = minetest.get_node(pos)
if self.timer>0.2 then
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
for k, obj in pairs(objs) do
if obj:get_luaentity() ~= nil then
if obj:get_luaentity().name ~= "throwing:arrow_" .. kind .. "_entity" and obj:get_luaentity().name ~= "__builtin:item" then
obj:punch(self.object, 1.0, {
full_punch_interval=1.0,
damage_groups={fleshy=eq},
}, nil)
if math.random() < toughness then
if math.random(0,100) % 2 == 0 then
minetest.add_item(self.lastpos, 'throwing:arrow_' .. kind)
local newpos = self.object:getpos()
for _, pos in pairs(get_trajectoire(self, newpos)) do
local node = minetest.get_node(pos)
if self.timer>0.2 then
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
for k, obj in pairs(objs) do
if obj:get_luaentity() ~= nil then
if obj:get_luaentity().name ~= "throwing:arrow_" .. kind .. "_entity" and obj:get_luaentity().name ~= "__builtin:item" then
obj:punch(self.object, 1.0, {
full_punch_interval=1.0,
damage_groups={fleshy=eq},
}, nil)
if math.random() < toughness then
if math.random(0,100) % 2 == 0 then
minetest.add_item(pos, 'throwing:arrow_' .. kind)
end
else
minetest.add_item(pos, 'default:stick')
end
else
minetest.add_item(self.lastpos, 'default:stick')
self.object:remove()
return
end
self.object:remove()
return
end
end
end
end
if self.lastpos.x~=nil then
if node.name ~= "air" and not string.find(node.name, 'water') and not string.find(node.name, 'default:grass') and not string.find(node.name, 'default:junglegrass')
if node.name ~= "air" and not string.find(node.name, 'water_') and not string.find(node.name, 'default:grass') and not string.find(node.name, 'default:junglegrass')
and not string.find(node.name, 'flowers:') and not string.find(node.name, 'farming:') then
if math.random() < toughness then
minetest.add_item(self.lastpos, 'throwing:arrow_' .. kind)
minetest.add_item(pos, 'throwing:arrow_' .. kind)
else
minetest.add_item(self.lastpos, 'default:stick')
minetest.add_item(pos, 'default:stick')
end
self.object:remove()
return
end
end
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
self.lastpos={x=newpos.x, y=newpos.y, z=newpos.z}
end
minetest.register_entity("throwing:arrow_" .. kind .. "_entity", THROWING_ARROW_ENTITY)

View File

@ -43,57 +43,60 @@ local THROWING_ARROW_ENTITY={
THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime
local pos = self.object:getpos()
local node = minetest.get_node(pos)
local newpos = self.object:getpos()
for _, pos in pairs(get_trajectoire(self, newpos)) do
local node = minetest.get_node(pos)
if self.timer>0.2 then
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 0.5)
for k, obj in pairs(objs) do
if obj:get_luaentity() ~= nil then
if obj:get_luaentity().name ~= "throwing:arrow_torch_entity" and obj:get_luaentity().name ~= "__builtin:item" then
local damage = 0.5
obj:punch(self.object, 1.0, {
full_punch_interval=1.0,
damage_groups={fleshy=damage},
}, nil)
if self.timer>0.2 then
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 0.5)
for k, obj in pairs(objs) do
if obj:get_luaentity() ~= nil then
if obj:get_luaentity().name ~= "throwing:arrow_torch_entity" and obj:get_luaentity().name ~= "__builtin:item" then
local damage = 0.5
obj:punch(self.object, 1.0, {
full_punch_interval=1.0,
damage_groups={fleshy=damage},
}, nil)
local toughness = 0.9
if math.random() < toughness then
if math.random(0,100) % 2 == 0 then -- 50% of chance to drop //MFF (Mg|07/27/15)
minetest.add_item(pos, 'throwing:arrow_torch')
end
else
minetest.add_item(pos, 'default:stick')
end
self.object:remove()
return
end
end
end
end
if self.lastpos.x~= nil then
if node.name ~= "air" then
local player = minetest.get_player_by_name(self.player)
if not player then self.object:remove() return end
if not string.find(node.name, "water_") and not string.find(node.name, "lava")
and not string.find(node.name, "torch") and minetest.get_item_group(node.name, "unbreakable") == 0
and not minetest.is_protected(self.lastpos, self.player) and node.diggable ~= false then
local dir=vector.direction(self.lastpos, pos)
local wall=minetest.dir_to_wallmounted(dir)
minetest.add_node(self.lastpos, {name="default:torch", param2 = wall})
else
local toughness = 0.9
if math.random() < toughness then
if math.random(0,100) % 2 == 0 then -- 50% of chance to drop //MFF (Mg|07/27/15)
minetest.add_item(self.lastpos, 'throwing:arrow_torch')
end
minetest.add_item(self.lastpos, 'throwing:arrow_torch')
else
minetest.add_item(self.lastpos, 'default:stick')
end
self.object:remove()
return
end
self.object:remove()
return
end
end
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
end
if self.lastpos.x~=nil then
if node.name ~= "air" then
local player = minetest.get_player_by_name(self.player)
if not player then self.object:remove() return end
if not string.find(node.name, "water") and not string.find(node.name, "lava")
and not string.find(node.name, "torch") and minetest.get_item_group(node.name, "unbreakable") == 0
and not minetest.is_protected(self.lastpos, self.player) and node.diggable ~= false then
local dir=vector.direction(self.lastpos, pos)
local wall=minetest.dir_to_wallmounted(dir)
minetest.add_node(self.lastpos, {name="default:torch", param2 = wall})
else
local toughness = 0.9
if math.random() < toughness then
minetest.add_item(self.lastpos, 'throwing:arrow_torch')
else
minetest.add_item(self.lastpos, 'default:stick')
end
end
self.object:remove()
return
end
end
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
self.lastpos={x=newpos.x, y=newpos.y, z=newpos.z}
end
minetest.register_entity("throwing:arrow_torch_entity", THROWING_ARROW_ENTITY)