detach player (if attached) before attacking

master
Juraj Vajda 2018-11-28 23:01:31 -05:00
parent 9e2ba14c50
commit 562f73399c
1 changed files with 30 additions and 2 deletions

32
api.lua
View File

@ -1955,9 +1955,37 @@ local do_states = function(self, dtime)
-- punch player (or what player is attached to)
local attached = self.attack:get_attach()
if attached then
self.attack = attached
-- detach player (if attached) before attacking
if attached and self.attack:is_player() then
-- carts
if attached:get_luaentity().name == "carts:cart" then
attached:get_luaentity().driver = nil
carts:manage_attachment(self.attack, nil)
-- boats
elseif attached:get_luaentity().name == "boats:boat" then
attached:get_luaentity().driver = nil
attached:get_luaentity().auto = false
self.attack:set_detach()
player_api.player_attached[self.attack:get_player_name()] = false
player_api.set_animation(self.attack, "stand" , 30)
local pos = self.attack:get_pos()
pos = {x = pos.x, y = pos.y + 0.2, z = pos.z}
minetest.after(0.1, function()
self.attack:set_pos(pos)
end)
-- mob horse
elseif attached:get_luaentity().name == "mob_horse:horse" then
minetest.add_item(attached:get_pos(), "mobs:saddle")
mobs.detach(self.attack, {x = 1, y = 0, z = 1})
end
end
-- if attached then
-- self.attack = attached
-- end
self.attack:punch(self.object, 1.0, {
full_punch_interval = 1.0,
damage_groups = {fleshy = self.damage}