ContentDesigner:Spawn Script Template
- Last edited 9 years ago by Vlash Nytefall
LUA:SpawnScripts - Spawn Script Template
Return to: LUA:SpawnScripts | Tutorials | Portal | Forum | Project Manager | Bug Tracker
This guide is all about the spawn script template, and offers an explanation of each part of the code to help better understand how the emulator server uses LUA scripting language to make your NPC's come to life. If you are using the EQ2LuaEditor then this exact template can be created by going to file->New->Spawn Script.
In order to have a spawn script that can be submitted to the server you must follow a certain structure. First will be a break down of the code with an explanation of what each part does. At the bottom there will be the full template. If you are using the EQ2LuaEditor then one can be created by going to file->New->Spawn Script.
Comments Section --[[ |
In the comments section is where information goes about the spawn script that is being made. This information is useful when you or someone else needs to look at the script if an error occurs at a later date. A comment section can be quickly located by the two dashes followed by two left square brackets at the beginning of a line --'' and has two dashes followed by two right square brackets ''-- on the last line after the comment. As we can see from the code above there is a place for the scripts name, purpose, author, date, and notes.
Script Name: This is where the the name of the NPC the script is created for will go. It also includes the location of that script and will look something like this.
Script Name : SpawnScripts/Darklight/VerexNZa.lua
The above example is case sensitive, and all spawn scripts will go into a folder called SpawnScripts. This is the first line as can be seen in the example above. Next is the zone of the NPC. This NPC is located in Darklight Wood, so it will go into a folder named Darklight. After that is the name of the NPC that this spawn script will be assigned to. As can be seen above VerexNZa the name of the NPC Verex N'Za. Notice that the ' has been removed in the naming process. Last is the .lua. Since LUA is the scritping language that the emulator uses so it must be present.
Script Purpose: This is where the name of the NPC will go. For extra clarification the spawn ID can be placed in here as well. This will help later on to identify the NPC in the database. It will look something like this.
Script Purpose : Verex N'Za (340030)
Script Author: This is where the author of the script goes. Easy enough to figure out, and could possibly let someone know who to contact with either help on the script, or questions on why they done something the way they did. Just to keep the layout of this page the same here is what it will look like.
Script Author : Cynnar
Script Date: This is where the date you made the script goes. It could be helpful if there is a server code change and scripts before that date need to be edited to reflect those changes. Here is what it will look like.
Script Date : 2015.07.01
Script Notes: Here is where any special notes goes. An example would be if there is something that needs to be added to the spawn script but is not able to be added at the current time of coding. Here is what it should look like.
Script Notes : Missing PlayFlavor information for the hail function.
Basic Functions function spawn(NPC) |
In order to get a NPC to operate in a particular way, a function must be used. These five basic functions are the most used functions for a spawn script. At the very least a spawn script needs the function spawn, function respawn, and function hailed in order to make an NPC have a conversation. Before jumping into what each of these functions mean, it is crucial to understand the syntax and parameters that make up a function. Lets use the function hailed as an example.
function hailed(NPC, Spawn) FaceTarget(NPC, Spawn) end
Every function begins with the word function, and will close out with the word end. Everything after function a before end is what we want the function to do. We need to tell the server what function we want to execute. This is done by using one of the functions the server calls, and in this example it is hailed. The hailed function needs two parameters to work properly, and will always be between the left and right parentheses ( ). In this example the first parameter is NPC. This points to the NPC that the spawn script is assigned to. There is a comma "," followed by a space that separates the two parameter, and must be there or the function will not work. The next parameter is Spawn. For the hailed function this points to the player. Just a quick note here that Spawn does not always point to player depending on the function used. Spawn could also point to another NPC for NPC to NPC interaction. For a deeper look into the spawn server functions visit the LUA SpawnScritps page.
Inside our function we have FaceTarget. This is one of many lua functions that can be used, and as the name suggest this will cause the NPC to face its target. It also has to have two parameters as well, and uses NPC and Spawn. To see all of these function visit LUA All Functions page.
Basic Template complete --[[ |