MODULE: BackgroundSpeech v0.5b

Started by Bernie, Thu 07/07/2005 19:00:36

Previous topic - Next topic

Bernie

I loved how the character in No-Action Jackson was able to talk and you could still control him. Here's a way to code this:

Note: the DisplaySpeechBackgroundEx() and IsCharacterSpeeching() functions were originally posted by Scorpiorus.

Note #2: This uses old-style scripting.

Code: ags

//this goes into header script:

import function DisplaySpeechBackgroundEx(int CharID, string speech);
import function Reset(int overlay);
import function IsCharacterSpeeching(int CharID);
import function SetIdle(int CharID, int View);


//top of global script:

#define AGS_CHARACTER_MAX 150
int bank[AGS_CHARACTER_MAX];

function Reset(int overlay) {

   int i=0;
   while (i<AGS_CHARACTER_MAX) {
      if (bank[ i ]==overlay) bank[ i ]=0;
      i++;
   }
}


function DisplaySpeechBackgroundEx(int CharID, string speech) {
   
   int overlay = DisplaySpeechBackground(CharID, speech);
   Reset(overlay);
   bank[CharID] = overlay;
}


function IsCharacterSpeeching(int CharID) {
   return IsOverlayValid(bank[CharID]);
}

int idle[150];

function SetIdle(int CharID, int View) {
  
idle[CharID]=View;
SetCharacterIdle(CharID, View,0);

}


//game start:

int a=0;
while (a<150) {
idle[a]=-1;
a=a+1;
}


//repeatedly_execute_always:

int a=0;

while (a < GetGameParameter(GP_NUMCHARACTERS, 0, 0, 0)){

if (character[a].Animating==0){
  if (character[a].Speaking==0){

    if (IsCharacterSpeeching(a)==1) {if (character[a].IdleView != character[a].SpeechView) {
    SetCharacterIdle(a, character[a].SpeechView, 0);}}

  if (IsCharacterSpeeching(a)==0) {if (character[a].IdleView == character[a].SpeechView) {

if (idle[a] != character[a].IdleView) {SetCharacterIdle(a, idle[a], 0);}}}}
}

a=a+1;  
}


Use SetIdle() to set an idle view for the character if needed. These kick in instantly, so if you need pausing in that animation, you'll have to do it through animations.

DisplaySpeechBackgroundEx() will let your character do background talking and also display the speech view when he's standing.

Drawback #1: The idle animations won't have a starting timer anymore, but it can be through the idle animation instead (long pause on first frame, etc.)

Drawback #2: The speech view and idle view speeds will need some adjusting.

Other than that this seems to work just fine.

Lazarus

Hi I'm having a look at your background speech module and I cannot seem to get the speech to display all of the converstation in that it just displays the last line.
eg. BackgroundSpeech.Say(cRoger, "What can I do for you? ");

I loaded the module ok, and I've then placed the background speech as a run script in the repeatedly_execute for the room.

In the run script I have

BackgroundSpeech.IsCharacterSpeaking(cEgo);
BackgroundSpeech.IsCharacterSpeaking(cRoger);


BackgroundSpeech.Say(cEgo, "Hello");Ã, 
BackgroundSpeech.Say(cRoger, "Nice to meet you");
BackgroundSpeech.Say(cEgo, "it's a lovely day");Ã, 
BackgroundSpeech.Say(cRoger, "What can I do for you? ");

any help would be grateful
*Currently using AGS Editor 2.70 (Build 2.70.601)*

Bernie

If you want to use this module for whole conversations, you could do that with some pretty simple repeatedly execute code:

int queue;
function repeatedly execute() {

if ((BackgroundSpeech.IsCharacterSpeaking(cEgo)==0) && (BackgroundSpeech.IsCharacterSpeaking(cRoger)==0)) {queue = queue + 1;}

if (queue == 1) { BackgroundSpeech.Say(cEgo, "Hello."); }
if (queue == 2) { BackgroundSpeech.Say(cRoger, "What a lovely day!"); }
if (queue == 3) { BackgroundSpeech.Say(cEgo, "Meep!"); }
// ...and so on.
}

I didn't check if the code is error free, but it should explain how to do this. :)

A�rendyll (formerly Yurina)

What exactly does this script? Does it display a background behind the text, or is it something else?
Yuna: Give me a Y!
Rikku: Give me an R!
Paine: Give me a break...
~Final Fantasy X-2

I've been

Bernie

This lets a character speak in Lucas Arts-style but doesn't pause the game while it does so. You can still walk around while the character is talking and the speech view will be shown while it's standing. Games like Day of the Tentacle had that.

Bernie

#5
A bug has been found in v0.5 of this module. If two or more characters background-talk for a while, it will make all involved characters display the speech animation. I tried to fix it but couldn't figure out how - lack of coding skills, I presume.

My old code works without problems, so I've decided to make that version available: http://www.origamihero.com/files/bgs05a.scm

To use it in versions above 2.70, deactivate 'enforce new-style strings' and 'enforce object-based scripting'. No special settings are neccessary for v2.70 and below.

DisplaySpeechBackgroundEx(character,text) will display speech and animate the character, and IsCharacterSpeeching(character) lets you find out if a character is background-speaking.

I have yet to figure out how to convert this thing to object-based scripting, so it may take a while until such a version is available.

Bernie

#6
Looks like the one in my last post doesn't work with 2.71. However, this one does and features the same functions:

http://www.origamihero.com/files/bgs05a271.scm (AGS 2.71 and below, not ObjectOrientified)

and...

http://www.origamihero.com/files/bgs05b.scm (AGS 2.72 and higher)

(Right-clicking it and choosing 'Save Target As...' should get it going.)

All you need to do is to import it through the module manager, then the two commands DisplaySpeechBackgroundEx() and IsCharacterSpeeching() are usable (05a version).

LilFoxwoman

Ok I downloaded and imported it but now it shows no Speechanimation anymore.

Bernie

Hmm, that's strange. I tried it and it works just fine. Just to be sure, did you...

1. Assign a speech view to the character?
2. Use DisplaySpeechBackgroundEx (and not DisplaySpeechBackground)?
3. Not call it from repeatedly_execute repeatedly?

If you call it from repeatedly_execute, you need to make sure the command is only run once. If you want to try it out, the best way is through a keypress.

LilFoxwoman

#9
Yes I use the repeatedly_execute, but after each Sentence the character animates and after this animation say the next one. I show you my script:

Code: ags

// script for room: Repeatedly execute

  met=Random(400);
  if (met==1) {
    spruch=Random(3);
    SetObjectFrame(7,158,0,0);
    if (spruch==0) DisplaySpeechBackgroundEx(GER, "Ds Leehbn is sooo ungereschd!");
    if (spruch==1) DisplaySpeechBackgroundEx(GER, "Warum? Waaarum nur?");
    if (spruch==2) DisplaySpeechBackgroundEx(GER, "Thor soll eusch Rehe zermatschn!");
    if (spruch==3) DisplaySpeechBackgroundEx(GER, "Noch ein Schlugg!");
    SetCharacterView(GER, 182);
    SetObjectView(7, 158);
    AnimateCharacter(GER, 0,5,1);
    AnimateObject(7,0,5,1);
  }


Before you fixed the module, the speechanimation worked...

Bernie

#10
Ah... make sure your character is not animating while DisplaySpeechBackgroundEx() is active. It won't show the talking view if a characters is animating. Call ReleaseCharacterView() first:

Code: ags

// script for room: Repeatedly execute

  met=Random(400);
  if (met==1) {
    spruch=Random(3);
    ReleaseCharacterView(GER);
    SetObjectFrame(7,158,0,0);
    if (spruch==0) DisplaySpeechBackgroundEx(GER, "Ds Leehbn is sooo ungereschd!");
    if (spruch==1) DisplaySpeechBackgroundEx(GER, "Warum? Waaarum nur?");
    if (spruch==2) DisplaySpeechBackgroundEx(GER, "Thor soll eusch Rehe zermatschn!");
    if (spruch==3) DisplaySpeechBackgroundEx(GER, "Noch ein Schlugg!");
  }

  if ((IsCharacterSpeeching(GER)==0) && (character[GER].Animating==0)) {
    SetCharacterView(GER, 182);
    AnimateCharacter(GER, 0,5,1);
    SetObjectView(7, 158);
    AnimateObject(7,0,5,1);
  }

LilFoxwoman

Ok now its working!Ã,  :D

Thank you very much!!!


SMF spam blocked by CleanTalk