custom breakable object

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

custom breakable object

Post 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,
}
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
User avatar
THOM
Posts: 1274
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: custom breakable object

Post by THOM »

For what do you need the controller-component?
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: custom breakable object

Post 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
Last edited by Isaac on Tue Jan 13, 2015 12:09 pm, edited 9 times in total.
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: custom breakable object

Post 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!
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
User avatar
Ciccipicci
Posts: 154
Joined: Mon Oct 08, 2012 12:55 am

Re: custom breakable object

Post by Ciccipicci »

Thanks! Someone should make a pack of breakable object! I'm in love with them!
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: custom breakable object

Post 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
Post Reply