mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2025-01-11 18:40:25 +01:00
improve/debug throwing mod
This commit is contained in:
parent
678715707e
commit
0edff51305
@ -45,9 +45,9 @@ local THROWING_ARROW_ENTITY={
|
||||
|
||||
THROWING_ARROW_ENTITY.on_step = function(self, 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)
|
||||
|
||||
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
|
||||
@ -57,13 +57,13 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
|
||||
self.inventory:remove_item("main", {name=self.stack:get_name()})
|
||||
end
|
||||
if self.stack then
|
||||
minetest.add_item(self.lastpos, {name=self.stack:get_name()})
|
||||
minetest.add_item(pos, {name=self.stack:get_name()})
|
||||
end
|
||||
local toughness = 0.95
|
||||
if math.random() < toughness then
|
||||
minetest.add_item(self.lastpos, 'throwing:arrow_build')
|
||||
minetest.add_item(pos, 'throwing:arrow_build')
|
||||
else
|
||||
minetest.add_item(self.lastpos, 'default:stick')
|
||||
minetest.add_item(pos, 'default:stick')
|
||||
end
|
||||
self.object:remove()
|
||||
return
|
||||
@ -71,14 +71,13 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if self.lastpos.x~=nil then
|
||||
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
|
||||
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()})
|
||||
@ -86,9 +85,12 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
|
||||
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
|
||||
self.lastpos={x=newpos.x, y=newpos.y, z=newpos.z}
|
||||
end
|
||||
|
||||
minetest.register_entity("throwing:arrow_build_entity", THROWING_ARROW_ENTITY)
|
||||
|
@ -40,11 +40,12 @@ local THROWING_ARROW_ENTITY={
|
||||
player = "",
|
||||
}
|
||||
|
||||
|
||||
THROWING_ARROW_ENTITY.on_step = function(self, 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)
|
||||
|
||||
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
|
||||
@ -56,7 +57,7 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
|
||||
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")
|
||||
minetest.add_item(pos, "throwing:arrow_dig")
|
||||
end
|
||||
self.object:remove()
|
||||
return
|
||||
@ -64,21 +65,18 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
|
||||
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)
|
||||
|
@ -42,7 +42,8 @@ local THROWING_ARROW_ENTITY={
|
||||
|
||||
THROWING_ARROW_ENTITY.on_step = function(self, 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)
|
||||
|
||||
if self.timer>0.2 then
|
||||
@ -56,7 +57,7 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
|
||||
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')
|
||||
minetest.add_item(pos, 'default:stick')
|
||||
end
|
||||
self.object:remove()
|
||||
return
|
||||
@ -80,7 +81,8 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
|
||||
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
|
||||
|
||||
minetest.register_entity("throwing:arrow_fire_entity", THROWING_ARROW_ENTITY)
|
||||
|
@ -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()
|
||||
|
@ -44,7 +44,8 @@ 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 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
|
||||
@ -58,10 +59,10 @@ function throwing_register_arrow_standard (kind, desc, eq, toughness, craft)
|
||||
}, nil)
|
||||
if math.random() < toughness 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
|
||||
else
|
||||
minetest.add_item(self.lastpos, 'default:stick')
|
||||
minetest.add_item(pos, 'default:stick')
|
||||
end
|
||||
self.object:remove()
|
||||
return
|
||||
@ -70,19 +71,19 @@ function throwing_register_arrow_standard (kind, desc, eq, toughness, craft)
|
||||
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)
|
||||
|
@ -43,7 +43,8 @@ local THROWING_ARROW_ENTITY={
|
||||
|
||||
THROWING_ARROW_ENTITY.on_step = function(self, 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)
|
||||
|
||||
if self.timer>0.2 then
|
||||
@ -59,10 +60,10 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
|
||||
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')
|
||||
minetest.add_item(pos, 'throwing:arrow_torch')
|
||||
end
|
||||
else
|
||||
minetest.add_item(self.lastpos, 'default:stick')
|
||||
minetest.add_item(pos, 'default:stick')
|
||||
end
|
||||
self.object:remove()
|
||||
return
|
||||
@ -71,11 +72,11 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
|
||||
end
|
||||
end
|
||||
|
||||
if self.lastpos.x~=nil then
|
||||
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")
|
||||
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)
|
||||
@ -94,6 +95,8 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
|
||||
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
|
||||
|
||||
minetest.register_entity("throwing:arrow_torch_entity", THROWING_ARROW_ENTITY)
|
||||
|
Loading…
Reference in New Issue
Block a user