Difference between revisions of "ContentDesigner:Spawn Script Template"

 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{PageHeaderChild|ContentDesigner:SpawnScripts|Spawn Script Template}}
+
{{PageHeaderChild|LUA:SpawnScripts|Spawn Script Template}}
  
 
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''.
 
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''.
Line 40: Line 40:
 
<br/>
 
<br/>
 
function respawn(NPC)<br/>
 
function respawn(NPC)<br/>
spawn(NPC)<br/>
+
&nbsp;&nbsp;&nbsp;&nbsp;spawn(NPC)<br/>
 
end<br/>
 
end<br/>
 
<br/>
 
<br/>
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 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.
+
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:SpawnScripts|LUA SpawnScritps]] page.
  
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.
+
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:AllFunctions|LUA All Functions]] page.
 
 
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.
 
 
{|style="table-layout:fixed; width: 100%;"
 
{|style="table-layout:fixed; width: 100%;"
 
|{{TextBox
 
|{{TextBox
Line 78: Line 76:
 
<br/>
 
<br/>
 
function respawn(NPC)<br/>
 
function respawn(NPC)<br/>
spawn(NPC)<br/>
+
&nbsp;&nbsp;&nbsp;&nbsp;spawn(NPC)<br/>
 
end<br/>
 
end<br/>
 
<br/>
 
<br/>

Latest revision as of 21:47, 15 June 2016

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.


A breakdown of the template

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

--[[
Script Name : <script-name>
Script Purpose : <purpose>
Script Author : <author-name>
Script Date : 9/7/2015
Script Notes : <special-instructions>
--]]

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)
end

function respawn(NPC)
    spawn(NPC)
end

function hailed(NPC, Spawn)
end

function aggro(NPC, Spawn)
end

function death(NPC, Spawn)
end

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

--[[
Script Name : <script-name>
Script Purpose : <purpose>
Script Author : <author-name>
Script Date : 9/7/2015
Script Notes : <special-instructions>
--]]

function spawn(NPC)
end

function respawn(NPC)
    spawn(NPC)
end

function hailed(NPC, Spawn)
end


On to Creating Conversations
Back to SpawnScripts