WaspUK1966 wrote:Thanks for that. Have you got a working code that uses the onAttack function. Still cant get it to work! Sorry..
George
This is what I've come up with:
Code: Select all
defineObject{
name = "spear_breakable",
baseObject = "base_item",
components = {
{
class = "Model",
model = "assets/models/items/skeleton_spear.fbx",
},
{
class = "Item",
uiName = "Spear",
gfxIndex = 208,
impactSound = "impact_blade",
weight = 3.0,
fitContainer = false,
traits = { "light_weapon", "two_handed", "spear", "aquatic" },
},
{
class = "MeleeAttack",
attackPower = 10,
accuracy = 0,
cooldown = 5,
swipe = "thrust",
attackSound = "swipe",
reachWeapon = true,
onAttack = function(self, champion, action, slot)
if self.go.meleeattack:isEnabled() then
--hudPrint(self.go.item:getUiName().." attack")
else
hudPrint("The spear is broken, you cannot attack with it.")
return false
end
end,
onHitMonster = function(self, monster, side, dmg, champion)
--hudPrint(self.go.item:getUiName().." hit monster")
self.go.item:setUiName("Spear (broken)")
hudPrint("The spear breaks!")
self.go.meleeattack:disable()
end,
onPostAttack = function(self)
--hudPrint(self.go.item:getUiName().." post attack")
end,
},
},
tags = { "weapon" },
}
When you hit a monster, the spear "breaks" and can't be used to attack anymore.
It doesn't break if you attack a wall or an obstacle.
What I don't understand is, self.go.meleeattack:disable() by itself doesn't work.
You can still attack with the spear even with the MeleeAttack component disabled.
That's why the "onAttack" function contains the "if self.go.meleeattack:isEnabled()" check.