Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Gepard on Sat 24/02/2007 07:08:18

Title: multiple if´s - SOLVED
Post by: Gepard on Sat 24/02/2007 07:08:18
I have an area divided into A, B and C. There is a XYX character in C. Now I want to do it like this: After player character do something in B, he have enough time to go to A. Now after this time (timer) I want XYX to come from C to B and at this point (XYX standing in B area) I want the game to consider wheter player character is on region A or not. Now I cannot do this with regions, because XYX is not a player character. Can anyone help me?

Thanks
Title: Re: multiple if´s
Post by: Gepard on Sat 24/02/2007 07:09:01
I was also trying to do this with: ischaractercollidingwithobject, but didnt help me.
Title: Re: multiple if´s
Post by: Scorpiorus on Sat 24/02/2007 08:23:13
Yes you cannot use region events for NPC, therefore you need to manually check if they are standing on a region by using the Region.GetAtRoomXY() (http://www.adventuregamestudio.co.uk/manual/Region.GetAtRoomXY.htm) function within the repeatedly execute event:

on doing something while on B (ie. interact object/hotspot or something):



Ã,  Ã,  SetTimer( 1, 400 ); // set timer #1 for 400 game loops




room's repeatedly execute:


Ã,  Ã,  if ( IsTimerExpired(1) )
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  character[XYZ].Walk( REGION_B_X, REGION_B_Y, eNoBlock, eAnywhere );
Ã,  Ã,  }

Ã,  Ã,  // check if XYZ NPC is on the region B
Ã,  Ã,  if ( Region.GetAtRoomXY( character[XYZ].x, character[XYZ].y ) == region[REGION_B_NUMBER] )
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  if ( Region.GetAtRoomXY( player.x, player.y ) == region[REGION_A_NUMBER] )
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  // player is on region A
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  else
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  // player is not on region A
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  }
Title: Re: multiple if´s
Post by: Gepard on Sat 24/02/2007 10:21:08
Now its working, that is great, but I just cannot stop it. For example if I put display message instead of //player is on region A, it will be there for ever. What to do now? Thanks for the help by the way.
Title: Re: multiple if´s
Post by: Scorpiorus on Sat 24/02/2007 10:28:26
Ah yeah, you just need to set a flag to not trigger it again. Region.Enabled should do fine in this case:


Ã,  Ã,  if ( IsTimerExpired(1) )
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  character[XYZ].Walk( REGION_B_X, REGION_B_Y, eNoBlock, eAnywhere );
Ã,  Ã,  }

Ã,  Ã,  // check if XYZ NPC is on the region B
Ã,  Ã,  if ( Region.GetAtRoomXY( character[XYZ].x, character[XYZ].y ) == region[REGION_B_NUMBER] )
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  if ( Region.GetAtRoomXY( player.x, player.y ) == region[REGION_A_NUMBER] )
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  // player is on region A
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  else
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  // player is not on region A
Ã,  Ã,  Ã,  Ã,  }

Ã,  Ã,  Ã,  Ã,  region[REGION_B_NUMBER].Enabled = false; // disable the region so it won't trigger the event again

Ã,  Ã,  }
Title: Re: multiple if´s
Post by: Gepard on Sat 24/02/2007 10:38:42
Thanks a lot!