1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2025-01-12 02:50:25 +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,9 +45,9 @@ local THROWING_ARROW_ENTITY={
THROWING_ARROW_ENTITY.on_step = function(self, dtime) THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime self.timer=self.timer+dtime
local pos = self.object:getpos() local newpos = self.object:getpos()
for _, pos in pairs(get_trajectoire(self, newpos)) do
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
if self.timer>0.2 then if self.timer>0.2 then
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1) local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1)
for k, obj in pairs(objs) do for k, obj in pairs(objs) do
@ -57,13 +57,13 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.inventory:remove_item("main", {name=self.stack:get_name()}) self.inventory:remove_item("main", {name=self.stack:get_name()})
end end
if self.stack then if self.stack then
minetest.add_item(self.lastpos, {name=self.stack:get_name()}) minetest.add_item(pos, {name=self.stack:get_name()})
end end
local toughness = 0.95 local toughness = 0.95
if math.random() < toughness then if math.random() < toughness then
minetest.add_item(self.lastpos, 'throwing:arrow_build') minetest.add_item(pos, 'throwing:arrow_build')
else else
minetest.add_item(self.lastpos, 'default:stick') minetest.add_item(pos, 'default:stick')
end end
self.object:remove() self.object:remove()
return return
@ -71,14 +71,13 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
end end
end end
end end
if self.lastpos.x~= nil then if self.lastpos.x~= nil then
if node.name ~= "air" then if node.name ~= "air" then
if self.inventory and self.stack and not minetest.setting_getbool("creative_mode") 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()}) self.inventory:remove_item("main", {name=self.stack:get_name()})
end end
if self.stack then 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 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()}) minetest.place_node(self.lastpos, {name=self.stack:get_name()})
else else
minetest.add_item(self.lastpos, {name=self.stack:get_name()}) minetest.add_item(self.lastpos, {name=self.stack:get_name()})
@ -86,10 +85,13 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
end end
minetest.add_item(self.lastpos, 'default:shovel_steel') minetest.add_item(self.lastpos, 'default:shovel_steel')
self.object:remove() self.object:remove()
return
end end
end end
self.lastpos={x=pos.x, y=pos.y, z=pos.z} 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
minetest.register_entity("throwing:arrow_build_entity", THROWING_ARROW_ENTITY) minetest.register_entity("throwing:arrow_build_entity", THROWING_ARROW_ENTITY)

View File

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

View File

@ -42,7 +42,8 @@ local THROWING_ARROW_ENTITY={
THROWING_ARROW_ENTITY.on_step = function(self, dtime) THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime self.timer=self.timer+dtime
local pos = self.object:getpos() local newpos = self.object:getpos()
for _, pos in pairs(get_trajectoire(self, newpos)) do
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
if self.timer>0.2 then if self.timer>0.2 then
@ -56,7 +57,7 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
damage_groups={fleshy=damage}, damage_groups={fleshy=damage},
}, nil) }, nil)
if math.random(0,100) % 2 == 0 then -- 50% of chance to drop //MFF (Mg|07/27/15) 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') minetest.add_item(pos, 'default:stick')
end end
self.object:remove() self.object:remove()
return return
@ -80,7 +81,8 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
end end
end end
end end
self.lastpos={x=pos.x, y=pos.y, z=pos.z} end
self.lastpos={x=newpos.x, y=newpos.y, z=newpos.z}
end end
minetest.register_entity("throwing:arrow_fire_entity", THROWING_ARROW_ENTITY) 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 players[playerName] = nil
end) 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) function throwing_shoot_arrow (itemstack, player, stiffness, is_cross)
if not player then return end if not player then return end
local arrow = itemstack:get_metadata() local arrow = itemstack:get_metadata()

View File

@ -44,7 +44,8 @@ function throwing_register_arrow_standard (kind, desc, eq, toughness, craft)
THROWING_ARROW_ENTITY.on_step = function(self, dtime) THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime self.timer=self.timer+dtime
local pos = self.object:getpos() local newpos = self.object:getpos()
for _, pos in pairs(get_trajectoire(self, newpos)) do
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
if self.timer>0.2 then if self.timer>0.2 then
@ -58,10 +59,10 @@ function throwing_register_arrow_standard (kind, desc, eq, toughness, craft)
}, nil) }, nil)
if math.random() < toughness then if math.random() < toughness then
if math.random(0,100) % 2 == 0 then if math.random(0,100) % 2 == 0 then
minetest.add_item(self.lastpos, 'throwing:arrow_' .. kind) minetest.add_item(pos, 'throwing:arrow_' .. kind)
end end
else else
minetest.add_item(self.lastpos, 'default:stick') minetest.add_item(pos, 'default:stick')
end end
self.object:remove() self.object:remove()
return return
@ -70,19 +71,19 @@ function throwing_register_arrow_standard (kind, desc, eq, toughness, craft)
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 and not string.find(node.name, 'flowers:') and not string.find(node.name, 'farming:') then
if math.random() < toughness then if math.random() < toughness then
minetest.add_item(self.lastpos, 'throwing:arrow_' .. kind) minetest.add_item(pos, 'throwing:arrow_' .. kind)
else else
minetest.add_item(self.lastpos, 'default:stick') minetest.add_item(pos, 'default:stick')
end end
self.object:remove() self.object:remove()
return return
end 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 end
minetest.register_entity("throwing:arrow_" .. kind .. "_entity", THROWING_ARROW_ENTITY) minetest.register_entity("throwing:arrow_" .. kind .. "_entity", THROWING_ARROW_ENTITY)

View File

@ -43,7 +43,8 @@ local THROWING_ARROW_ENTITY={
THROWING_ARROW_ENTITY.on_step = function(self, dtime) THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime self.timer=self.timer+dtime
local pos = self.object:getpos() local newpos = self.object:getpos()
for _, pos in pairs(get_trajectoire(self, newpos)) do
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
if self.timer>0.2 then if self.timer>0.2 then
@ -59,10 +60,10 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
local toughness = 0.9 local toughness = 0.9
if math.random() < toughness then if math.random() < toughness then
if math.random(0,100) % 2 == 0 then -- 50% of chance to drop //MFF (Mg|07/27/15) 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') minetest.add_item(pos, 'throwing:arrow_torch')
end end
else else
minetest.add_item(self.lastpos, 'default:stick') minetest.add_item(pos, 'default:stick')
end end
self.object:remove() self.object:remove()
return return
@ -75,7 +76,7 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
if node.name ~= "air" then if node.name ~= "air" then
local player = minetest.get_player_by_name(self.player) local player = minetest.get_player_by_name(self.player)
if not player then self.object:remove() return end if not player then self.object:remove() return end
if not string.find(node.name, "water") and not string.find(node.name, "lava") 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 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 and not minetest.is_protected(self.lastpos, self.player) and node.diggable ~= false then
local dir=vector.direction(self.lastpos, pos) local dir=vector.direction(self.lastpos, pos)
@ -95,6 +96,8 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
end end
self.lastpos={x=pos.x, y=pos.y, z=pos.z} 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
minetest.register_entity("throwing:arrow_torch_entity", THROWING_ARROW_ENTITY) minetest.register_entity("throwing:arrow_torch_entity", THROWING_ARROW_ENTITY)