Author Topic: enabling hotspots/regions depending on NPCs room  (Read 293 times)  Share 

DrakeStoel

  • Believe it or not...
    • I can help with voice acting
    •  
I'm trying to make it so that when a guard is in a particular room, a hotspot becomes available, and a region preventing you from moving on disappears. This is the code I'm using:

Code: Adventure Game Studio
  1. function room_AfterFadeIn()
  2. {
  3.     if (player.PreviousRoom == 9) player.Walk(500, 260, eBlock, eAnywhere);
  4.    
  5.     if (cMGrd.Room == 1){
  6.       hMansionDoor.Enabled = true;
  7.       region[1].Enabled = false;
  8.     }
  9.     else if (cMGrd.Room == 10){
  10.       hMansionDoor.Enabled = false;
  11.       region[1].Enabled = true;
  12.     }
  13.     else Unhandled();
  14. }

When I run the game, the hotspot is already on, and the region is still there. Anyone's help would be greatly appreciated  :grin:

Andail

  • Global Moderator
  • Mittens Baronet
  • Cultured man of mystery
    • I can help with backgrounds
    •  
Re: enabling hotspots/regions depending on NPCs room
« Reply #1 on: 11 Aug 2012, 12:44 »
First of all, why not use a walkable area to decide where the player can and cannot go?

Second, mind that you're blocking the rest of the script when the player is instructed to walk with an eBlock. So the hotspots and stuff aren't affected until the player is done walking. One way to solve this is by handling all the enabling/disabling of hotspots and areas in the "enter room before fade-in" instead.

If nothing works, check that the other character is indeed in the specified room by having something like
function room_AfterFadeIn()
{
Display ("The guard is in room %d", cMGrd.Room);
}
or similar. Just to make sure.
« Last Edit: 11 Aug 2012, 12:47 by Andail »
Be vigilant, citizen!
Check out my GiP, The Samaritan Paradox
Also, check my blog at http://faravidinteractive.wordpress.com/

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: enabling hotspots/regions depending on NPCs room
« Reply #2 on: 11 Aug 2012, 12:54 »
Alternatively, you can move the player.Walk line below the rest of the code.
Btw, what does Unhandled() do here?
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

DrakeStoel

  • Believe it or not...
    • I can help with voice acting
    •  
Re: enabling hotspots/regions depending on NPCs room
« Reply #3 on: 11 Aug 2012, 21:23 »
Hmmmm... I tried your suggestions, but they didn't work. And I'm not sure what the else Unhandled() was for, so I took that out.
It's strange because when I try running it with the guard staring in room 1, the hotspot is on, and the region's off. But when I start with the guard where he should be, in room 10, then get rid of him, it doesn't work.

Andail

  • Global Moderator
  • Mittens Baronet
  • Cultured man of mystery
    • I can help with backgrounds
    •  
Re: enabling hotspots/regions depending on NPCs room
« Reply #4 on: 11 Aug 2012, 21:30 »
Ah.
This code won't magically update just because the guard character leaves.
You need to check this repeatedly, so put it in repeatedly execute instead.
Code: Adventure Game Studio
  1. function room_AfterFadeIn()
  2. {
  3.     if (player.PreviousRoom == 9) player.Walk(500, 260, eBlock, eAnywhere);
  4. }
  5. function room_RepExec()
  6. {
  7.     if (cMGrd.Room == 1 && hMansionDoor.Enabled != true){
  8.         hMansionDoor.Enabled = true;
  9.         region[1].Enabled = false;
  10.     }
  11.     else if (cMGrd.Room == 10 && hMansionDoor.Enabled !=false){
  12.         hMansionDoor.Enabled = false;
  13.         region[1].Enabled = true;
  14.     }
  15. }
  16.  
(I put an extra if-clause there to prevent the repeatedly execute to keep running the same function over and over again - not that it's very necessary)
« Last Edit: 11 Aug 2012, 21:35 by Andail »
Be vigilant, citizen!
Check out my GiP, The Samaritan Paradox
Also, check my blog at http://faravidinteractive.wordpress.com/

DrakeStoel

  • Believe it or not...
    • I can help with voice acting
    •  
Re: enabling hotspots/regions depending on NPCs room
« Reply #5 on: 11 Aug 2012, 21:34 »
Bingo! Thanks a bunch, it worked perfectly!

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: enabling hotspots/regions depending on NPCs room
« Reply #6 on: 12 Aug 2012, 13:44 »
Btw, assuming some AI isn't sending the guard through multiple rooms, a simpler way would be to just call the relevant commands right when you're removing the guard from the room.
Putting stuff in rep_exe is only necessary to handle reactions to situations that happen at some arbitrary point in the future.
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"