Walking to a NPC using FOA template (SOLVED)

Started by cjhrules, Thu 31/08/2006 10:12:30

Previous topic - Next topic

cjhrules

Usually "EGO" Walks to a character and stops at a distance at say 30px, but on one character I want "EGO" to move closer.( to a specific x,y cord )If I use MoveCharBlocking... he first walks to the point he was surposed to walk to acording to the foa template and after that he walks to the x, y cord I instructed. It looks wierd... I want to make some kind of exception on this one character... Is it possible?

strazer

What template are you talking about? Link?
Isn't there a thread for that template where you can ask? If not, have you tried contacting the template's author directly?

And please tell us what code you're trying to use exactly, and where you have put it.

cjhrules

Hi!
here is the code for character click form the global script:

Code: ags

function WalkToCharacterEx(int charidwhogoes, int charidtogo, int direction, int xoffset, int yoffset, int NPCfacesplayer, int blocking){
  //Goes to a character staying at the side defined by 'direction': 1 up, 2 right, 3 down, 4 left
  //and it stays at xoffset or yofsset from the character. NPCfacesplayer self-explained. ;)
  // blocking: 0=non-blocking; 1=blocking; 2=semi-blocking.
  // returns 1 if player arrived.
  int playerchar,charidx,charidy,playerx,playery;
  if (charidwhogoes!=GetPlayerCharacter() && blocking==2) blocking=0;//npcs cant perform semi-blocking actions
  playerchar=charidwhogoes;
  charidx=character[charidtogo].x;
  charidy=character[charidtogo].y;
  playerx=character[playerchar].x;
  playery=character[playerchar].y;
      int arrived = 1;
      if ((Offset (playerx, charidx) > xoffset) || (Offset (playery, charidy) > yoffset)){
        if (direction==0){ // shortest way.
          if (Offset(charidx,playerx)>=Offset(charidy,playery)){ // left or right
            if (playerx>=charidx) direction=2; //right
            else direction=4; //left
          }
          else{
            if (playery>=charidy) direction=3; //down
            else direction=1;
          }
        }
        // calculate target position
        if (direction==1) charidy-=yoffset;
        else if (direction==2) charidx+=xoffset;
        else if (direction==3) charidy+=yoffset;
        else if (direction==4) charidx-=xoffset;
        // move character
        if (blocking==0){
          MoveCharacter(playerchar,charidx,charidy);
          arrived = 0;
        }
        else if (blocking==1){
          MoveCharacterBlocking(playerchar,charidx,charidy,0);
          arrived = 1;
        }
        else if (blocking==2) arrived = MovePlayer(charidx,charidy);
      }
      if (arrived > 0){
        // characters only face each other after the moving character arrived at the target point
        if (NPCfacesplayer==1)  FaceCharacter(charidtogo, playerchar);
        FaceCharacter(playerchar, charidtogo);
      }
      return arrived;
}

function GoToCharacter(int charid, int direction, int NPCfacesplayer, int blocking){
  //same as above but with default x and y offset.
  int defaultxoffset, defaultyoffset;
  defaultxoffset=25;
  defaultyoffset=15;
  return WalkToCharacterEx(GetPlayerCharacter(),charid,direction,defaultxoffset,defaultyoffset,NPCfacesplayer,blocking);
}


The thing is I really don't want to change it since it's only a problem for one character.

a-v-o

The distance in which the walking character stops before the target character is defined in xoffset and yoffset. So, if you want the walking character to walk closer, then just use smaller values (or 0 Zero) for xoffset and yoffset.

Quote
he first walks to the point he was surposed to walk to acording to the foa template and after that he walks to the x, y cord I instructed
You said, that you have the coordinates, so why do you use WalkToCharacterEx and not e.g. MovePlayer (x, y)?

cjhrules

but I only want this for one chracter so I really don't want to change the script. I only have cordinates for this one character. I have tried to make him an object but It seems that you can't talk to an object.... maybe that is also because of the foa template

Khris

a-v-o didn't suggest to change the global script.

The function causing the player walk to the default distance is called right in the on_mouse_click function, so you won't get around changing the script.

This doesn't mean that the player will always get closer, though, try this:

Code: ags
function GoToCharacter(int charid, int direction, int NPCfacesplayer, int blocking){
Ã,  //same as above but with default x and y offset.
Ã,  int defaultxoffset, defaultyoffset;
Ã,  if (character[charid]==cGuy) {Ã,  Ã,  Ã, // change cGuy to your NPCÃ,  Ã,  Ã,  Ã,  EDIT
Ã,  Ã,  return MovePlayer(x, y);Ã,  // change to the specific coordsÃ,  Ã,  Ã,  Ã,  Ã, EDIT
Ã,  }
Ã,  else {
Ã,  Ã,  defaultxoffset=25;
Ã,  Ã,  defaultyoffset=15;
Ã,  Ã,  return WalkToCharacterEx(GetPlayerCharacter(),charid,direction,defaultxoffset,defaultyoffset,NPCfacesplayer,blocking);
Ã,  }
}


cjhrules


SMF spam blocked by CleanTalk