Help with OnDie and Coordinates

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

Help with OnDie and Coordinates

Post by Lark »

Well, after a long time away due to family, work, and other issues, I'm finally back - Thank you AH for the LoG2 magnet!

I've waited as long as I can, but I'm dying to do some things, but need the script reference. Until then, does anyone have any idea how to convert the following LoG1 object? Doing so would answer several questions: I believe it's just "defineObject" now, I need to add height to the spawn line, but "onDie" and "self." don't work in LoG2.

Code: Select all

cloneObject{
  name = "exploding_barrel_block",
  baseObject = "barrel_crate_block",
  onDie = function(self)
    for i = -1, 1 do
      for j = -1, 1 do
        spawn("fireburst", self.level, self.x + i, self.y + j, 0)
        end
      end
    end
  }
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: Help with OnDie and Coordinates

Post by NutJob »

This may help.
User avatar
Lark
Posts: 178
Joined: Wed Sep 19, 2012 4:23 pm
Location: Springfield, MO USA

Re: Help with OnDie and Coordinates

Post by Lark »

Thanks, but I've looked at this (and all the rest of the Forum as best as I could) and I can't find what I need.

Basically, I need to know the new way of doing two things:
  • The "onDie" isn't triggering (so it's probably called something else now).
  • The coordinates of the object/script itself are no longer accessible via "self.x", "self.y", "self.level", "self.facing", et cetera. They also are probably renamed. I found (and lost) a way to reference an object's location by its name which will be useful when I find it again, but in this case, I need to reference locations around the object too.
I've played around with both, but I haven't found the magic combination yet.

Thanks!
User avatar
Lark
Posts: 178
Joined: Wed Sep 19, 2012 4:23 pm
Location: Springfield, MO USA

Re: Help with OnDie and Coordinates

Post by Lark »

I have had a little "success" - I can create a script and find its location using things like:

Code: Select all

script_entity_2.x
script_entity_2.y
script_entity_2.elevation
script_entity_2.level
script_entity_2.facing
This isn't very useful for multiple versions of of the same script and I assume for the same objects since you won't know what it's called until you place them. So I'm still missing the concept of "self". Why, even "script_entity_2.id" works and returns, ... (wait for it). Uh, "script_entity_2" - the name of the script as suspected. I'm hoping there is still a replacement for "self".
User avatar
Prozail
Posts: 158
Joined: Mon Oct 27, 2014 3:36 pm

Re: Help with OnDie and Coordinates

Post by Prozail »

You need to go through the healthcomponent.
Also, be wary of how you use "self" or you might crash the game.

Edit: I just realized this crashes the game if the party gets hit by explosion... not sure what causes it though...

Code: Select all


defineObject {
	name = "exploding_barrel_block",
	baseObject = "barrel_crate_block",
	components = {
		{
			class =	"Health",
			name ="health",
			health = 30,
			onDie = function(sender)
				for i = -1, 1 do
					for j = -1, 1 do
						spawn("fireburst", sender.go.level, sender.go.x + i, sender.go.y + j, 0)
					end
				end
			end
		},
	},
}

User avatar
Lark
Posts: 178
Joined: Wed Sep 19, 2012 4:23 pm
Location: Springfield, MO USA

Re: Help with OnDie and Coordinates

Post by Lark »

Yep, locks it up tight. It displays a damage number on the screen and everything locks up. While this object still remains a mystery, you did answer one of my big questions of how a script can find the location of its caller. Although I tried multiple combinations, I missed the working one which is to use ".go" (game object). A script can now spawn things, or do other things, based on the caller's location. Here is a reporting script:

Code: Select all

function test(caller)
  hudPrint(
    "Coord={" .. self.go.x .. ", "  .. caller.go.y .. ", "  .. caller.go.elevation .. "} " 
    .. " level=" .. caller.go.level
    .. "  facing="  .. caller.go.facing 
    .. "  id=" .. caller.go.id
    )
  end
If you place two different triggers that call this script, the coordinates, et cetera will be different based on which trigger you activated.

Thank you Prozail! -Lark
Post Reply