This is a reference tutorial. It could be rewritten to something easier to read/understand and added to wiki later by volunteers.
So you found out place XXX-X is too boring, and could use people moving around?
It's time for Moving NPCS!
Here's an example of a move-able NPC:
Code: Select all
<npc id="463">
<!-- Yannika, Hinnaks sandwich-making wife. -->
<sprite>races/human-female.xml</sprite>
<sprite>hairstyles/hairstyle12.xml|#470320,570c27,8e2b41,a42d2d,c82525,e89687,fcd4a4</sprite>
<sprite>equipment/chest/tanktop-female.xml|#620e48,bf1b8b,e32bcf,ffb6f7</sprite>
<sprite>equipment/legs/cottonskirt-female.xml|#3c1554,6d3195,c987d1</sprite>
<sprite>equipment/head/brimmedflowerhat.xml</sprite>
<sprite>equipment/feet/boots-female.xml|#111111,222222,333333,444444,555555,aaaaaa</sprite>
<menu name="Talk" command="talk 'NAME'"/>
</npc>
- The NPC ID. It must be over 400 and unique. Usually, just pick the next free ID available, skipping those with ID >800 which are reserved.
- The comment. People reading source code must know what the NPC is about.
- In this order: A body and a hair (optional) for the NPC. The bodies are under races/ folder, and the hairstyles under hairstyles.
- Hair color. In the example above, they'll be Fire Red. You can find the hair colors on itemcolors.xml - be mindful between "hair" and "hairS"! You can see which one to use on the begin of items.xml
Their syntax is:
Code: Select all
<sprite> PATH/TO/SPRITE|#DYE-COLOR </sprite>
Once finished, add the menu option of talking, save, and finish!
Protip: You'll make that a Merge Request against clientdata repository. Please refrain from sending us the whole XML file if possible.
In db/constants.conf, declare the new NPC constant:
Code: Select all
NPC_AWESOMENPC: 463
Rename NPC_AWESOMENPC to something at least a bit descriptive. (eg. NPC_MOUBOO or NPC_VALIA).
2. Create the NPC file.
It'll mimic this structure:
Code: Select all
// Evol Scripts
// Author:
// <your name here>
// Description:
// <what your NPC does>
XXX-X,x,y,0 script Awesome NPC Name NPC_AWESOMENPC,{
hello();
close;
OnTimer1000:
domovestep();
end;
OnInit:
initpath "move", 54, 43,
"dir", DOWN, 0,
"wait", 27, 0,
"move", 43, 43,
"dir", UP, 0,
"wait", 27, 0,
"move", 48, 45,
"dir", DOWN, 0,
"wait", 20, 0;
initialmove;
initnpctimer;
.sex = G_OTHER;
.distance = 5;
end;
}
- XXX-X, X, Y - are the map coordinates. That reads as: map XXX-X.tmx (x,y)
- The "0" after coordinates is the direction its facing. "0" is south (the default)
- It's called Awesome NPC Name. Keep it under 23 chars. If you have multiple NPCs with same name, you can put a # at the end, followed by an identifier. eg. Student#1. NPC names must be unique and are case-sensitive!
Inside the OnInit block is where the magic happens.
keyword, arg1, arg2,
Now let's analyse the code:
Code: Select all
initpath "move", 54, 43,
"dir", DOWN, 0,
"wait", 27, 0,
"move", 43, 43,
"dir", UP, 0,
"wait", 20, 0;
These coordinates must be nearby, as NPCs are not capable of crossing huge distances in one go.
Once it finishes, it'll change its direction to be facing DOWN.
Direction only takes one argument, so we add a 0 to keep the structure.
After that, it'll wait 27 seconds before moving again.
Again, wait only takes one argument, so we add a 0 to keep the structure.
After this, it'll move to (43, 43). Once finished it'll change its direction to be facing UP (with an extra 0 to keep structure). Then it'll wait a bit, 20 seconds.
Once it finishes, it mets a ; (semicolon). initpath is a command/function/keyword, and those only end when you give it a semicolon.
It'll go back to start when it finishes, so the first movement usually points to wherever the NPC default position is.
Code: Select all
initialmove;
initnpctimer;
will put this to work. You're finished.
If you're testing locally, run make maps so your localhost learns about this new NPC. There's no need to run that for the merge request.
And now you have a moving NPC!
CONGRATULATIONS
Keep in mind "no arguments" means "put a 0, 0, at the end", for example.
The most common are:
- dir - Direction (UP/DOWN/LEFT/RIGHT). One argument.
- sit - Makes NPC to sit. No arguments.
- stand - Makes NPC stand. No arguments.
- wait - Makes NPC to wait X seconds. One argument.
- emote - Makes NPC shows an emote. One argument. eg. E_JOY
- warp - Makes NPC to warp. Unlike move, it will not have any animation.
- speed - Allows NPC to run or walk slower. One argument.
- say - Makes NPC say something to everyone see.
- call - Calls a custom function to do whatever. Accepts up to two arguments, as usual.
- move - Makes NPC walk somewhere.