I asked this question before (years ago) and somehow got it to work, but I've lost the notes I made and I don't have the same game I was experimenting with it in. So far every which way I've tried to implement this it doesn't work right.
I'm trying to make a NPC spawn inside a room when the player walks on a region, the NPC walks to a certain location, then stops moving and should begin a different animation.
In this iteration of the code everything works until the NPC stops, the new animation never triggers. I can't figure out what I'm doing wrong?
Any help would be appreciated. Thanks!
function repeatedly_execute_always()
{
if (cMarauder.Room != 70 && SPAWN_MARAUDER == 1)
{
cMarauder.ChangeRoom (70, 1460, 340, eDirectionLeft);
cMarauder.Walk (965, 335, eNoBlock, eWalkableAreas);
if (cMarauder.x == 965) {
cMarauder.LockView (45);
cMarauder.Animate (0, 5, eRepeat, eNoBlock);//IDLE, GUARDING DOORWAY
}
}
}
Your coordinate check is inside the first check, so it'll never happen.
function repeatedly_execute_always() {
if (cMarauder.Room != 70 && SPAWN_MARAUDER == 1)
{
cMarauder.ChangeRoom(70, 1460, 340, eDirectionLeft);
cMarauder.Walk(965, 335); // eNoBlock, eWalkableAreas is both the default
}
// we need to check for the view, otherwise this will keep firing
if (cMarauder.x == 965 && cMarauder.View != 45) {
cMarauder.LockView(45);
cMarauder.Animate(0, 5, eRepeat, eNoBlock); // IDLE, GUARDING DOORWAY
}
}
The above should work, although I'd use a different approach:
a) I'd use a variable that indicates the state of the marauder
b) I'd use cMarauder.SetIdleView(...) in case I decide the marauder is supposed to walk elsewhere later
Thanks so much, you're right SetIdleView is better because I can interact with him or have him do something else, here's what I'm using in case it might help someone else too.
function repeatedly_execute_always()
{
if (cMarauder.Room != 70 && SPAWN_MARAUDER == 1)
{
cMarauder.ChangeRoom(70, 1460, 340, eDirectionLeft);
cMarauder.Walk(965, 335); // eNoBlock, eWalkableAreas is both the default
}
// we need to check for the view, otherwise this will keep firing
if (cMarauder.x == 965 && cMarauder.View != 45) {
cMarauder.SetIdleView (45, 1);// IDLE, GUARDING DOORWAY
}
Great, you should probably use cMarauder.IdleView != 45 though.
Actually, scratch that. The IdleView kicks in automatically when the character stops walking, so you don't even need the second if-block. Just set the IdleView in room_Load or game_start.