ContentDesigner:Creating Movement
- Last edited 9 years ago by Vlash Nytefall
ContentDesigner:SpawnScripts - Creating Movement
Return to: ContentDesigner:SpawnScripts | Tutorials | Portal | Forum | Project Manager | Bug Tracker
The Creating Movement guide will show you how to get your NPC's to walk and run around. With many different combinations you can make a specific path for the NPC to follow to walking in circles if you choose.
There are two functions that can be used to make an NPC move. Below you will find examples of how to use both to make an NPC move around in Norrath.
The MovementLoopAddLocation() function will allow an NPC to move along a given set of coordinates. This can be along a path, in a circle, or random locations. The below example will show a simple movement script. There must be at least two MovementLoopAddLocation() functions in the script for this to work, and the parameters used are as follows... NPC, x, y, z, speed, delay, function name Note *The delay is in seconds *The function name is optional Now let's see an example function spawn(NPC) MovementLoopAddLocation(NPC, -407.46, -60.48, 174.23, 2, 8) MovementLoopAddLocation(NPC, -420.76, -60.86, 180.15, 2, math.random(5, 15)) MovementLoopAddLocation(NPC, -425.42, -61.32, 186.58, 2) MovementLoopAddLocation(NPC, -424.20, -61.98, 190.47, 2, math.random(5, 15)) MovementLoopAddLocation(NPC, -410.19, -62.87, 189.81, 2, math.random(5, 15)) MovementLoopAddLocation(NPC, -406.82, -60.56, 174.38, 2, math.random(5, 15), "Comment") end This script contains the function spawn(NPC) and will run everything inside this block of code when the NPC spawns. This means everytime the NPC spawns it will begin the movement loop. Taking a closer look at this code we can see there are a few different ways of using the MovementLoopAddLocation() function. Here is breakdown of those lines.
MovementLoopAddLocation(NPC, -407.46, -60.48, 174.23, 2, 8) If the MovementLoopAddLocation() parameters are compared to the parameters guide listed above we can see that -407.46 is the X coords, -60.48 is the y coords, 174.23 is the z coords. We can also see that our speed is set to 2. This should be the average walk speed, and that is what we want to have this NPC do. If we wanted the NPC to run we would set this to 4. If the NPC is to chase something then set this to 6. We end with the delay parameter. This is measured in seconds. So our friend here will pause at this location for 8 seconds before moving to the next location.
MovementLoopAddLocation(NPC, -420.76, -60.86, 180.15, 2, math.random(5, 15)) It is easy to see that math.random(5, 15) is telling us that 5 seconds is the lowest number to choose from and to go as high as 15 seconds. Now it will make each NPC different than the next when moving from point to point. One thing to keep in mind is when an NPC is spawned and math.random() chooses the number to use for the delay it will keep using that number until the end of that spawns life cycle. For instance when he is killed.
MovementLoopAddLocation(NPC, -425.42, -61.32, 186.58, 2) This will cause the NPC to go to this location and keep moving instead of pausing. This is helpful if the NPC needs to make a turn but does not stop. It is safe to say you can put s 0 in for the delay and it will do the same thing.
MovementLoopAddLocation(NPC, -406.82, -60.56, 174.38, 2, math.random(5, 15), "Comment") The function name "Comment" will look for a function call Comment and execute that function. Once it completes the "Comment" function it will then resume to the delay and finally move on to start over again. You can see in the example above that the function Comment will cause the NPC to say "Nice day for a walk, isn't it?" when it reaches this location. Take notice that this MovementLoopAddLocation() and the very first one are close in proximity of each other. This is to make sure that the NPC is in a good location to walk back to that first location. Since this is a loop the script will move back to the top and start all over again. If the NPC has walked around a building, and was not brought back to the starting point, he will walk back in a straight line and through anything in his path like the building. Best practice is to use the NPC's spawn_location_placement coords as the ending point for your movement script.
|
MoveToLocation() will allow the NPC to move to a specific location then stop. With this function a script can be created to have a NPC flee in terror when anyone/anything with a heartbeat talks to them. Below is a simple script using MoveToLocation()
MoveToLocation(NPC, x, y, z, speed, function name)
function hailed(NPC, Spawn) MoveToLocation(NPC, 10, 0, 20, 6, "Yell") end This will make our scared NPC run away when someone hails him. This code shows 10 is the X parameter, 0 is the y parameter, and 20 is the z parameter. The speed is set to 6 which is the chasing speed, or in this case fleeing speed. The function "Yell" is called to have the NPC say something when he leaves.
|