Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a bug #5

Open
IFRFSX opened this issue Aug 20, 2020 · 3 comments
Open

a bug #5

IFRFSX opened this issue Aug 20, 2020 · 3 comments

Comments

@IFRFSX
Copy link

IFRFSX commented Aug 20, 2020

shoot mobs mod's animals, the minetest will exit directly

@IFRFSX
Copy link
Author

IFRFSX commented Aug 20, 2020

2020-08-20 21:27:15: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'mobs_animal' in callback luaentity_Step(): ...gfsx/桌面/minetest/bin/../mods/bows/bows/arrow.lua:13: attempt to index local 'opos' (a nil value)
2020-08-20 21:27:15: ERROR[Main]: stack traceback:
2020-08-20 21:27:15: ERROR[Main]: ...gfsx/桌面/minetest/bin/../mods/bows/bows/arrow.lua:13: in function 'on_hit_object'
2020-08-20 21:27:15: ERROR[Main]: ...gfsx/桌面/minetest/bin/../mods/bows/bows/arrow.lua:150: in function <...gfsx/桌面/minetest/bin/../mods/bows/bows/arrow.lua:103>

@mferrari-incomm
Copy link

I had the same issue. The offending piece of code is in arrow.lua:

bows.on_hit_object=function(self,target,hp,user,lastpos)
	local hp2=target:get_hp()-hp
	target:set_hp(hp2)
	target:punch(target,1,{full_punch_interval=1,damage_groups={fleshy=4}},nil)
	if hp2>0 then
		local pos=self.object:get_pos()
		local opos=target:get_pos()
		local dir = user:get_look_dir()
		self.object:set_attach(target, "", {x=(opos.x-pos.x)*4,y=(pos.y-opos.y)*4,z=(pos.z-opos.z)*4},{x=0,y=-90,z=0})
	end
	return self
end

Even though hp2 is in fact bigger than 0, target:get_pos() is returning nil.

I haven't tested it yet, but I think we can hack it this way for now:

bows.on_hit_object=function(self,target,hp,user,lastpos)
	local hp2=target:get_hp()-hp
	target:set_hp(hp2)
	target:punch(target,1,{full_punch_interval=1,damage_groups={fleshy=4}},nil)
	if hp2>0 then
		local pos=self.object:get_pos()
		local opos=target:get_pos()
		local dir = user:get_look_dir()

		if pos ~= nil and opos ~= nil and dir ~= nil then
			self.object:set_attach(target, "", {x=(opos.x-pos.x)*4,y=(pos.y-opos.y)*4,z=(pos.z-opos.z)*4},{x=0,y=-90,z=0})
		end
	end
	return self
end

@IFRFSX
Copy link
Author

IFRFSX commented Oct 17, 2020

@Morocotopo

I have tested your code, shot the sheep in mobs_animal with bows, and the error no longer appears.
If you are free, you can fork a bows code and submit a PR to the author.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants