User Tag List

Results 1 to 6 of 6

Thread: NPC Follower

  1. #1
    &&
    ZC Developer
    Joe123's Avatar
    Join Date
    Sep 2006
    Age
    32
    Posts
    3,061
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    7,303
    Level
    26
    vBActivity - Bars
    Lv. Percent
    8.74%

    NPC Follower

    Example Quest

    This script will have an ffc follow right behind Link whilst walking around.
    It's based on me watching the behaviour from Terranigma, but it should work the same as when you have Marin in tow in Link's Awakening, for example.

    You should arrange the NPC's combos like this:
    Code:
    Still Up   | Still Down   | Still Left   | Still Right
    Walking Up | Walking Down | Walking Left | Walking Right
    And set the ffc's combo to the first one.
    If you want it to work for more than one screen, the 'Carryover' flag is advised.
    You could probably set it up to work ok-ish with the 'No FFC Carryover' screen flag, but if you wanted anything more complicated you'd need some sort of script to toggle when this one functions, but obviously that's very much dependant on your quest so I can't write it to work for everyone.

    Thanks to LinkTheMaster for the 'FFCToPoint' function

    Code:
    const int M_NORMAL			= 0;
    const int M_MOVINGTOPOS		= 1;
    const int M_SOLIDATPOS		= 2;
    
    ffc script FollowLink{
    	void run(){
    		int orig = this->Data;
    		int lastDir;
    		int MovementState;
    		int CurrentScreen;
    		int idle;
    		while(true){
    			int x = Link->X; int y = Link->Y;
    			if(Link->Dir == DIR_UP||Link->Dir == DIR_DOWN) y -= Link->Dir*32-16;
    			else x -= (Link->Dir-2)*32-16;
    			
    			if(CurrentScreen != Game->GetCurScreen()) MovementState = NormalPlacement(this,x,y);
    			if(MovementState == M_NORMAL){
    				if(lastDir != Link->Dir) MovementState = MoveToPosition(this,x,y);
    				else MovementState = NormalPlacement(this,x,y);
    			}else if(MovementState == M_MOVINGTOPOS) MovementState = WhileMoving(this,x,y,idle);
    			else if(MovementState == M_SOLIDATPOS) MovementState = CheckPos(this,x,y);
    			
    			SetGraphics(this,orig);
    			CurrentScreen = Game->GetCurScreen();
    			idle = (idle+1)%6;
    			lastDir = Link->Dir;
    		Waitframe();
    		}
    	}
    	int NormalPlacement(ffc this,int x,int y){
    		if(Solid(this,x,y)) return M_SOLIDATPOS;
    		this->X = x; this->Y = y;
    		return M_NORMAL;
    	}
    	int MoveToPosition(ffc this,int x,int y){
    		if(Solid(this,x,y)) return M_SOLIDATPOS;
    		int speed = Distance(x,y,this->X,this->Y)/8;
    		if(speed < 0.5) return M_NORMAL;
    		else if(speed < 1.2) speed *= 2;
    		FFCToPoint(this,x,y,speed);
    		return M_MOVINGTOPOS;
    	}
    	int WhileMoving(ffc this,int x,int y,int idle){		
    		if(Abs(this->X-x) < 3 && Abs(this->Y-y) < 3){
    			this->Vx = 0; this->Vy = 0;
    			return M_NORMAL;
    		}
    		
    		if(idle == 0) return MoveToPosition(this,x,y);
    		return M_MOVINGTOPOS;
    	}
    	int CheckPos(ffc this,int x,int y){
    		if(Solid(this,x,y)) return M_SOLIDATPOS;
    		return MoveToPosition(this,x,y);
    	}
    	bool Solid(ffc this,int x,int y){
    		if(Screen->isSolid(x+8,y+8)){
    			this->Vx = 0; this->Vy = 0;
    			return true;
    		}
    	}
    	void SetGraphics(ffc this,int orig){
    		int moving;
    		if(Link->InputUp || Link->InputDown || Link->InputLeft || Link->InputRight
    		  || this->Vx != 0 || this->Vy != 0) moving = 4;
    		this->Data = orig+moving+Link->Dir;
    	}
    	int FFCToPoint(ffc f,int x,int y,int speed){
    		if(speed == 0) return -1;
    		int dx = x-f->X; int dy = y-f->Y;
    		int dis = Abs(dx) + Abs(dy);
    		int d = dis/speed;
    		f->Vx = dx/d; f->Vy = dy/d;
    		return d;
    	}
    }

  2. #2
    Octorok
    Join Date
    Nov 2006
    Age
    29
    Posts
    463
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    1,770
    Level
    14
    vBActivity - Bars
    Lv. Percent
    8.15%

    Re: NPC Follower

    It's not working in the example version. What build does this use?

    Click here to level up my card, or be sacrificed... ^_^

    Want to see Shattered Earth, AGN's RPG, back? Got a computer that is capable of running a server? PM me!

  3. #3
    &&
    ZC Developer
    Joe123's Avatar
    Join Date
    Sep 2006
    Age
    32
    Posts
    3,061
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    7,303
    Level
    26
    vBActivity - Bars
    Lv. Percent
    8.74%

    Re: NPC Follower

    Oh wouldja look at that, I accidently cleared the buffer before I posted the test quest.
    Now that was a bit silly of me wasn't it.

    Try again now.

  4. #4
    Octorok
    Join Date
    Nov 2006
    Age
    29
    Posts
    463
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    1,770
    Level
    14
    vBActivity - Bars
    Lv. Percent
    8.15%

    Re: NPC Follower

    Heh, you uploaded the key to the heavens scripts into the buffer.

    If it's included in there, it still isn't working, it might be me, but I dunno.

    Still, this script sounds great.

    Click here to level up my card, or be sacrificed... ^_^

    Want to see Shattered Earth, AGN's RPG, back? Got a computer that is capable of running a server? PM me!

  5. #5
    Octorok Beta Link's Avatar
    Join Date
    Jan 2007
    Age
    31
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    1,125
    Level
    11
    vBActivity - Bars
    Lv. Percent
    52.14%

    Re: NPC Follower

    Quote Originally Posted by Joe123
    but it should work the same as when you have Marin in tow in Link's Awakening, for example.
    Mwahahahaha!!!

    *Yoinks*


    You are made of epic win, Joe.

  6. #6
    &&
    ZC Developer
    Joe123's Avatar
    Join Date
    Sep 2006
    Age
    32
    Posts
    3,061
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    7,303
    Level
    26
    vBActivity - Bars
    Lv. Percent
    8.74%

    Re: NPC Follower

    Oh, oops =P

    Well it's working for me now...


    Glad you like it Beta Link =)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Armageddon Games is a game development group founded in 1997. We are extremely passionate about our work and our inspirations are mostly drawn from games of the 8-bit and 16-bit era.
Social