Get monster position and area around him.

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
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Get monster position and area around him.

Post by Emera Nova »

What im looking for is what is needed to check where a monster is and then in the adjacent squares send out a spell so that it damages anything in those tiles.
Eburt
Posts: 69
Joined: Thu Feb 05, 2015 5:44 am

Re: Get monster position and area around him.

Post by Eburt »

There are several ways to do this and I find that the easiest way depends on where you are trying to get the information. E.g., if say you're defining an attack for that monster, or adding a hook to any other component of that monster you can use self.go.x and self.go.y to obtain the x and y positions. Then just add/subtract 1 from each as appropriate to get the adjacent squares. GameObject.getPosition() and GameObject.getWorldPosition() can also be useful, depending on what you are doing.

Note that you probably want some error checking in case the monster is on the edge of the map since trying to create the tile damager (or anything else) outside the map bounds will crash the game. Elevation may also be something you want to consider. Hope this helps.
Post Reply