Page 1 of 1

custom breakable object

Posted: Sun Jan 11, 2015 11:54 pm
by bongobeat
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?
SpoilerShow

Code: Select all

--mine wall support breakable
defineObject{
	name = "mine_support_wall_01_block",
   baseObject = "base_obstacle",
   components = {
      {
         class = "Model",
			model = "assets/models/env/mine_support_wall_01.fbx",
			staticShadow = true,
      },
   		{
			class = "Door",
			sparse = true,
			hitSound = "impact_blunt",
		},

		{
			class = "Obstacle",
			hitSound = "barrel_hit",
			hitEffect = "hit_wood",
		},
      {
         class = "Health",
         health = 50,
			immunities = { "poison" },
			spawnOnDeath = "barrel_crate_block_broken",
			onDie = function(self)
				self.go:playSound("barrel_die")
			end,      },
      {
         class = "Controller",
      },
   },
	placement = "wall",
	editorIcon = 160,
	automapIcon = 88,
	minimalSaveState = true,
}

Re: custom breakable object

Posted: Mon Jan 12, 2015 12:58 am
by THOM
For what do you need the controller-component?

Re: custom breakable object

Posted: Mon Jan 12, 2015 1:12 am
by Isaac
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

Re: custom breakable object

Posted: Mon Jan 12, 2015 3:40 pm
by bongobeat
Shame on me, you are right, It works perfectly :oops:

I have placed it near a mine secret door, so that's why it did not work, it hits the secret_door first.
(by the way, if the secret door is open, it works when you hit the mine support)
Placed normally, it's ok
THOM wrote:For what do you need the controller-component?
I don't know, this comes from the breakable wall definition from skugasvein.

I have already deleted the door and controller component, don't sure if those are needed.
SpoilerShow

Code: Select all

defineObject{
	name = "mine_support_wall_01_breakable",
	baseObject = "base_obstacle",
	components = {
		{
			class = "Model",
			model = "assets/models/env/mine_support_wall_01.fbx",
		},
		{
			class = "Obstacle",
			hitSound = "barrel_hit",
			hitEffect = "hit_wood",
		},
		{
			class = "Health",
			health = 50,
			immunities = { "poison" },
			spawnOnDeath = "barrel_crate_block_broken",
			onDie = function(self)
				self.go:playSound("barrel_die")
			end,
		},
      {
         class = "Controller",
      },
	},
   placement = "wall",
   automapTile = "wall",
   editorIcon = 120,
}
sorry for bothering!

Re: custom breakable object

Posted: Tue Jan 13, 2015 1:44 am
by Ciccipicci
Thanks! Someone should make a pack of breakable object! I'm in love with them!

Re: custom breakable object

Posted: Tue Jan 13, 2015 9:57 am
by Isaac
I changed the attack hook extensively. It's still just an approximate for damage dealt, and still does not display damage floating text.
I wish I knew of a built-in object damaging function that behaved like a normal attack; or at least a way to determine the exact damage a champion would do with the weapon. :(

*Missile weapons do not affect the breakable support; but firearms do.

**Added a kludge to allow spells to affect the supports; functional~ish. Image