Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Duckbutcher on Tue 04/09/2007 13:44:25

Title: Lechuck Style Random Room Appearances... (SOLVED)
Post by: Duckbutcher on Tue 04/09/2007 13:44:25
Hi, I'm looking to incorporate something similar to the last segment of MI2 in my game, with a character randomly entering the same room as the player character (like LeChuck with the Voodoo Doll).
I haven't a clue how to go about doing this. It would be done over a series of rooms, which makes it even more of a headache for me.

If anyone has any suggestions at all, they would be greatly appreciated. I'm in the dark on this one.
Title: Re: Lechuck Style Random Room Appearances...
Post by: Ashen on Tue 04/09/2007 14:06:44
There's a couple of suggestions in this thread (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=29702.0). Are they any use? (I prefer KhrisMUC's, personally. It's a bit more work, but I think the result is better.)
Title: Re: Lechuck Style Random Room Appearances...
Post by: Khris on Tue 04/09/2007 14:10:49
Here's a shorter way:

Use the on_event function; something like this:
//global script

function repeatedly_execute() {
  if (IsTimerExpired(1)) {
    if (player.Room>=6 && player.Room<=9) CallRoomScript(1);   // occurs in rooms 6-9
  }
}

function on_event(EventType event, int data) {
  if (event==eEventEnterRoomBeforeFadein) {
    if (Random(2)==0) SetTimer(1, 160+Random(2)*40);  // 33% Chance of entering the Room after 4 to 6 seconds
  }
  ...
}

//room script in rooms 6-9

function on_call(int p) {
  if ([p==1) {
    // place LeChuck at an exit
  }
}
Title: Re: Lechuck Style Random Room Appearances...
Post by: Duckbutcher on Sun 09/09/2007 16:32:33
Sorry for the late reply guys, and thanks for the code, it works perfectly.

I do have another request if anyone can help me out - I'd like to have a hotspot turn alternately on and off in 4 second intervals - it's an idea I have for a real time collision based puzzle -  I was just wondering if it's possible to do this in the 'background', ie, non blocking. Any ideas?

Title: Re: Lechuck Style Random Room Appearances...
Post by: Ashen on Sun 09/09/2007 16:39:08
Timers (SetTimer / IsTimerExpired) would seem to be made for that, or you could use your own variable and repeatedly_execute. Timers would be simpler, though.