From 3f288ae1840ef5d0d488994fedd5f07a2d095ab6 Mon Sep 17 00:00:00 2001 From: crabman77 Date: Tue, 21 Jul 2015 20:59:59 +0200 Subject: [PATCH] remove random pickaxe or stick and add digged node and throwing:arrow_dig fix crash if not player in function throwing_shoot_arrow() "LuaEntity name "" not defined" and "functions.lua:34: attempt to index a nil value" fix crash, "self.*" not defined after self.object:remove() "dig_arrow.lua:67: attempt to index field 'player' (a nil value)" --- mods/throwing/dig_arrow.lua | 18 +++++------------- mods/throwing/functions.lua | 3 +++ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/mods/throwing/dig_arrow.lua b/mods/throwing/dig_arrow.lua index adb4e6b2..af914501 100755 --- a/mods/throwing/dig_arrow.lua +++ b/mods/throwing/dig_arrow.lua @@ -55,12 +55,7 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) damage_groups={fleshy=damage}, }, nil) self.object:remove() - local toughness = 0.9 - if math.random() < toughness then - minetest.add_item(self.lastpos, 'throwing:arrow_dig') - else - minetest.add_item(self.lastpos, 'default:stick') - end + minetest.add_item(self.lastpos, "throwing:arrow_dig") end end end @@ -68,18 +63,15 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) if self.lastpos.x~=nil then if node.name ~= "air" then - self.object:remove() + if minetest.get_item_group(node.name, "unbreakable") == 0 and areas:canInteract(self.lastpos, self.player:get_player_name()) and node.diggable ~= false then minetest.set_node(pos, {name = "air"}) end - local toughness = 0.65 - if math.random() < toughness then - minetest.add_item(self.lastpos, 'default:pick_steel') - else - minetest.add_item(self.lastpos, 'default:stick') - end + minetest.add_item(self.lastpos, node.name) + minetest.add_item(self.lastpos, "throwing:arrow_dig") + self.object:remove() end end self.lastpos={x=pos.x, y=pos.y, z=pos.z} diff --git a/mods/throwing/functions.lua b/mods/throwing/functions.lua index e6d1c518..2fefc7ca 100755 --- a/mods/throwing/functions.lua +++ b/mods/throwing/functions.lua @@ -17,11 +17,13 @@ minetest.register_on_leaveplayer(function(player) end) function throwing_shoot_arrow (itemstack, player, stiffness, is_cross) + if not player then return end local arrow = itemstack:get_metadata() itemstack:set_metadata("") player:set_wielded_item(itemstack) local playerpos = player:getpos() local obj = minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, arrow) + if not obj then return end local dir = player:get_look_dir() obj:setvelocity({x=dir.x*stiffness, y=dir.y*stiffness, z=dir.z*stiffness}) obj:setacceleration({x=dir.x*-3, y=-10, z=dir.z*-3}) @@ -44,6 +46,7 @@ function throwing_unload (itemstack, player, unloaded, wear) if not minetest.setting_getbool("creative_mode") then player:get_inventory():add_item("main", arrow[1]) end + break end end end