[FIXED] Editor Hangs: Obj > Die > Spell > Damage Party

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
User avatar
Lark
Posts: 178
Joined: Wed Sep 19, 2012 4:23 pm
Location: Springfield, MO USA

[FIXED] Editor Hangs: Obj > Die > Spell > Damage Party

Post by Lark »

The following object, when destroyed, blows up and damages the party... and then the editor/game immediately hang. This was my first object I created for LoG1 and I wanted to use it in LoG2. Prozail helped convert it, but alas it locks up everything when it dies.

Is this a bug or is something wrong with the object? Thanks, -Lark

Code: Select all

defineObject {
  name = "exploding_barrel_block",
  baseObject = "barrel_crate_block",
  components = {
    {
    class =   "Health",
    name ="health",
    health = 30,
    onDie = function(c)
      local i, j
      for i = -1, 1 do
        for j = -1, 1 do
          spawn("fireburst", c.go.level, c.go.x + i, c.go.y + j, 0, c.go.elevation)
          end
        end
      end
      },
    },
  }
(Reposted from dormant thread.)
Last edited by Lark on Wed Nov 05, 2014 7:26 pm, edited 1 time in total.
User avatar
Prozail
Posts: 158
Joined: Mon Oct 27, 2014 3:36 pm

Re: [Bug?] Editor Hangs: Obj > Die > Spell > Damage Party

Post by Prozail »

Looks like it hangs only if the ENTIRE party dies. If you do damage with for instance a fireball, that some survies, it works., maybe try a delayedCall to not have the party die in the same "gameframe", not tested myself.

My second suggestion is toying with the tiledamager-component
Last edited by Prozail on Wed Nov 05, 2014 7:10 pm, edited 1 time in total.
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: [Bug?] Editor Hangs: Obj > Die > Spell > Damage Party

Post by JohnWordsworth »

I think the problem is that the fireburst is spawning immediately, which is then doing more damage to the health component, which is calling onDie again, which is spawning more fireburst... This loop continues until the game crashes.

SO...

You have two options.

1. Spawn a fireburst on the 8-spaces around the barrel but not on the barrel.
SpoilerShow

Code: Select all

defineObject {
	name = "exploding_barrel_block",
	baseObject = "barrel_crate_block",
	components = {
		{
			class = "Health",
			health = 30,
			onDie = function(c)
				local i, j;
				
				for i = -1, 1 do
					for j = -1, 1 do
						if i ~= 0 or j ~= 0 then
							spawn("fireburst", c.go.level, c.go.x + i, c.go.y + j, 0, c.go.elevation)
						end
					end
				end
			end
		}
	}
}
2. Set a flag on the component in the onDie function. At the start of the function, if that flag is already set, then you return doing nothing more (stop the infinite loop). This appears to work (which is cool), but I don't know what the policy is on setting random variables on components like this (it seems to work fine - but is it meant too?).
SpoilerShow

Code: Select all

defineObject {
	name = "exploding_barrel_block",
	baseObject = "barrel_crate_block",
	components = {
		{
			class = "Health",
			health = 30,
			onDie = function(c)
				if ( c.property ~= nil ) then
					--print("BLOCKED")
					return
				end
				
				c.property = 1;
				local i, j;
				
				for i = -1, 1 do
					for j = -1, 1 do
						spawn("fireburst", c.go.level, c.go.x + i, c.go.y + j, 0, c.go.elevation)
					end
				end
			end
		}
	}
}
Both of these solutions appear to work in the editor for me, whereas I got a crash with your original code.
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
User avatar
Prozail
Posts: 158
Joined: Mon Oct 27, 2014 3:36 pm

Re: [Bug?] Editor Hangs: Obj > Die > Spell > Damage Party

Post by Prozail »

Thank you John.. you just answered another question I had ;)
User avatar
Lark
Posts: 178
Joined: Wed Sep 19, 2012 4:23 pm
Location: Springfield, MO USA

Re: [Bug?] Editor Hangs: Obj > Die > Spell > Damage Party

Post by Lark »

Perfect, thank you. Why do I expect old (lazy) programming from LoG1 to work on LoG2? Hey, it was my first LUA! And should I change history? Won't the Smithsonian object? Good programming will always win out. Speaking of which, I should probably do boundary checking... Thank you John! -Lark
User avatar
Kuro01
Posts: 36
Joined: Tue Jun 23, 2015 2:05 pm

Re: [FIXED] Editor Hangs: Obj > Die > Spell > Damage Party

Post by Kuro01 »

I made one that spawns rats. I'm new at this lots of fun.It works.Not sure if everything in there is needed.

Code: Select all

defineObject{
	name = "exploding_barrel_rat_swarm",
	baseObject = "base_obstacle",
	components = {
		{
			class = "Model",
			model = "assets/models/env/barrel_crate_block.fbx",
		},
		{			
			class = "Obstacle",
			hitSound = "barrel_hit",
			hitEffect = "hit_wood",	
		},
		{
			class = "Health",
			health = 50,
			immunities = { "poison" },
			spawnOnDeath = "barrel_crate_block_broken",
			onDie = function(self)
				for i = 1, math.random(2,3) do
					local obj = self.go:spawn("rat_swarm")
					local pos = obj:getWorldPosition()
					local spread = 1.5
					pos.x = pos.x + (math.random() - 0.5) * spread
					pos.z = pos.z + (math.random() - 0.5) * spread
					obj:setWorldPosition(pos)
				end
			end,
		},
		{
			class = "Sound",
			sound = "barrel_die",
		},
	},
	editorIcon = 260,
}
Post Reply