Difference between revisions of "How to Move Npcs"
(→= Making NPCs Movable) |
(→Making NPCs Walkable) |
||
Line 16: | Line 16: | ||
Migrate the table and you're done. | Migrate the table and you're done. | ||
+ | |||
+ | === Simple NPC Movement === | ||
+ | |||
+ | This is a really simple script that will make the npc loop through the path. This is 'scripts/zones/Port_Jeuno/npcs/Red_Ghost.lua' | ||
+ | |||
+ | -- includes pathfind methods | ||
+ | require("scripts/globals/pathfind"); | ||
+ | |||
+ | -- total path, you can have multiple | ||
+ | path = { | ||
+ | -96.823616, 0.001000, -3.722488, -- x1, y1, z1 | ||
+ | -96.761887, 0.001000, -2.632236, -- x2, y2, z2 | ||
+ | -96.698341, 0.001000, -1.490001, -- etc | ||
+ | -96.636963, 0.001000, -0.363672, | ||
+ | -96.508736, 0.001000, 2.080966, | ||
+ | -96.290009, 0.001000, 6.895948, | ||
+ | -96.262505, 0.001000, 7.935584, | ||
+ | -96.282127, 0.001000, 6.815756, | ||
+ | -96.569176, 0.001000, -7.781419, | ||
+ | -96.256729, 0.001000, 8.059505, | ||
+ | -96.568405, 0.001000, -7.745419, | ||
+ | -96.254066, 0.001000, 8.195477, | ||
+ | -96.567200, 0.001000, -7.685426 | ||
+ | }; | ||
+ | |||
+ | function onSpawn(npc) | ||
+ | -- pathfind.first(path) will retrieve the first point in the path | ||
+ | -- that will be {-96.823616, 0.001000, -3.722488} | ||
+ | -- npc:setPos will set the npc to the first point | ||
+ | -- this should be done for safety | ||
+ | npc:setPos(pathfind.first(path)); | ||
+ | -- this calls onPath and starts moving the npc to the first point through the whole path | ||
+ | onPath(npc); | ||
+ | end; | ||
+ | |||
+ | -- onPath is called everytime the npc hits a point on the path | ||
+ | -- so this will be called 12 times through the entire walk | ||
+ | -- the first point isn't called because you are already there | ||
+ | function onPath(npc) | ||
+ | -- patrol will keep looping through the path when it finishes | ||
+ | pathfind.patrol(npc, path); | ||
+ | end; | ||
+ | |||
+ | === Creating a Path == | ||
+ | |||
+ | An easy way of getting points is to use the ashita plugin navi (http://www.ffevo.net/files/file/190-navi/). Then go in game and run around. You can then export the points and use it in lua. | ||
+ | |||
+ | If you are on linux you can use this command to output all points: ack 'x="([\-0-9\.]+)" y="([\-0-9\.]+)" z="([\-0-9\.]+)"' west.xml --output='$1, $2, $3,' > west_points.asc | ||
== Examples == | == Examples == |
Revision as of 22:34, 26 July 2013
Whats up? This will walk you through the process of making npcs and mobs move.
Contents
Making NPCs Walkable
Making NPCs Movable
By default a npc will not be in the server update loop. This means the npc cannot move around.
First find the id of the npc you want to update. Find your npc by looking in 'sql/npc_list.sql'. Search for your npcs name and copy the id.
npc_dummies currently uses the old npc format so you'll have to transform the npc id through this function: npcid + (4096 * zoneid) + 0x1000000).
Then put that inside a new row:
INSERT INTO `npc_dummies` VALUES('your_id_here');
Migrate the table and you're done.
Simple NPC Movement
This is a really simple script that will make the npc loop through the path. This is 'scripts/zones/Port_Jeuno/npcs/Red_Ghost.lua'
-- includes pathfind methods require("scripts/globals/pathfind");
-- total path, you can have multiple path = { -96.823616, 0.001000, -3.722488, -- x1, y1, z1 -96.761887, 0.001000, -2.632236, -- x2, y2, z2 -96.698341, 0.001000, -1.490001, -- etc -96.636963, 0.001000, -0.363672, -96.508736, 0.001000, 2.080966, -96.290009, 0.001000, 6.895948, -96.262505, 0.001000, 7.935584, -96.282127, 0.001000, 6.815756, -96.569176, 0.001000, -7.781419, -96.256729, 0.001000, 8.059505, -96.568405, 0.001000, -7.745419, -96.254066, 0.001000, 8.195477, -96.567200, 0.001000, -7.685426 };
function onSpawn(npc)
-- pathfind.first(path) will retrieve the first point in the path -- that will be {-96.823616, 0.001000, -3.722488} -- npc:setPos will set the npc to the first point -- this should be done for safety
npc:setPos(pathfind.first(path));
-- this calls onPath and starts moving the npc to the first point through the whole path
onPath(npc); end;
-- onPath is called everytime the npc hits a point on the path -- so this will be called 12 times through the entire walk -- the first point isn't called because you are already there function onPath(npc)
-- patrol will keep looping through the path when it finishes
pathfind.patrol(npc, path); end;
= Creating a Path
An easy way of getting points is to use the ashita plugin navi (http://www.ffevo.net/files/file/190-navi/). Then go in game and run around. You can then export the points and use it in lua.
If you are on linux you can use this command to output all points: ack 'x="([\-0-9\.]+)" y="([\-0-9\.]+)" z="([\-0-9\.]+)"' west.xml --output='$1, $2, $3,' > west_points.asc