Page 1 of 1

Making a monster move on a predefined path?

Posted: Sun Sep 16, 2012 4:38 pm
by Ixnatifual
Is it possible to make a monster follow a certain path somehow?

Re: Making a monster move on a predefined path?

Posted: Sun Sep 16, 2012 4:40 pm
by petri
At least in theory you could disallow moving and turning towards tiles that are not on the predefined path using onMove and onTurn hooks. Good luck! :)

Re: Making a monster move on a predefined path?

Posted: Thu Sep 20, 2012 8:16 pm
by Ixnatifual
I've used blockers instead. The problem is you're just telling it where it can't go, which means that while it's spotted the player in a different direction, it's not gonna move off on the path anytime soon. Perhaps a feature request could be made to put a "monster target" entity in a level and set a monster to target that entity instead of the party when moving. A lot of interesting monster manipulation could be done this way.

Re: Making a monster move on a predefined path?

Posted: Thu Sep 20, 2012 8:19 pm
by ScroLL
Is it possible for us to script our own AI states?

Re: Making a monster move on a predefined path?

Posted: Fri Sep 21, 2012 12:49 am
by Favashi
Hi!!

I was trying to do the same for my dungeon. So far I've managed to do for one monster. I think doing some modification may work for various monsters (perhaps creating an array of ids of monsters with two array mappings).

With this setup I got the monster follow the path marked in green.

Image

First you have to make a clone of the monster in the file "monsters.lua", put in the following code:

Code: Select all

cloneObject{
    name="skeleton_guard",
    baseObject = "skeleton_warrior",
    onMove = function(self, dir)
	   return movScript.chekMovement(dir)
    end,

    onTurn = function(self, dir)
       return movScript.checkTurn(dir)
    end,
}
We then create an instance of the script in the editor (I have followed the example of the spider eggs)

The script code is as follows:

Code: Select all

curr_pos = 1
mov_map  = {1,1,1,1,2,2,2,2,1,1,1,1,0,0,0,0,3,3,3,3}
turn_map  = {0,0,0,0,1,0,0,0,-1,0,0,0,-1,0,0,0,-1,0,0,0,1}

function chekMovement(dir)
	print("MOVE =>",curr_pos)
	if curr_pos >= table.getn(mov_map) then
		curr_pos = 1
	end
	if dir ~= mov_map[curr_pos] then
		return false
	end
	curr_pos = curr_pos + 1
	return true
end

function checkTurn(dir)
    print("TURN =>",curr_pos)
	if dir ~= turn_map[curr_pos] then
		return false
	end
	return true
end
Sorry for my bad English...

Re: Making a monster move on a predefined path?

Posted: Fri Sep 21, 2012 1:17 am
by Montis
What happens when you move behind the monster? I could imagine it just gets stuck since tries to turn to you but can't?

Re: Making a monster move on a predefined path?

Posted: Fri Sep 21, 2012 10:41 am
by Favashi
Well, according to the tests I've done, when monsters detects the party group, they try turning in his direction, but as always receive false to turn, they could not. I think the script can be improved a lot. I did it last night something quick.

Maybe there is another way to do it. A hook can be added to the "onDamage" event to cancel this behavior. It would be interesting if there was an event when they detect the party group for cancel this behaviour.