MODULE: Caterpillar v0.1 - Follow the player from behind

Started by Daniel Eakins, Mon 21/11/2011 22:29:30

Previous topic - Next topic

Daniel Eakins

This module allows you to have characters follow the player character from behind, walking exactly in the player character's footsteps and changing rooms with them, forming a 'caterpillar' system. It is basically a smoother version of Bernie's FolEx old module (see http://www.adventuregamestudio.co.uk/yabb/index.php?topic=25121.0 ).

It was primarily designed for RPGs using keyboard controls (in particular, the KeyboardMovement module by Rui "Brisby" Pires & strazer). It currently does not work well with mouse controls because the KeyboardMovement is strictly 8-directional whereas mouse movement is, well, 360-directional.

Note that if your player character has MovementLinkedToAnimation = true, the characters who follow him must also have that parameter true and the same AnimationSpeed as him. If he has MovementLinkedToAnimation = false, the characters who follow him can have different AnimationSpeed values. In both cases, the characters's WalkSpeeds will be aligned with that of the player (including if you have implemented a custom "running" feature for your player's movement).

This is my first module ever, so sorry if there are bugs or if the code is awkward. Suggestions/comments are of course welcome.


Functions:

  Disable();
    Disables caterpillar movement.

  Enable();
    Enables caterpillar movement. By default, the module is automatically enabled at game start.

  Status();
    Returns whether caterpillar movement is currently enabled.

  Set(int spot, Character* name);
    Adds a character to the specified spot in the caterpillar (spot 0 is the first character that follows the player's character, spot 1 is the second, etc.). Note that adding a character makes them become non-solid.

    To remove a character from a spot, just set name to null. The character's original solid property will be restored.

  Get(int spot);
    Returns the ID number of the character in the specified spot.


Version history:

  v0.1 (November 21, 2011)  First release by Daniel Eakins


License:

  This module is released into the public domain.


Download
We all have our time machines, don't we?

Perkele2012

This module sounds good! i know the post is a couple of months old, to bad it´s not avaible for download anymore. was looking forward to trying it out in my project..

cheers!

Icey


Deu2000

That module is very interesting. Bad that it isn't available  :'(.



Marion

Hi ! I'm really interested, is the module available? Thank you !

Daniel Eakins

Hello, sorry for replying so late (almost two years later!). I kind of left the forum at some point :sad:

The module has now been reuploaded.
We all have our time machines, don't we?

Monsieur OUXX

#6
Sorry for digging up an old thread, but this module is rather useful, yet I found a bug.
This bug seems to have been introduced after an unfortunate last-minute modification.

Current code :
Code: ags

static function Caterpillar::Set(int spot, Character* name) {
 
  // If 'name' is already at 'spot' or is the player, do nothing
  int n;
  while (n < NMAX) {
    if (name == follower[n] || name == player) {return;}
    n++;
  }
  // If 'name' is null, remove current character from 'spot'
  if (name == null) {
    ...
    follower[spot] = null;
  }
...


As you can see, the function is broken. The end-used is supposed to use "null" value for parameter "name" in order to remove that value from array "follower".
But before "if (name == null)" occurs, there is that loop which does "if (name == follower[n] ...) {return;}". If name==null, then name==follower[n] can be true! Therefore you never get to reach if (name == null)

Unless I'm overlooking something obvious, the correct code should be :
Code: ags

static function Caterpillar::Set(int spot, Character* name) {
 
  // If 'name' is already at 'spot' or is the player, do nothing
  if (name != null) { // !!!!!!!!!!!!!!!!!!!
      int n;
      while (n < NMAX) {
        if (name == follower[n] || name == player) {return;}
        n++;
      }
  }                   //!!!!!!!!!!!!!!!!!!!!
  // If 'name' is null, remove current character from 'spot'
  if (name == null) {
    if (follower[spot] != null) { // !!!!!!!!!!!!!!!!
      follower[spot].StopMoving();
      follower[spot].Solid = originalsolid[spot];
    }                            //!!!!!!!!!!!!!!!!!!!
    follower[spot] = null;
  }...
 

Daniel Eakins

Hey, what a coincidence, I was cleaning up my Dropbox folders just now and so I had to log in the forum to check some old links, after months of inactivity. I do not have AGS installed on this computer anymore so I can't check your edit Monsieur OUXX but I'm trusting your expertise :)
We all have our time machines, don't we?

ollj

this will go well with my "conga dance animations"

Daniel Eakins

We all have our time machines, don't we?

SMF spam blocked by CleanTalk