FindEntity Not WOrking

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Darsithis
Posts: 51
Joined: Wed Jul 24, 2013 6:31 pm

FindEntity Not WOrking

Post by Darsithis »

I'm trying to set up a simple thing: when you kill both patrols in the room, the door at the end opens. I've tried about 6 different ways to do it.

First, I have a timer that is deactivated. This timer, when activated, runs a script every minute. This script has been many variations on:

Code: Select all

function CheckOperatingRoomClear()

	if findEntity("operatingRoomPatrol1") == nil and findEntity("operatingRoomPatrol2") == nil then
		operatingRoomExitDoor:open()
		operatingRoomTimer:deactivate()
	end
end

Code: Select all

function CheckOperatingRoomClear()

	if not findEntity("operatingRoomPatrol1") and not findEntity("operatingRoomPatrol2") then
		operatingRoomExitDoor:open()
		operatingRoomTimer:deactivate()
	end
end
Along with a few other tries.

I've also tried a custom monster that hooks into onDie to decrement a counter. That fails as well. So my question is, what can I do to accomplish this, and, is this all failing because I use "K" to kill the monsters (I'm testing a high level room with level 1 debug party).
Darsithis
Posts: 51
Joined: Wed Jul 24, 2013 6:31 pm

Re: FindEntity Not WOrking

Post by Darsithis »

Actually it appears that the skeleton_patrol type cannot be found via findEntity. This all works correctly if I use anything that isn't a patrol.

AH, fix it!
User avatar
Allanius2
Posts: 124
Joined: Mon Apr 14, 2014 10:12 pm

Re: FindEntity Not WOrking

Post by Allanius2 »

I haven't much experience with lua or Grimrock mods, but is it possible that the monsters continue to exist even if dead? Maybe you need to check for their deaths like this:

Code: Select all

if findEntity("operatingRoomPatrol1").dead and findEntity("operatingRoomPatrol2").dead then
      operatingRoomExitDoor:open()
      operatingRoomTimer:deactivate()
   end
end
Sorry I can't be of more help in that department. What I really wanted to share with you is for testing your mods with a higher leveled party. Komag has a great Grimrock remake mod http://www.nexusmods.com/grimrock/mods/230/? in which he has setup different parties to test with. Just download and check the "lua" entry in the upper left hand corner of level 1. I hope this helps.
Darsithis
Posts: 51
Joined: Wed Jul 24, 2013 6:31 pm

Re: FindEntity Not WOrking

Post by Darsithis »

Allanius2 wrote:I haven't much experience with lua or Grimrock mods, but is it possible that the monsters continue to exist even if dead? Maybe you need to check for their deaths like this:

Code: Select all

if findEntity("operatingRoomPatrol1").dead and findEntity("operatingRoomPatrol2").dead then
      operatingRoomExitDoor:open()
      operatingRoomTimer:deactivate()
   end
end
Sorry I can't be of more help in that department. What I really wanted to share with you is for testing your mods with a higher leveled party. Komag has a great Grimrock remake mod http://www.nexusmods.com/grimrock/mods/230/? in which he has setup different parties to test with. Just download and check the "lua" entry in the upper left hand corner of level 1. I hope this helps.
Well what I did to discover the bug is I added print(findEntity("operatingRoomPatrol1")) and found that returns nil at all times although finding a single skeleton's entity worked just fine. It wasn't a matter of them dying and remaining - the game considered them not to exist from the start. The moment the plate triggered my timer, the gate would open, every time.

It works now that I replaced the two patrol with 8 individual skeletons. But I will check out the Grimrock remake (which I played through!) and see what I can find.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: FindEntity Not WOrking

Post by minmay »

Groups of multiple monsters do not retain their id when the level is played. Each monster in the group is its own entity, and regardless of the id you gave the group, each monster will be created with numerical id like you get from e.g. using "spawn("snail")". If you need to refer to a monster in a group you'll have to find it by some other means and get the id from that.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
msyblade
Posts: 792
Joined: Fri Oct 12, 2012 4:40 am
Location: New Mexico, USA
Contact:

Re: FindEntity Not WOrking

Post by msyblade »

You may be able to clone another skeleton, put those into a patrol, and add an OnDie hook to open the door.
Currently conspiring with many modders on the "Legends of the Northern Realms"project.

"You have been captured by a psychopathic diety who needs a new plaything to torture."
Hotel Hades
Darsithis
Posts: 51
Joined: Wed Jul 24, 2013 6:31 pm

Re: FindEntity Not WOrking

Post by Darsithis »

minmay wrote:Groups of multiple monsters do not retain their id when the level is played. Each monster in the group is its own entity, and regardless of the id you gave the group, each monster will be created with numerical id like you get from e.g. using "spawn("snail")". If you need to refer to a monster in a group you'll have to find it by some other means and get the id from that.
Good to know - let's say I create a skeleton patrol I called operatingRoomPatrol1. Would each one be, perhaps "operatingRoomPatrol1_1", "operatingRoomPatrol1_2" and so on?
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: FindEntity Not WOrking

Post by minmay »

Darsithis wrote:
minmay wrote:Groups of multiple monsters do not retain their id when the level is played. Each monster in the group is its own entity, and regardless of the id you gave the group, each monster will be created with numerical id like you get from e.g. using "spawn("snail")". If you need to refer to a monster in a group you'll have to find it by some other means and get the id from that.
Good to know - let's say I create a skeleton patrol I called operatingRoomPatrol1. Would each one be, perhaps "operatingRoomPatrol1_1", "operatingRoomPatrol1_2" and so on?
No, they would be "37" and "38" and "39" and "40" or perhaps "5281" and "5282" and "5283" and "5284" or something similar.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
Allanius2
Posts: 124
Joined: Mon Apr 14, 2014 10:12 pm

Re: FindEntity Not WOrking

Post by Allanius2 »

Would there be a way to get those id from a collection entity such as "party.getChampion(1)"?
User avatar
Leki
Posts: 550
Joined: Wed Sep 12, 2012 3:49 pm

Re: FindEntity Not WOrking

Post by Leki »

There is nothing like patrol in entities, as you can see here: http://www.grimrock.net/modding/asset-d ... reference/
Patrol is only some kind of tricky monster group manager. Try for example to write script like: for each entities in cell, if monster, setPosition to x+1, y+1. It will split the patrol into 4 skeletons, each in one cell, but they will move all in the same way. There in one "leading" monster, who has AI and collision (you can go through 3 of them freely now) and rest of the group are only puppets, until the lead monster dies etc. So no, you cannot work with patrol. It's only some kind of hack.
If you wanna open the door, when patrol is dead, you can do it in many ways. Without clone monsters and let me say easiest way is:
- you can add monster blocker in front of room with patrol and doors, to keep patrol of monsters in area (and monsters from dungeon out of the room
- on entrance into room add invisible once party trigger plate and start that one, or two or three sec timer
- timer will run script each sec or two or three, depends how intense interval you want
- in script just set local m = 4, theh do entitiesAt(level, x, y) over all cells in room (make array for x and y, where cells can be defined)
- if entity.class = "Monster", local m = m - 1
- after cell loop do if m = 0 open door and deactivate timer, else m = 4
But depends what you want to achieve and how complex your room is etc.
I'm the Gate I'm the Key.
Dawn of Lore
Post Reply