Author Topic: Walking to a NPC using FOA template (SOLVED)  (Read 522 times)  Share 

Walking to a NPC using FOA template (SOLVED)
« on: 31 Aug 2006, 10:12 »
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?
« Last Edit: 04 Sep 2006, 23:42 by strazer »

Re: Question about walk to NPC char using foa temp.
« Reply #1 on: 01 Sep 2006, 11:40 »
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.

Re: Question about walk to NPC char using foa temp.
« Reply #2 on: 01 Sep 2006, 13:12 »
Hi!
here is the code for character click form the global script:

[code]
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);
}

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

a-v-o

  • delphi programmer
    • I can help with proof reading
    •  
Re: Question about walk to NPC char using foa temp.
« Reply #3 on: 03 Sep 2006, 14:53 »
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)?

Re: Question about walk to NPC char using foa temp.
« Reply #4 on: 03 Sep 2006, 16:00 »
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

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: Question about walk to NPC char using foa temp.
« Reply #5 on: 04 Sep 2006, 18:20 »
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]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);
  }
}[/code]
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

Re: Question about walk to NPC char using foa temp.
« Reply #6 on: 04 Sep 2006, 23:39 »
YES! THX!  :)