1
0
Fork 0

Make arrows only damage players and mobs

objects
Wuzzy 2017-07-25 01:14:32 +02:00
parent 613ea77713
commit 3bee57e97d
1 changed files with 20 additions and 28 deletions

View File

@ -59,13 +59,13 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
-- Iterate through all objects and remember the closest attackable object -- Iterate through all objects and remember the closest attackable object
for k, obj in pairs(objs) do for k, obj in pairs(objs) do
if obj:get_luaentity() ~= nil then -- Arrows can only damage players and mobs
local entity_name = obj:get_luaentity().name if obj ~= self._shooter and obj:is_player() then
if obj ~= self._shooter and entity_name ~= "mcl_throwing:arrow_entity" and entity_name ~= "__builtin:item" and entity_name ~= "__builtin:falling_node" then ok = true
elseif obj:get_luaentity() ~= nil then
if obj ~= self._shooter and obj:get_luaentity()._cmi_is_mob then
ok = true ok = true
end end
elseif obj ~= self._shooter then
ok = true
end end
if ok then if ok then
@ -83,36 +83,28 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
-- If an attackable object was found, we will damage the closest one only -- If an attackable object was found, we will damage the closest one only
if closest_object ~= nil then if closest_object ~= nil then
local obj = closest_object local obj = closest_object
if obj:get_luaentity() ~= nil then local is_player = obj:is_player()
local entity_name = obj:get_luaentity().name local lua = obj:get_luaentity()
if obj ~= self._shooter and entity_name ~= "mcl_throwing:arrow_entity" and entity_name ~= "__builtin:item" and entity_name ~= "__builtin:falling_node" then if obj ~= self._shooter and (is_player or (lua and lua._cmi_is_mob)) then
obj:punch(self.object, 1.0, { obj:punch(self.object, 1.0, {
full_punch_interval=1.0, full_punch_interval=1.0,
damage_groups={fleshy=self._damage}, damage_groups={fleshy=self._damage},
}, nil) }, nil)
if obj:is_player() then if is_player then
mcl_hunger.exhaust(obj:get_player_name(), mcl_hunger.EXHAUST_DAMAGE) mcl_hunger.exhaust(obj:get_player_name(), mcl_hunger.EXHAUST_DAMAGE)
end end
if lua then
local entity_name = lua.name
-- Achievement for hitting skeleton, wither skeleton or stray (TODO) with an arrow at least 50 meters away -- Achievement for hitting skeleton, wither skeleton or stray (TODO) with an arrow at least 50 meters away
-- NOTE: Range has been reduced because mobs unload much earlier than that ... >_> -- NOTE: Range has been reduced because mobs unload much earlier than that ... >_>
-- TODO: This achievement should be given for the kill, not just a hit -- TODO: This achievement should be given for the kill, not just a hit
if self._shooter and self._shooter:is_player() and vector.distance(pos, self._startpos) >= 20 then if self._shooter and self._shooter:is_player() and vector.distance(pos, self._startpos) >= 20 then
if (entity_name == "mobs_mc:skeleton" or entity_name == "mobs_mc:skeleton2") then if (entity_name == "mobs_mc:skeleton" or entity_name == "mobs_mc:stray" or entity_name == "mobs_mc:witherskeleton") then
awards.unlock(self._shooter:get_player_name(), "mcl:snipeSkeleton") awards.unlock(self._shooter:get_player_name(), "mcl:snipeSkeleton")
end end
end end
self.object:remove()
end end
elseif obj ~= self._shooter then
obj:punch(self.object, 1.0, {
full_punch_interval=1.0,
damage_groups={fleshy=self._damage},
}, nil)
if obj:is_player() then
mcl_hunger.exhaust(obj:get_player_name(), mcl_hunger.EXHAUST_DAMAGE)
end
self.object:remove() self.object:remove()
end end
end end