Page 1 of 1

Walking Mobs on a Route

Posted: Wed Nov 09, 2011 4:09 am
by pewpew122
If you want to receive support we need this info to help you properly.
» Find Revision
L2J Revision 5034:
L2JDP Revision 8482:

I'm trying to add a patrolling mob on a field (example Cruma Marshlands) that walks on a set path and attacks any players that's very close to it. I noticed that NPCs can be turned into Walker NPCs but those are only passive NPCs for towns. Then I found a Routes.xml file that has some coordinates and a cycle pattern that lets me change it to however I want it.

However, I'm confused on how to use it since I do not know how to add a NPC ID to it so it does that specific route to an specific mob npc. In what part do I need to add the NPCID so I can add a walkingroute on the Routes.xml so my Mob uses it.

Re: Walking Mobs on a Route

Posted: Wed Nov 09, 2011 11:38 am
by VlLight
Not sure, if it wasn't changed, but looks like wasn't. You should create individual script for it.
Simplified example can looks like this:

Code: Select all

public class SimplifiedExample extends Quest{    public SimplifiedExample(int questId, String name, String descr)    {        super(questId, name, descr);        addSpawnId(EXAMPLE_MOB);    }     @Override    public final String onSpawn(L2Npc npc)    {        WalkingManager.getInstance().startMoving(npc, route_ID_from_Routes_XML);                return super.onSpawn(npc);    }     public static void main(String[] args)    {        new SimplifiedExample(-1, "SimplifiedExample", "custom");    }}
This simplified code, of course, is suitable, if ONLY ONE mob with used ID spawns (actually, if there is no other mobs with this ID in radius 3000 from starting point of route (you can change range in class)), else all of them will march by this route.
So, if you wish to make marching only some mobs, or if you wish to make mobs with same ID marching by different routes, you should define correspondence between mob and route.
It can be done like this, by spawn coordinates of monsters:

Code: Select all

private static final Map<Integer, int[]> ROUTE_DATA = new HashMap<Integer, int[]>();static{    ROUTE_DATA.put(1, new int[] { 14840, 251949 });    ROUTE_DATA.put(2, new int[] { 16082, 251790 });    ROUTE_DATA.put(5, new int[] { 16524, 255244 });    ROUTE_DATA.put(12, new int[] { 17670, 252256 });} private static int getRoute(L2Npc npc){    for (int key : ROUTE_DATA.keySet())    {        int coord[] = ROUTE_DATA.get(key);        if (coord[0] == npc.getSpawn().getLocx() && coord[1] == npc.getSpawn().getLocy())            return key;    }            return -1;} 
So, you can start moving only for selected mobs and by own route:

Code: Select all

if (getRoute(npc) > 0)        WalkingManager.getInstance().startMoving(npc, getRoute(npc)); 
P.S> Note, if you spawn mobs by spawntable, not by script, you shoud call onSpawn() for mobs at script start (at least, it was so in Freya)

Re: Walking Mobs on a Route

Posted: Wed Nov 09, 2011 4:05 pm
by lucan
For a single custom Mob I can use the script gordon.java? Just changing the ID of the NPC, path coordinates, new name to file and load it in scripts.java?

EDITED...
Yes, the AI gordon.java can be used for this function, only changes few informations like NPC id, names GORDON and Gordon to own name, coordinates of walks and in the line if (_isWalkTo > 55) change the number 55 to be equal to the amount of routes that you have in WALKS and the name of file.
Put the file loading in scripts.cfg and works! I tested and works perfect!

Re: Walking Mobs on a Route

Posted: Fri Nov 25, 2011 6:21 pm
by corbin12
VlLight, can you please explain further about getRoute?

Re: Walking Mobs on a Route

Posted: Fri Nov 25, 2011 6:36 pm
by VlLight
corbin12 wrote:VlLight, can you please explain further about getRoute?
What exactly is unclear? For monsters with same ID it needs to identify them between each other, for attach individual route to each of them. One from alternatives is spawn point (if monsters have different) - you should pair spawn coordinates and route (For example, map with route number as key)

Re: Walking Mobs on a Route

Posted: Fri Nov 25, 2011 6:46 pm
by corbin12
This thing is unclear:

ROUTE_DATA.put(1, new int[] { 14840, 251949 });
ROUTE_DATA.put(2, new int[] { 16082, 251790 });
ROUTE_DATA.put(5, new int[] { 16524, 255244 });
ROUTE_DATA.put(12, new int[] { 17670, 252256 });

What does 2,5,12 mean?? and 14840, 251949 and the other down from them. Are these X or Y?

Re: Walking Mobs on a Route

Posted: Fri Nov 25, 2011 6:46 pm
by lion
2,5,12 route id in Route.xml, yes x and y

Re: Walking Mobs on a Route

Posted: Fri Nov 25, 2011 6:52 pm
by corbin12
ty. And in x (for example I have 5 mobs) every mob who is in x will run(all of them)?

Re: Walking Mobs on a Route

Posted: Fri Nov 25, 2011 7:14 pm
by lion
in this example you have check x and y, if this not enough you can add heading check for example, then npc name and other

Re: Walking Mobs on a Route

Posted: Fri Dec 02, 2011 9:47 pm
by corbin12
Thank you. I made a script but only one of 2 mobs run