Difference between revisions of "ContentDesigner:Spawn Script Template"
| Line 58: | Line 58: | ||
FaceTarget(NPC, Spawn) | FaceTarget(NPC, Spawn) | ||
end | end | ||
| − | As we can see in the first line the very first word is ''function''. This tells the server that everything after this is part of LUA and needs to be executed accordingly. The next word is ''hailed''. This is the | + | As we can see in the first line the very first word is ''function''. This is a core function that is used by the server, and tells the server that everything after this is part of LUA and needs to be executed accordingly. To see a full list of server core functions visit the [[LUA:AllFunctions|Server Core Functions]] section of the LUA page. The next word is ''hailed''. This is the function that LUA uses. To see a full list of functions that are used by a LUA Function you can visit the [[LUA:SpawnScripts|All LUA Functions]] section of the LUA page. Next we see ''(NPC, Spawn)''. These are parameters. They will always be inside the left ( and right ) parentheses and are needed for the function to work. ''NPC'' is our first parameter in this list. The first parameter is telling the ''function hailed'' who needs to be doing the responding. Since ''NPC'' is the first parameter here then it is telling the function hailed that the NPC is what needs to respond when hailed. Take notice now that there is a comma " , " then a space that separates NPC and Spawn. You must put this comma and space in so LUA knows where one parameter ends and the other begins. The second parameter is ''Spawn'' and is telling ''function hailed'' who the ''NPC'' needs to respond to. In this case it is the ''Spawn''. Current standards we have adopted are to use NPC as the value for the NPCs parameters, and depending on the function, Spawn as the value for the Players parameters. |
On the second line we see that it is indented. The more lines of code you have the harder it becomes to keep up with every thing. With this indent it allows a script writer to easily see what is inside each function, and every line inside the function should be indented also. After that the code starts with ''FaceTarget''. This is another LUA function and as it states this will make something face it's target. The following we see is again another set of parameters that is identical to the function hailed. ''(NPC, Spawn)'' The first parameter is telling ''FaceTarget'' who needs to be doing the facing. In this case it is the ''NPC''. This means that the second parameter is telling ''FaceTarget'' who the ''NPC'' needs to face. In this case it is the ''Spawn'', and remember that Spawn stands for the player. | On the second line we see that it is indented. The more lines of code you have the harder it becomes to keep up with every thing. With this indent it allows a script writer to easily see what is inside each function, and every line inside the function should be indented also. After that the code starts with ''FaceTarget''. This is another LUA function and as it states this will make something face it's target. The following we see is again another set of parameters that is identical to the function hailed. ''(NPC, Spawn)'' The first parameter is telling ''FaceTarget'' who needs to be doing the facing. In this case it is the ''NPC''. This means that the second parameter is telling ''FaceTarget'' who the ''NPC'' needs to face. In this case it is the ''Spawn'', and remember that Spawn stands for the player. | ||
Revision as of 00:38, 9 September 2015
ContentDesigner:SpawnScripts - Spawn Script Template
Return to: ContentDesigner: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
As we can see in the first line the very first word is function. This is a core function that is used by the server, and tells the server that everything after this is part of LUA and needs to be executed accordingly. To see a full list of server core functions visit the Server Core Functions section of the LUA page. The next word is hailed. This is the function that LUA uses. To see a full list of functions that are used by a LUA Function you can visit the All LUA Functions section of the LUA page. Next we see (NPC, Spawn). These are parameters. They will always be inside the left ( and right ) parentheses and are needed for the function to work. NPC is our first parameter in this list. The first parameter is telling the function hailed who needs to be doing the responding. Since NPC is the first parameter here then it is telling the function hailed that the NPC is what needs to respond when hailed. Take notice now that there is a comma " , " then a space that separates NPC and Spawn. You must put this comma and space in so LUA knows where one parameter ends and the other begins. The second parameter is Spawn and is telling function hailed who the NPC needs to respond to. In this case it is the Spawn. Current standards we have adopted are to use NPC as the value for the NPCs parameters, and depending on the function, Spawn as the value for the Players parameters.
On the second line we see that it is indented. The more lines of code you have the harder it becomes to keep up with every thing. With this indent it allows a script writer to easily see what is inside each function, and every line inside the function should be indented also. After that the code starts with FaceTarget. This is another LUA function and as it states this will make something face it's target. The following we see is again another set of parameters that is identical to the function hailed. (NPC, Spawn) The first parameter is telling FaceTarget who needs to be doing the facing. In this case it is the NPC. This means that the second parameter is telling FaceTarget who the NPC needs to face. In this case it is the Spawn, and remember that Spawn stands for the player.
The final line has the word end on it and that is is. Every function must close with the word end. This tells the server that this LUA function has come to and end and it can now continue down the list.
Basic Template complete --[[ |