Teleporting Characters and

Started by , Thu 17/03/2005 02:00:50

Previous topic - Next topic

John

Dear AGS Powers That Be,

1. Is there a way to teleport a character to a given spot on the screen? Ã, (I'm looking for something that has the effect of this function but isn't illegal:

function teleport(int charID, int newX, int newY) {
Ã,  character[EGO].x = newX;
Ã,  character[EGO].y = newY;
}

2. Also, based on a boolean value, is it possible to respond with the same message whenever you try to look at or interact with an object? Ã, (In my game, EGO can seal himself inside a box, so it doesn't make sense for him to be able to "see" the objects in the room.)

Thank you!

strazer

#1
1. The safest way is this:

Code: ags

function teleport(int charID, int newX, int newY) {
  if (charID == GetPlayerCharacter()) // if the character is the player character
    NewRoomEx(character[GetPlayerCharacter()].room, newX, newY); // put player in current room at new coordinates
  else // if character is a non-player character (NPC)
    NewRoomNPC(charID, character[GetPlayerCharacter()].room, newX, newY); // put NPC in current room at new coordinates
}


These are room coordinates. If you really want to pass screen coordinates, add GetViewPortX/Y to the newX and newY variables first.

2. Sure:

Code: ags

// room script

int IsPlayerInBox = 0; // declare room variable storing if player has himself sealed in box


function object0_a {
  // script for object0: Interact with object

  if (IsPlayerInBox == 1) { // if player is sealed in box
    // code for player getting himself out of box
    IsPlayerInBox = 0;
  }
  else { // if player is NOT sealed in box
    // code for player sealing himself in box
    IsPlayerInBox = 1;
  }

}


function on_mouse_click() {

  if (GetCursorMode == MODE_LOOK) { // if mouse is in look mode
    if (IsPlayerInBox == 1) { // if player is sealed in box
      DisplaySpeech(GetPlayerCharacter(), "I can't see anything.");
      ClaimEvent(); // don't run global on_mouse_click afterwards (i.e. don't run any look interactions)
    }
  }

}

SMF spam blocked by CleanTalk