Please login or register.

Login with username, password and session length
Advanced search  

News:

Forum rules - please read before posting, it can save you a lot of time.

Author Topic: Making NPCs Follow Your Main Actor?  (Read 5251 times)

0 Members and 1 Guest are viewing this topic.

Old_Guy

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 8
    • View Profile
Making NPCs Follow Your Main Actor?
« on: September 29, 2007, 08:34:48 PM »

I'm a complete noob with a (probably) dumb question.

I am making a 2D game. It is my first shot with WME  :)
Is there a way to make selected NPC's "follow" my main actor where ever he goes (as if the NPC is being led by the hand so to speak)?
Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Making NPCs Follow Your Main Actor?
« Reply #1 on: September 29, 2007, 08:46:14 PM »

you can have a daemon script which would periodically check the X and Y position of your lead actor and then call GoTo method of support
actor. Try it and if you're still unsure, I'll post some code.
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Old_Guy

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 8
    • View Profile
Re: Making NPCs Follow Your Main Actor?
« Reply #2 on: September 29, 2007, 08:55:17 PM »

Very cool. Thanks! I'll give it a shot.
Logged

Old_Guy

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 8
    • View Profile
Re: Making NPCs Follow Your Main Actor?
« Reply #3 on: September 29, 2007, 11:03:12 PM »

The Old Guy hasn't quite been able to pull it off.  ???

And so I come a beggin' for the aforementioned code . . .please.
Logged

Daniel

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 124
  • I'm *not* a llama!
    • View Profile
Re: Making NPCs Follow Your Main Actor?
« Reply #4 on: September 29, 2007, 11:47:13 PM »

If you're referring to the same OldGuy from the demo, then if memory serves, he is an Entity and not an Actor. Entities can't walk in WME, if I recall correctly, and therefore they don't have any GoTo() method. If that is really the case, you should try what meta recommended but this time with an Actor instead of an Entity and it should work.

Oh, and welcome to the forum, by the way :)
Logged

sychron

  • Wanderer zwischen den Welten
  • Global Moderator
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 223
  • There is no spoon. The enemy gate is down!
    • View Profile
Re: Making NPCs Follow Your Main Actor?
« Reply #5 on: September 29, 2007, 11:53:48 PM »

I rather think he's referencing himself ...
Logged
... delete the inner sleep ...

Daniel

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 124
  • I'm *not* a llama!
    • View Profile
Re: Making NPCs Follow Your Main Actor?
« Reply #6 on: September 30, 2007, 01:12:17 AM »

I rather think he's referencing himself ...
Could be... I'm just not very used to people using third person to refer to themselves...
Logged

Old_Guy

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 8
    • View Profile
Re: Making NPCs Follow Your Main Actor?
« Reply #7 on: September 30, 2007, 05:23:34 AM »

Yes, he was referring to himself. Sorry for the mix up.
Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Making NPCs Follow Your Main Actor?
« Reply #8 on: September 30, 2007, 09:10:02 AM »

First of all we're going to tweak the main actor script file (it's usually called actor.script and is located in the actor's folder). We'll add here custom
method GoTo, which will override the original.

Code: [Select]
method GoTo(posx,posy)
{
   // We store some attributes to indicate, that our actor got a Go To command
   this.newWalking = true;
   this.targetX = posx;
   this.targetY = posy;
   
  // we call the original Go To
   this.GoTo(posx, posy);
}

Now we modify the script for the second actor:
Code: [Select]
#include "scripts\base.inc"

while (1)
{
  if (actor.newWalking)
  {
     actor.newWalking = false;
     if (this.IsWalking()) this.Reset();  //if our support cast already moves, stop him
     this.GoTo(actor.targetX, actor.targetY);  // send support cast to the leading role character.
  }
   Sleep(100);
}


Sorry, I can't test it right now, but should work.
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

sychron

  • Wanderer zwischen den Welten
  • Global Moderator
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 223
  • There is no spoon. The enemy gate is down!
    • View Profile
Re: Making NPCs Follow Your Main Actor?
« Reply #9 on: September 30, 2007, 12:22:05 PM »

I would add a trigger to the endless loop, something like

while (1) {
  if (isFollowing){
    your stuff here
  }
}

So you can trigger wether actor 2 should follow or not.
Logged
... delete the inner sleep ...

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Making NPCs Follow Your Main Actor?
« Reply #10 on: September 30, 2007, 01:21:58 PM »

yes but for understanding the principle it's better to present the minimal version and build on it.  ;)
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Old_Guy

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 8
    • View Profile
Re: Making NPCs Follow Your Main Actor?
« Reply #11 on: October 01, 2007, 03:10:14 PM »

Thank you very much, kind Sir   : ).
Logged

Old_Guy

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 8
    • View Profile
Re: Making NPCs Follow Your Main Actor?
« Reply #12 on: October 01, 2007, 05:09:33 PM »

Here is my final non-elegant tweaking. It seems to work great. It lets me take hold of the npc and lead it until I "re-take", which then lets go of the npc.

In the NPC's .script file:
=================
on "Take"
{
  if (this.isHeld)
   {
   this.isHeld = false; // Let go of the NPC
   }
  else
   {
   GoToObject();
   this.isHeld = true;  // Hold the NPC
   FollowHim();
   }
}


function FollowHim()
{
 while (this.isHeld)
 {
   if (actor.newWalking)
   {
     actor.newWalking = false;
     if (this.IsWalking()) this.Reset();  //if npc is already moving, stop him
     this.GoTo(actor.targetX-25, actor.targetY-25);  // send npc to the main actor
   }//end if
  Sleep(100);
 }//end while
} // end FollowHim


Many thanks  :)
Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Making NPCs Follow Your Main Actor?
« Reply #13 on: October 01, 2007, 07:05:43 PM »

the only suggestion would be to define your "following" function as a method instead of function.

This way you could also trigger the follow mode outside of the script through:

npc.FollowHim();
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Old_Guy

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 8
    • View Profile
Re: Making NPCs Follow Your Main Actor?
« Reply #14 on: October 04, 2007, 02:02:45 PM »

Excellent idea. TYVM ! : )
Logged
 

Page created in 0.031 seconds with 23 queries.