How verify if there is a monster on a tile ?

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
montagneyaya
Posts: 103
Joined: Tue May 01, 2012 11:08 pm

How verify if there is a monster on a tile ?

Post by montagneyaya »

I will verify if there is a monster on a tile, I use entitiesAt(level, x, y) but how i see if the iterator is a monster ?

The only possibility I know

Code: Select all

monsters_list = {"snail", "crowern", "wyvern", "other_monster"}
for i in entitiesAt(1,15,15) do
    for j in monsters_list do
        if i.name == j then
            print("monster")
        end
    end
end
List all monster is laborious, there is no other possibility ?
Last edited by montagneyaya on Thu Nov 15, 2012 2:30 am, edited 1 time in total.
User avatar
Neikun
Posts: 2457
Joined: Thu Sep 13, 2012 1:06 pm
Location: New Brunswick, Canada
Contact:

Re: How verify if there is a monster on a tile ?

Post by Neikun »

I wonder if there's a way to list them by class.
"I'm okay with being referred to as a goddess."
Community Model Request Thread
See what I'm working on right now: Neikun's Workshop
Lead Coordinator for Legends of the Northern Realms Project
  • Message me to join in!
User avatar
montagneyaya
Posts: 103
Joined: Tue May 01, 2012 11:08 pm

Re: How verify if there is a monster on a tile ?

Post by montagneyaya »

All entities have the following properties that can be accessed with the dot operator:

“name” returns the name of the entity
“id” returns the unique identifier of the entity
“x” returns the x-coordinate of the entity on the map
“y” returns the y-coordinate of the entity on the map
“facing” returns the facing of the entity (0=north, 1=east, 2=south, 3=west)
“level” returns the dungeon level index of the entity
No class :(
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: How verify if there is a monster on a tile ?

Post by Komag »

I don't know of any other way, but you should only have to do it once, and then you can refer to the list as many times as you need in your dungeon
Finished Dungeons - complete mods to play
User avatar
Lark
Posts: 178
Joined: Wed Sep 19, 2012 4:23 pm
Location: Springfield, MO USA

Re: How verify if there is a monster on a tile ?

Post by Lark »

montagneyaya wrote:I will verify if there is a monster on a tile, I use entitiesAt(level, x, y) but how i see if the iterator is a monster ?
I had the same problem looking for monsters and other things. The trick is to find a keyword or method that is only attached to the entities in which you're interested. For example, only monsters have the setAIState method. So if you iterate over the entities returned and eleminate those without this method, you'll have a list of monsters. You might also want to filter on other things like finding all objects in a square - so look only for objects with the getWeight method. You can look at the entity name too, for example, and find all doors, but finding all monsters or objects without looking at methods is difficult. You can write a dedicated routine for each requirement, but I wrote a generic find and filter routine instead which is found at viewtopic.php?f=14&t=3985&p=41224&hilit=Lark#p41224 that will do the trick.

To find all monsters, just use monsters = findAll(self.level, self.x, self.y, {":setAIState"})

See the original post for more details and for the code.

Have Fun! -Lark
User avatar
Neikun
Posts: 2457
Joined: Thu Sep 13, 2012 1:06 pm
Location: New Brunswick, Canada
Contact:

Re: How verify if there is a monster on a tile ?

Post by Neikun »

Oh that Lark and his /infinite genius/
uncompromisingly stubborn
<3
Last edited by Neikun on Thu Nov 15, 2012 4:38 am, edited 2 times in total.
"I'm okay with being referred to as a goddess."
Community Model Request Thread
See what I'm working on right now: Neikun's Workshop
Lead Coordinator for Legends of the Northern Realms Project
  • Message me to join in!
User avatar
montagneyaya
Posts: 103
Joined: Tue May 01, 2012 11:08 pm

Re: How verify if there is a monster on a tile ?

Post by montagneyaya »

Thanks for your answers.

I test my script and I have an error :

Code: Select all

for j in monsters_list do    attempt to call a table value
I test other simple script with table

Code: Select all

function OpenAll()
	list_of_gates = {"portcullis_1", "portcullis_2", "portcullis_3"}
	for i in list_of_gates do
		i:open()
	end
end
and have the same error, why have I the error "attempt to call a table value" ?
User avatar
Lark
Posts: 178
Joined: Wed Sep 19, 2012 4:23 pm
Location: Springfield, MO USA

Re: How verify if there is a monster on a tile ?

Post by Lark »

The problem here is that you have a table that contains the ids of the entities that you want, but not the entities themselves. Try this (untested) code:

Code: Select all

function OpenAll()
   list_of_gates = {"portcullis_1", "portcullis_2", "portcullis_3"}
   for i in list_of_gates do
      entity = findEntity(i)
      if entity ~= nil then entity:open() end
   end
end
Good Luck, -Lark

P.S. The FindAll function referenced above returns entities, not ids, so you won't have that problem if you use that function.
Last edited by Lark on Thu Nov 15, 2012 4:23 am, edited 1 time in total.
User avatar
Lark
Posts: 178
Joined: Wed Sep 19, 2012 4:23 pm
Location: Springfield, MO USA

Re: How verify if there is a monster on a tile ?

Post by Lark »

Neikun wrote:Oh that Lark and his infinite genius <3
Thank you :oops: , but you should replace "infinite genius" with "uncompromisingly stubborn" to get closer to the truth! Hey, I like programming! :geek: -Lark
User avatar
Neikun
Posts: 2457
Joined: Thu Sep 13, 2012 1:06 pm
Location: New Brunswick, Canada
Contact:

Re: How verify if there is a monster on a tile ?

Post by Neikun »

If you say so~ haha.
I will continue to revere you as one of the most creative scripters this community's got.
"I'm okay with being referred to as a goddess."
Community Model Request Thread
See what I'm working on right now: Neikun's Workshop
Lead Coordinator for Legends of the Northern Realms Project
  • Message me to join in!
Post Reply