// All these functions are for use with the Adventure Game // Studio (AGS), available at www.adventuregamestudio.co.uk // greGAMES! provides no warranty, explicit or implicit, // for the use of these functions. Caveat scriptor. // Display room or global message messageNumber as speech // from character charID. // By using myDisplayMessage() instead of DisplayMessage() // or DisplaySpeech(), you can edit all speech from the // message windows without having to use that obnoxious // "Display Message As:" field. function myDisplayMessage(int charID, int messageNumber) { string buffer; GetMessageText(messageNumber, buffer); DisplaySpeech(charID, buffer); } // Same as built-in function PlaySound(), but blocks until // soundID is finished. // In addition to sound effects, this function will block // on speech and frame sounds. function playSoundBlocking (int soundID) { PlaySound(soundID); while (IsSoundPlaying() == 1) Wait(1); } // Play music track if it's not already playing. // If two rooms have the same music, playIfNew() ensures // that the music doesn't reset upon moving between them. function playIfNew(int track) { if (GetCurrentMusic() != track) PlayMusic(track); } // charID says messageNumber unless it's been said before, // as tracked by globalVar. function onlyOneTime(int charID, int messageNumber, int globalVar) { if (GetGlobalInt(globalVar) == 0) { myDisplayMessage(charID, messageNumber); SetGlobalInt(globalVar, 1); } } // Teleport charID to specified room at coordinates x,y. // Don't use this function while charID is moving. function teleportCharacter(int charID, int room, int x, int y) { character[charID].room = room; character[charID].x = x; character[charID].y = y; } // Display messageID above the inventory as character INV. // INV is meant to be invisible with the same speech color // as EGO, so it appears that EGO is speaking. function invMessage(int messageID) { // The inventory GUI pauses the game, mucking up speech. // Accordingly, invMessage unpauses and pauses the game. // If you have any timers running, make sure they don't // expire in the middle of this function, or your game // can freeze. To do this, encapsulate all references to // IsTimerExpired() in (if IsGUIOn(INVENTORY) == 0). int gamePaused = IsGamePaused(); teleportCharacter(INV, character[EGO].room, GetViewportX() + 160, 12); if (gamePaused == 1) UnPauseGame(); myDisplayMessage(INV, messageID); if (gamePaused == 1) PauseGame(); } // If EGO has inventory item invID, return 1. // Otherwise, return 0. function hasInv(int invID) { return character[EGO].inv[invID]; } // Move charID relative to his current position by // coordinates xOffset, yOffset. function moveRelative(int charID, int xOffset, int yOffset) { MoveCharacterBlocking(charID, character[charID].x + xOffset, character[charID].y + yOffset, 0); } // Face charID in a particular direction. // direction can be "left", "right", "down", or "up". function faceDirection(int charID, string direction) { int xCoord = character[charID].x; int yCoord = character[charID].y; if (StrComp(direction, "left") == 0) { xCoord = -700; // -= 1; } else if (StrComp(direction, "right") == 0) { xCoord = 700; // += 1; } else if (StrComp(direction, "down") == 0) { yCoord = 700; // += 1; } else { // StrComp(direction, "up") == 0 yCoord = -700; // -= 1; } FaceLocation(charID, xCoord, yCoord); } // Move character mover to character moveTo, adjusted by // xOffset + delta, yOffset + delta. // delta is a built-in value, currently 25. function moveToCharacter(int mover, int moveTo, int xOffset, int yOffset) { int delta; if (character[mover].x < character[moveTo].x) { delta = -25; } else { delta = 25; } MoveCharacterBlocking(mover, character[moveTo].x + delta + xOffset, character[moveTo].y + yOffset, 0); FaceCharacter(mover, moveTo); } // Face character charID toward object objected. // This can look strange if you don't have diagonal loops. function faceObject(int charID, int objectID) { FaceLocation(charID, GetObjectX(objectID), GetObjectY(objectID)); }