HowTo - Creature Movement and Waypoints

From OregonCore Wiki
Jump to: navigation, search


Creature Movement

The topic of creature movement seems to come up fairly frequently in discussions regarding content creation. Although the process of adding movement and actions to creatures is fairly simple, it's not often clear to us when we first start looking at building content. This short guide will provide basic instructions on the various types of movement to get the new content creator started.

There was a post on the TrinityCore forums some time ago that brought up an excellent point, that is worth repeating here. When we are adding creature movement, it can be extremely helpful to record video of the creature on the retail servers. This will allow us to examine the movement carefully so that we can duplicate (as closely as possible) the proper behavior.

As we learn the various commands and steps to create our new content, you will see a section called What We Created, or What We Modified. This information is given so that you will know where to look in the database for the various pieces. After you become familiar with the process of creating movement, you may find it easier at times to make the changes directly to the database. This information is also needed if you are creating content to be submitted for inclusion to the OregonDB, since you will need to create a proper SQL file to add your content. Likewise, if your content is intended only for your own use, you will need to create an SQL file with your changes in order to apply them after a major database upgrade.

Now on to the basics...


Basic Creature Movement: Random Movement

1. Spawn or select an NPC.

2. With the NPC selected, issue the command .npc spawndist RADIUS, where RADIUS is the distance that the NPC can randomly move from the spawn point. For example, the boars in Goldshire have a radius of 5. If we were adding another, we would spawn it, select it, and issue the command .npc spawndist 5.

Your creature should not be moving around in a random pattern.

What We Created

Only one table in our world database is modified by our actions: creature.

Changes in the creature table: The MovementType will be changed to 1, and spawndist will be changed to the radius we specify when we issue .npc spawndist RADIUS.


Basic Creature Movement: Paths (Waypoints)

1. Spawn or select an NPC.

2. Get the GUID with .npc info. For our example, we'll use 99999.

3. Select the NPC and issue the command .npc setmovetype way.

4. Go to the place where you want the first waypoint, and issue the command .path addwp GUID*10. In our example, GUID*10 would be 99999 * 10 or 999990. This would make the command .path addwp 999990. It is very helpful to make a temporary macro with this command, to avoid mis-typing the path ID on later points.

5. Keep adding waypoints to form the path by moving and either typing the command .path addwp GUID*10, or using a temporary macro, if you set one up.

6. Make sure the last point has a clear path back to the first point for the NPC to return by. This is very important. When the NPC finishes the last waypoint, they will return to the first and start over again. The NPC will take the shortest path, a straight line. If the path is not clear back to the first point, the movement will be flawed, resulting in a rather amusing, but completely incorrect combination of floating, running, and flailing of the arms that is very unlikely to be what you had hoped for.

7. Issue the command .loadpath GUID*10 (.loadpath 999990 in our example). This picks up the path data so that we don't need to restart the core to add the path to the NPC.

8. Select the NPC and issue the command .path load GUID*10. In our example, this would be .path load 999990.

9. To adjust the speed that the NPC is moving, we have to modify the speed field in creature_template. Setting speed to 1 will result in the creature walking at a regular pace, higher numbers result in faster movement. From a practical standpoint, this should probably not exceed 4 or 5, which appear as a fairly quick running pace. If you have an NPC that needs to be spawned in more than one location, such as a guard for example, and you need for some of them to move at different rates, it would be best to have two entries in creature_template; one each with the movement speeds needed for each spawn, since this value does not appear in the creature table. We can also adjust the speed for some portions of the path. We'll discuss that later in the article.

These steps should result in making your NPC walk the path that you have created. Congratulations!

What We Created

There are four tables in our world database that will be modified by our actions: creature, creature_addon, waypoint_data, and possibly creature_template.

Changes in the creature table: The MovementType will be changed to 2 when we issue .npc setmovetype way.

Changes in the creature_addon table: A new row will be added, or existing row replaced, with our NPC GUID as guid and path ID as path_id. This takes place when we issue the .path load GUID*10 command.

Changes in the waypoint_data table: The rows needed for each of the points in our new path will be created, with the path ID in the id field, and each step of the path, as a point field entry. These are added as we issue the .path addwp GUID*10 commands for each point in the path.

Changes in the creature_template table: If we adjusted the movement speed, our new value will, of course, be in the speed field.


Adding to the Paths

The path commands make it possible for us to make our new NPC do several things without having to create a C++ script, or even an EventAI sequence. Before we can start creating new actions, we need to be able to visualize the path. These steps will turn on the visual waypoints, which represent each point in our path using a half-size human male. The visual waypoints can only be seen if you have GM mode on.

1. If you have not already done so, enable GM mode with the .gm on command.

2. Select the NPC that is walking the path that you want to modify.

3. Issue the command .path show on.

You should now see the visual waypoints. To turn off the visual waypoints when we are finished, issue the command .path show off. To see what actions are attached to any of the points, do the following:

1. Select the visual waypoint, just as you would select an NPC.

2. Issue the command .path show info.

You will see a display in your chat window telling you the specific information about that point. This command can be used as we work with a path to verify the changes we are making.


Adding to the Path: Pauses (Delays)

1. Select the visual waypoint where we want our NPC to pause.

2. Add the delay by issuing the command .path modify delay DELAY_IN_MILLISECONDS. For a 5 second pause, this would be .path modify delay 5000.

3. Reload the path with the command .loadpath GUID*10 (.loadpath 999990 in our example). The NPC will stop moving - this is normal.

4. Select the NPC that will walk the path.

5. Reattach the path to the NPC by issuing the command .path load GUID*10 (.path load 999990 in our example). The NPC will immediately walk directly to the start of the path. Don't be alarmed, they only do this when we reattach the path.

The NPC will now walk the path, pausing at the waypoint we just modified.

What We Modified

Only one table in our world database has been modified: waypoint_data

Changes in the waypoint_data table: The delay field has been changed for the selected point, adding the delay in milliseconds.


Adding to the Path: Running (Speed Changes)

1. Select the visual waypoint that we want our NPC to run to.

2. Change the movement type by issuing the command .path modify move_flag 1. To reverse the setting, if you change your mind and want them to walk instead, the command is .path modify move_flag 0.

3. Reload the path with the command .loadpath GUID*10 (.loadpath 999990 in our example). The NPC will stop moving - this is normal.

4. Select the NPC that will walk the path.

5. Reattach the path to the NPC by issuing the command .path load GUID*10 (.path load 999990 in our example). The NPC will immediately walk directly to the start of the path. Don't be alarmed, they only do this when we reattach the path.

The NPC will now walk the path, running from the previous waypoint to the waypoint we just modified.

What We Modified

Only one table in our world database has been modified: waypoint_data

Changes in the waypoint_data table: The move_flag field has been changed for the selected point to 1, unless we were reversing a setting to make them walk instead, in which case move_flag will be set to 0.


Making Corrections

Deleting a Waypoint

1. Select the visual waypoint to delete by clicking on it.

2. Issue the command .path modify del.

3. Reload the path with .loadpath GUID*10.

4. Reattach the path to the NPC with .path load GUID*10.

Moving a Waypoint

1. Select the visual waypoint that you want to move by clicking on it.

2. Move to the place that you want the waypoint to be.

3. Issue the command .path modify move. The visual waypoint will move to your position.

4. Reload the path with .loadpath GUID*10.

5. Reattach the path to the NPC with .path load GUID*10.

Adding to an Existing Path

1. Select the NPC that is attached to the path.

2. Turn off visual waypoints with .path show off.

3. Turn on only the last visual waypoint with .path show last. This will indicate the point where you will start adding additional waypoints. [Note: There is also a command to show only the first waypoint, .path show first. Before changing the .path show option, you must turn off visual waypoints.]

4. Load the current path with .loadpath GUID*10.

5. Add waypoints by moving to the positions where you want the added points and issuing the command .path addwp GUID*10 NODEL. NODEL specifies that you do not want to delete the waypoints already in the path. For our example, this command would be .path addwp 999990 NODEL.

6. Continue adding additional waypoints with .path addwp GUID*10 NODEL until you have completed the path.

7. Reload the path with .loadpath GUID*10.

8. Reattach the path to the NPC with .path load GUID*10. At this point, you may wish to view the whole path with visual waypoints. The commands .show path off and .show path on will display all of the points.


Waypoint Scripts

In order to do more complex things with our paths, we have the ability to create waypoint scripts. These can be used to have our NPC speak, emote, cast a spell, and many other things. Using scripts, they can even do more than one of these at a particular waypoint. We can also make the probability of the scripts more random, where the options we've already looked at will occur 100% of the time. Waypoint scripts are quite a powerful tool, but require a slightly more complicated series of commands to create. The next sections will deal with some of the script actions that are frequently employed in the existing database. The available actions may be seen by referring to the waypoint_scripts article in the world database section of the wiki.


Waypoint Scripts: Creating a Script

These steps are required for all types of action that we will use.

1. Create the initial script and get the GUID by issuing the command .path event add. This lays the foundation for our script. It is not necessary to have our NPC or a visual waypoint selected at this time. We will join the script to our path in a later step. When this command is run, the system will provide a GUID by displaying New waypoint event added: NUMBER in the chat window. Make a not of the NUMBER. This is our event GUID. For our example, we will use 888 as the GUID.

2. Set the script ID with the command .path event mod GUID setid EVENTID. For the first action in our event, the GUID will be the same as the EVENTID. In our example, the command will be .path event mod 888 setid 888. When we add a second event, we will get a new GUID, but we will set the EVENTID to the GUID of the first event. We'll see that in a later step.

These steps are needed for any new script.

Now let's add some actions...


Waypoint Scripts: Talking

1. In order for our NPC to talk, they need something to say. We need to add a new string to db_script_string. For historical reasons, the entry number in db_script_string has to be between 2000000000 and 2000010000. For our example, we'll use 2000009000, which is far above the entries already found in the table, and within the system-specified limit. Using the SQL tool of your choice, create a new row in db_script_string with an entry value and default_content containing the text you want the NPC to say. In our example, the entry is 2000009000. You should choose something in a similar part of the allowed value range. The other fields in db_script_string are for localization. You may or may not need them, depending on your language choices. This table is only loaded at core start-up, so you will need to restart the core in order to have the string available for the next steps.

2. Set the event command for our event by issuing .path event mod EVENTID command 0. Command 0 is the TALK command. EVENTID was set earlier when we created the initial script. For our example, this command will be .path event mod 888 command 0.

3. Now we set the way the text is said. We have the option of a regular SAY, or a YELL. The command also supports WHISPER, but it requires a target, so we won't use it here. To have our text said in a SAY, the command is .path event mod EVENTID datalong 0. In our example, this will be .path event mod 888 datalong 0. To YELL, we issue .path event mod EVENTID datalong 2 (or .path event mod 888 datalong 2 in our example).

4. The next step is to add our text string that we created in db_script_string. The command for this is .path event mod EVENTID dataint DB_SCRIPT_STRING.ENTRY. In our example, this will be .path event mod 888 dataint 2000009000.

5. Now we have our event fully defined, so we can add it to a waypoint. Select a visual waypoint in our path by clicking on it.

6. Add the script to the waypoint with the command .path mod action EVENTID. In our example, this is .path mod action 888.

7. By default, our action will take place 100% of the time that the script runs. We can change this if we want a more random experience, using the command .path mod action_chance PERCENT - where PERCENT is the percent possibility of the action taking place. If we wanted a 50% chance, the command is .path mod action_chance 50.

8. In order to use our event, we have to reload the waypoint_scripts table, using .reload way.

9. Reload the path with the command .loadpath GUID*10 (.loadpath 999990 in our example). The NPC will stop moving - this is normal.

10. Reattach the path to the NPC by issuing the command .path load GUID*10 (.path load 999990 in our example). The NPC will immediately walk directly to the start of the path. Don't be alarmed, they only do this when we reattach the path.

11. For unknown (at this time) reasons, your NPC will not talk until the core has been restarted. Restart when you can, and when the server is back on line the event will be available.

Your NPC will now walk the path, saying the specified text at the waypoint you have chosen.

What We Created

Three tables in our world database are modified by our actions: waypoint_data, waypoint_scripts, and db_script_string.

Changes in the db_script_string table: A new row will be added with an entry that is unique and as far away from existing data as is practical. The content_default field will contain our string. Depending on your localization needs, one or more of the content_locX fields may be populated with the localized version of the text.

Changes in the waypoint_scripts table: A new row will be inserted for our script, with the id set to the guid (by the setid command), the command field will be 0 (the TALK command), the datalong field will be 0 for SAY or 2 for YELL depending on what we've chosen, and the dataint field will be the entry field of our string from db_script_string.

Changes in the waypoint_data table: The action field will be changed to contain the EVENTID of our script. The action_chance field will have our probability percent, if we have modified it, otherwise it will contain 100 indicating a 100% probability.


Waypoint Scripts: Emotes

1. Set the event command for our event by issuing .path event mod EVENTID command 1. Command 1 is the EMOTE command. EVENTID was set earlier when we created the initial script. For our example, this command will be .path event mod 888 command 1.

2. Now we set the emote to be performed. For our example, we'll have the NPC salute. The command to set the emote ID is .path event mod EVENTID datalong EMOTEID. In our example, this will be .path event mod 888 datalong 66, since a salute is ID 66. The reference section has a full list of Emotes.

3. Now we have our event fully defined, so we can add it to a waypoint. Select a visual waypoint in our path by clicking on it.

4. Add the script to the waypoint with the command .path mod action EVENTID. In our example, this is .path mod action 888.

5. Remember that by default, our action will take place 100% of the time that the script runs. We can change this if we want a more random experience, using the command .path mod action_chance PERCENT - where PERCENT is the percent possibility of the action taking place. If we wanted a 50% chance, the command is .path mod action_chance 50.

6. In order to use our event, we have to reload the waypoint_scripts table, using .reload way.

7. Reload the path with the command .loadpath GUID*10 (.loadpath 999990 in our example). The NPC will stop moving - this is normal.

8. Reattach the path to the NPC by issuing the command .path load GUID*10 (.path load 999990 in our example). The NPC will immediately walk directly to the start of the path. Don't be alarmed, they only do this when we reattach the path.

9. For unknown (at this time) reasons, your NPC will not perform the emote until the core has been restarted. Restart when you can, and when the server is back on line the event will be available.

Your NPC will now walk the path, performing the specified emote at the waypoint you have chosen.

What We Created

Two tables in our world database are modified by our actions: waypoint_data, and waypoint_scripts.

Changes in the waypoint_scripts table: A new row will be inserted for our script, with the id set to the guid (by the setid command), the command field will be 1 (the EMOTE command), the datalong field will be the EMOTEID that we wish to have the NPC perform.

Changes in the waypoint_data table: The action field will be changed to contain the EVENTID of our script. The action_chance field will have our probability percent, if we have modified it, otherwise it will contain 100 indicating a 100% probability.


Waypoint Scripts: Other Commands

There are many other commands available for us to use in our waypoint scripts. The wiki description of the waypoint_scripts table lists the various commands, and the data required to use them. Most of the remaining ones are specific to object, quest, or other NPC interaction, and do not lend themselves easily to a generalized guide such as this. For that reason, we will not outline the specific steps needed to use them. The steps given above will apply to nearly all of the others within the narrow range of appropriate use. If it seems that more information is needed, this guide will be expanded at a later date.

Please direct any questions to the appropriate forum.