Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Stranga on Thu 19/12/2019 23:14:45

Title: Help with a custom module for setting a path for a character
Post by: Stranga on Thu 19/12/2019 23:14:45
Hello everyone!

I'm not sure if this belongs in the beginner or advanced forums, but I can't figure out a way to implement it (if it's even possible). Basically, what I want to do is have one function that can set a path for a character to replace AGS's path finding system. Because I work with top down games mostly, the path finding looks a little janky and I want to avoid having to type [ character.Walk(x,y,ect) ] 10+ times. So I thought of this idea where I could have a function that I could add as many coordinates in it as I want!(Or maybe just a limit of 5-10).

So for example:

Code (ags) Select


player.WalkPath(eBlock, eWalkableAreas, point x, point y, point x, point y, point x, point y);

//The player would walk to each point in a sequence until there are no more coordinates

//or even

player.WalkPath(eBlock, eWalkableAreas, pos1, pos2, pos3, pos4, pos5);


I'm not sure if this is achievable in this state, but even so, I thought throwing the idea out there may be interesting.

Thanks for any help or input in advance!
Title: Re: Help with a custom module for setting a path for a character
Post by: eri0o on Thu 19/12/2019 23:53:19
It looks totally achievable, use Point* for position, I think you can use WalkPath(this Character*, BlockingStyle block, WalkWhere walk_where, Point* pos1, Point* pos2 = 0) and then consume the pos checking if the passed value is null, and if not, trigger a walk.
Title: Re: Help with a custom module for setting a path for a character
Post by: Stranga on Fri 20/12/2019 00:05:55
Thanks for your reply @ eri0o! :-D

I'll give this a try. I also found in the manual a function called AddWaypoint (Formerly known as MoveCharacterPath). Which is exactly what I'm after but I would like to simplify it as you suggested into a one line function.

Currently it would look like this:

Example:
Code (ags) Select

cSomeguy.Walk(160, 100);
cSomeguy.AddWaypoint(50, 150);
cSomeguy.AddWaypoint(50, 50);


So I think your solution may be better, unless I could find a way to store way points in a function?

Title: Re: Help with a custom module for setting a path for a character
Post by: eri0o on Fri 20/12/2019 01:26:07
Sorry, what do you mean store points in a function?

My example was the thing that would be in header and the idea was to have more pos parameters but I got lazy and wrote only 2.

I think you will need waypoint to be easier to have two or more points when using eNoBlock.
Title: Re: Help with a custom module for setting a path for a character
Post by: Stranga on Fri 20/12/2019 01:43:24
Sorry about that, I should have worded it better. By store points I meant storing a position (x and y) in the room in a single int not a function. I'm trying out your method first as I see it as a cleaner/ faster way to do this.  :)

Title: Re: Help with a custom module for setting a path for a character
Post by: eri0o on Fri 20/12/2019 02:34:37
You can create a method that is static or a simple function that returns a point

Code (ags) Select

Point* P(int x, int y){
  Point* p = new Point;
  p.X = x;
  p.Y = y;
  return p;
}


And then just use it on your calls like

Code (ags) Select
cNPC.WalkPath(eBlock, eWalkableAreas, P(40,50), P(100,120));