bongobeat wrote:I ve defined a breakable mine_support_wall but I can't break it with melee weapon. It works only with throwing weapons, or spells.
Please can someone tell me what I ve done wrong?
I loaded it unchanged, placed one, and broke it with the unarmed attack. I think what's probably wrong, is that you've defined it as placed on a wall, but are attacking it from behind [the door/wall].
____
This is a hack, but seems to work passably enough. Though it doesn't show the attack damage.
I do not yet know of a direct way to damage an object's health via script ~aside from damageTile() which is exploitable overkill. There is a way to detect when the door is hit, but no way (that I know of yet) to do anything to the door ~except destroy it, or calculate (fake) the damage and eventually destroy it; and that's what this does.
Code: Select all
--mine wall support breakable
defineObject{
name = "mine_support_wall_01_block",
baseObject = "base_wall",
components = {
{
class = "Model",
model = "assets/models/env/mine_support_wall_01.fbx",
staticShadow = true,
},
{
class = "Door",
sparse = true,
hitSound = "impact_blunt",
onAttackedByChampion = function (self, champion, weapon, attack, slot)
local attack_power = attack:getAttackPower()
local damageStat = attack:getBaseDamageStat()
if damageStat then
attack_power = attack_power + champion:getCurrentStat(damageStat)
end
local health = self.go.health:getHealth()
local damage = rollDamage(attack_power)
if weapon then
if not weapon.go:getComponent("FirearmAttack") then
local skillAdjustedDamage = function ()
local damage_bonus = function()
local isSkilled = 0
if attack:getRequirements() ~= nil then
isSkilled = champion:getSkillLevel(attack:getRequirements()[1])
end
if isSkilled then
return (damage * 0.2) * isSkilled
end
return 0
end
return damage + damage_bonus()
end
self.go.health:setHealth( health - skillAdjustedDamage())
end
else
self.go.health:setHealth( health - damage)
end
local effect = findEntity(self.go:spawn("particle_system").id)
effect.particle:setParticleSystem("hit_wood")
effect.particle:setOffset(vec(0,1.5,1))
if health < 0 then
spawn(self.go.health:getSpawnOnDeath())
self.go:destroy()
playSound("barrel_die")
else playSound("barrel_hit")
end
end,
},
{
class = "Obstacle",
-- hitSound = "barrel_hit",
-- hitEffect = "hit_wood",
blockParty = false,
blockMonsters = false,
},
{
class = "Health",
health = 50,
immunities = { "poison", "physical" },
spawnOnDeath = "barrel_crate_block_broken",
dieSound = "barrel_die",
onDie = function(self)
local effect = findEntity(self.go:spawn("particle_system").id)
effect.particle:setParticleSystem("hit_wood")
effect.particle:setOffset(vec(0,1.5,1))
end,
},
},
placement = "wall",
editorIcon = 160,
automapIcon = 88,
minimalSaveState = true,
}
What is needed is to be able to call an object.go.health:damage(amount, type) function... but something like that doesn't exist [afaik].
I'll come back to it when I learn of a better method.
edit:
**practically rewrote the script, but I like it a lot better now.
https://www.dropbox.com/s/21g3pwyyt269r ... t.avi?dl=0