Difference between revisions of "LUA"

m (Get Functions)
(General Functions)
 
(23 intermediate revisions by 8 users not shown)
Line 1: Line 1:
== The LUA Scripting System ==
+
{{PageHeaderParent|LUA}}
We have chosen [http://www.lua.org LUA] as our script engine for EQ2Emulator. Things like Quests, Spawn movement or interaction, Spells, and Zone-wide events are ''scripted'' in LUA using custom '''functions''' specific to the emulator core. Below you will find a list of current EQ2Emulator LUA Functions with links to what they do and examples of how to use them.
 
  
You will quickly see that the ease of the LUA Scripting language and it's tight integration with EQ2Emulator make our server extremely dynamic and customizable.<br />
 
<br />
 
Currently, EQ2Emulator employs LUA scripting for the following systems:
 
  
[[LUA:SpawnScripts | SpawnScripts]]
+
{{Header|EQ2Emulator: LUA Scripting|BackgroundColor=3d78b4|FontColor=ffffff}}
 +
''LUA Scripting'' is extending the functionality of the server without the need to recompile the code each time you wish to add some form of interaction with an NPC, an event happening in a zone, quest steps for players to work through, etc.
  
[[LUA:Spells | Spells]]
 
  
[[LUA:Quests | Quests]]
+
{{Header|What is "LUA"?|BackgroundColor=3d78b4|FontColor=ffffff}}
 +
For a comprehensive look at what LUA is, please visit the [http://www.lua.org lua.org] website and read their own [http://www.lua.org/about.html About] information. On this Wiki, we shall only discuss our own implementation of LUA.
  
[[LUA:ZoneScripts | ZoneScripts]]<br />
 
<br />
 
Follow any of these links for a closer look at the system. Below is a general list of LUA functions we'll keep at this top-level for easier reference.<br />
 
<br />
 
  
== LUA Parameter Basics ==
+
We have chosen LUA as our script engine for EQ2Emulator. Things like Quests, Spawn movement or interaction, Spells, and Zone-wide events are ''scripted'' in LUA using custom '''functions''' specific to the emulator core. Below you will find a list of current EQ2Emulator LUA Functions with links to what they do and examples of how to use them.
EQ2Emulator LUA Functions normally have ''parameters'' - that is, some value required to be passed from the World to the Script or vice-versa. An example of this is the '''function hailed(NPC, Spawn)'''. Note that there are 2 parameters for '''function hailed()'''. What the parameter ''names'' are is up to you, as long as there are the proper number of parameters in the () parens.
 
  
 +
You will quickly see that the ease of the LUA Scripting language and it's tight integration with EQ2Emulator make our server extremely dynamic and customizable.
  
Example: Here, the NPC says Hello to the player.
 
  function hailed(NPC, Spawn)
 
    Say(NPC, "Hello Player!")
 
  end
 
  
 +
Currently, EQ2Emulator employs LUA scripting for the following systems:
  
Example: Here, the Player says Hello to the NPC.
+
[[LUA:SpawnScripts | Spawns]]
  function hailed(NPC, Player)
 
    Say(Spawn, "Hello NPC!")
 
  end
 
  
Current ''standards'' we have adopted are to use '''NPC''' as the value for the NPCs parameters, and depending on the type of script, '''Spawn''' or '''Player''' for the Players parameters. Nearly all other parameter values are dynamic - that is, they can be any valid variable name you choose. But when coding scripts for the Official EQ2Emulator Project, be sure to follow ''our guidelines'' or your scripts will get rejected.
+
[[LUA:Spells | Spells]]
  
== LUA Functions ==
+
[[LUA:Quests | Quests]]
Our LUA Functions list is broken into several categories for clarity of functionality. More functions are added often, so check back if you are looking for something that you need for your scripts.
 
  
 +
[[LUA:ItemScripts | Items]]
  
=== Get Functions ===
+
[[LUA:ZoneScripts | Zones]]
This set of functions will ''GET'' info from the World or Database for use within any LUA script
 
  
Developer: [[Team:LethalEncounter | LethalEncounter]], [[Team:Scatman | Scatman]]
 
  
 +
Follow any of these links for a closer look at the system. Below is a general list of LUA functions we'll keep at this top-level for easier reference.
  
[[LUA:GetAgi | GetAgi(param)]]
 
  
[[LUA:GetClass | GetClass]]
+
{{Header|LUA Parameter Basics|BackgroundColor=3d78b4|FontColor=ffffff}}
 +
EQ2Emulator LUA Functions normally have ''parameters'' - that is, some value required to be passed from the World to the Script or vice-versa. An example of this is the '''function hailed(NPC, Spawn)'''. Note that there are 2 parameters for '''function hailed()'''. What the parameter ''names'' are is up to you, as long as there are the proper number of parameters in the () parens.
  
[[LUA:GetCurrentHP | GetCurrentHP]]
 
  
[[LUA:GetCurrentPower | GetCurrentPower]]
+
Example: Here, the Player says Hello to the NPC.
 +
  function hailed(NPC, Player)
 +
    Say(Player, "Hello NPC!")
 +
  end
  
[[LUA:GetDistance | GetDistance]]
+
Current ''standards'' we have adopted are to use '''NPC''' as the value for the NPCs parameters, and depending on the type of script, '''Spawn''' or '''Player''' for the Players parameters. Nearly all other parameter values are dynamic - that is, they can be any valid variable name you choose. But when coding scripts for the Official EQ2Emulator Project, be sure to follow ''our guidelines'' or your scripts will get rejected.
  
[[LUA:GetHeading | GetHeading]]
 
  
[[LUA:GetInt | GetInt]]
+
{{Header|LUA Functions|BackgroundColor=3d78b4|FontColor=ffffff}}
 +
Our LUA Functions list is broken into several categories for clarity of functionality. New functions are added often, so check this page often for changes.
  
[[LUA:GetLevel | GetLevel]]
 
  
[[LUA:GetLootCoin | GetLootCoin]]
+
=== IMPORTANT ===
 +
When adding LUA Command documentation to this Wiki, please be sure to use the
 +
[[LUA:CommandTemplate|LUA Command Template]] provided to maintain consistency across all our pages.
  
[[LUA:GetMaxHP | GetMaxHP]]
 
  
[[LUA:GetMaxPower | GetMaxPower]]
+
Below are the function names and a brief description of what the function does. For details on required parameters and usage, click the function name.
  
[[LUA:GetName | GetName]]
 
  
[[LUA:GetNPC | GetNPC]]
+
=== All Functions ===
 +
All the LUA functions EQ2Emu currently has.
  
[[LUA:GetRace | GetRace]]
+
[[LUA:AllFunctions|All Functions]]
  
[[LUA:GetRaceType | GetRaceType]]
 
  
[[LUA:GetSpawn | GetSpawn]]
+
=== Get Functions ===
 +
This set of functions will ''GET'' info from the World or Database for use within any LUA script.
  
[[LUA:GetSpeed | GetSpeed]]
+
[[LUA:GetFunctions|Get Functions]]
  
[[LUA:GetSta | GetSta]]
 
 
[[LUA:GetStr | GetStr]]
 
 
[[LUA:GetWis | GetWis]]
 
 
[[LUA:GetX | GetX]]
 
 
[[LUA:GetY | GetY]]
 
 
[[LUA:GetZ | GetZ]]
 
 
[[LUA:GetZone | GetZone]]
 
 
[[LUA:GetZoneID | GetZoneID]]
 
 
[[LUA:GetZoneName | GetZoneName]]
 
 
[[LUA:HasItem | HasItem]]
 
 
[[LUA:HasMoved | HasMoved]]
 
  
 
=== Set Functions ===
 
=== Set Functions ===
 
This set of functions will ''SET'' info in the World or Database from within any LUA script
 
This set of functions will ''SET'' info in the World or Database from within any LUA script
  
Developer: [[Team:LethalEncounter | LethalEncounter]], [[Team:Scatman | Scatman]]
+
[[LUA:SetFunctions|Set Functions]]
 
 
 
 
[[LUA:ModifyHP | ModifyHP]]
 
 
 
[[LUA:ModifyMaxHP | ModifyMaxHP]]
 
 
 
[[LUA:ModifyMaxPower | ModifyMaxPower]]
 
 
 
[[LUA:ModifyPower | ModifyPower]]
 
 
 
[[LUA:SetAgi | SetAgi]]
 
 
 
[[LUA:SetCurrentHP | SetCurrentHP]]
 
 
 
[[LUA:SetCurrentPower | SetCurrentPower]]
 
 
 
[[LUA:SetHeading | SetHeading]]
 
 
 
[[LUA:SetInt | SetInt]]
 
 
 
[[LUA:SetLootCoin | SetLootCoin]]
 
 
 
[[LUA:SetMaxHP | SetMaxHP]]
 
 
 
[[LUA:SetMaxPower | SetMaxPower]]
 
 
 
[[LUA:SetPosition | SetPosition]]
 
 
 
[[LUA:SetRaceType | SetRaceType]]
 
 
 
[[LUA:SetSpeed | SetSpeed]]
 
 
 
[[LUA:SetSta | SetSta]]
 
 
 
[[LUA:SetStr | SetStr]]
 
 
 
[[LUA:SetWis | SetWis]]
 
 
 
[[LUA:SpawnSet | SpawnSet]]
 
 
 
[[LUA:SpawnSetByDistance | SpawnSetByDistance]]
 
 
 
[[LUA:SummonItem | SummonItem]]
 
  
[[LUA:RemoveItem | RemoveItem]]
 
  
[[LUA:SetMount | SetMount(Spawn, mount_mode_type (int))]]
+
=== Item Functions ===
 
+
This set of function are used to make game Items perform special tasks (clickies or quest items)
[[LUA:SetMountColor | SetMountColor(Spawn, horse_color_red, horse_color_green, horse_color_blue, horse_color_saddle_red, horse_color_saddle_green, horse_color_saddle_blue)]]
 
  
 +
[[LUA:ItemFunctions|Item Functions]]
  
  
Line 159: Line 82:
 
These functions are for use within Quest scripts, and are some of the more complex LUA Functions in the EQ2Emulator.
 
These functions are for use within Quest scripts, and are some of the more complex LUA Functions in the EQ2Emulator.
  
Developer: [[Team:LethalEncounter | LethalEncounter]], [[Team:Scatman | Scatman]]
+
[[LUA:QuestFunctions|Quest Functions]]
 
 
 
 
 
 
[[LUA:Accepted | Accepted]]
 
 
 
[[LUA:AddQuestPrereqClass | AddQuestPrereqClass]]
 
 
 
[[LUA:AddQuestPrereqFaction | AddQuestPrereqFaction]]
 
 
 
[[LUA:AddQuestPrereqItem | AddQuestPrereqItem]]
 
 
 
[[LUA:SetQuestPrereqLevel | SetQuestPrereqLevel]]
 
 
 
[[LUA:AddQuestPrereqQuest | AddQuestPrereqQuest]]
 
 
 
[[LUA:AddQuestPrereqRace | AddQuestPrereqRace]]
 
 
 
[[LUA:AddQuestPrereqTradeskillLevel  | AddQuestPrereqTradeskillLevel ]]
 
 
 
[[LUA:AddQuestPrereqTradeskillClass  | AddQuestPrereqTradeskillClass ]]
 
 
 
[[LUA:AddQuestRewardCoin | AddQuestRewardCoin]]
 
 
 
[[LUA:AddQuestRewardItem | AddQuestRewardItem]]
 
 
 
[[LUA:AddQuestRewardFaction | AddQuestRewardFaction]]
 
 
 
[[LUA:AddQuestSelectableRewardItem | AddQuestSelectableRewardItem]]
 
 
 
[[LUA:AddQuestStep | AddQuestStep]]
 
 
 
[[LUA:AddQuestStepChat | AddQuestStepChat]]
 
 
 
[[LUA:AddQuestStepCompleteAction | AddQuestStepCompleteAction]]
 
 
 
[[LUA:AddQuestStepKill | AddQuestStepKill]]
 
 
 
[[LUA:AddQuestStepLocation | AddQuestStepLocation]]
 
 
 
[[LUA:AddQuestStepObtainItem | AddQuestStepObtainItem]]
 
 
 
[[LUA:AddQuestStepSpell | AddQuestStepSpell]]
 
 
 
[[LUA:AddStepProgress | AddStepProgress]]
 
 
 
[[LUA:AddTimer | AddTimer]]
 
 
 
[[LUA:Declined | Declined]]
 
 
 
[[LUA:GetQuest | GetQuest]]
 
 
 
[[LUA:GetQuestStep | GetQuestStep]]
 
 
 
[[LUA:GetTaskGroupStep | GetTaskGroupStep]]
 
 
 
[[LUA:GiveQuestReward | GiveQuestReward]]
 
 
 
[[LUA:HasCompletedQuest | HasCompletedQuest]]
 
 
 
[[LUA:HasQuest | HasQuest]]
 
 
 
[[LUA:OfferQuest | OfferQuest]]
 
 
 
[[LUA:ProvidesQuest | ProvidesQuest]]
 
  
[[LUA:QuestIsComplete | QuestIsComplete]]
 
 
[[LUA:QuestReturnNPC | QuestReturnNPC]]
 
 
[[LUA:QuestStepIsComplete | QuestStepIsComplete]]
 
 
[[LUA:RegisterQuest | RegisterQuest]]
 
 
[[LUA:Reload | Reload]]
 
 
[[LUA:SetCompletedDescription | SetCompletedDescription]]
 
 
[[LUA:SetQuestCompleteAction | SetQuestCompleteAction]]
 
 
[[LUA:SetQuestRewardComment | SetQuestRewardComment]]
 
 
[[LUA:SetQuestRewardExp | SetQuestRewardExp]]
 
 
[[LUA:SetQuestRewardStatus | SetQuestRewardStatus]]
 
 
[[LUA:SetRequiredQuest | SetRequiredQuest]]
 
 
[[LUA:SetStepComplete | SetStepComplete]]
 
 
[[LUA:UpdateQuestDescription | UpdateQuestDescription]]
 
 
[[LUA:UpdateQuestStepDescription | UpdateQuestStepDescription]]
 
 
[[LUA:UpdateQuestTaskGroupDescription | UpdateQuestTaskGroupDescription]]
 
 
[[LUA:UpdateQuestZone | UpdateQuestZone]]
 
  
 
=== Spell Functions ===
 
=== Spell Functions ===
 
These functions are used within Spell scripts to generate the expected effect of casting spells or using abilities.
 
These functions are used within Spell scripts to generate the expected effect of casting spells or using abilities.
  
Developer: [[Team:LethalEncounter | LethalEncounter]]
+
[[LUA:SpellFunctions|Spell Functions]]
 
 
 
 
'''SPECIAL NOTE ABOUT SPELL FUNCTIONS''':
 
Many spells simply alter an existing stat of one kind or another to yourself or a target, so there are not very many "spell functions" to speak of. SpellDamage is one of the few, since buffing, debuffing, or slowing (etc) a target are done through the '''SET''' Functions inside a Spell Script.
 
  
 
[[LUA:SpellDamage | SpellDamage]]
 
  
 
=== Spawn Functions ===
 
=== Spawn Functions ===
 
These are functions that normally go into SpawnScripts for interacting with NPCs or other types of Spawns.
 
These are functions that normally go into SpawnScripts for interacting with NPCs or other types of Spawns.
  
Developer: [[Team:LethalEncounter | LethalEncounter]], [[Team:Scatman | Scatman]]
+
[[LUA:SpawnFunctions|Spawn Functions]]
  
  
[[LUA:AddConversationOption | AddConversationOption]]
+
=== General Functions ===
 +
These are general functions that do not fall under any other classification.
  
[[LUA:AddLootCoin | AddLootCoin]]
+
[[LUA:MiscFunctions|Miscellaneous Functions]]
  
[[LUA:AddLootItem | AddLootItem]]
 
  
[[LUA:aggro | aggro]]
+
{{Header|LUA Script Examples|BackgroundColor=3d78b4|FontColor=ffffff}}
 +
Just a few examples of what you can do with LUA Scripting and EQ2Emulator custom functions... This is by no means a comprehensive list, just some concepts in use:
  
[[LUA:attacked | attacked]]
+
  function hailed(NPC, Spawn)
 +
    Say(NPC, "Your class is " .. GetClass(Spawn) .. "!")
 +
  end
  
[[LUA:casted_on | casted_on]]
+
This makes the NPC respond to the player who hails it with the players class.
  
[[LUA:CreateConversation | CreateConversation]]
 
  
[[LUA:death | death]]
+
  function ChangePlayerClass(NPC, Spawn)
 
+
    ''var'' = GetClass(Spawn)
[[LUA:Emote | Emote]]
+
    SetClass(Spawn, 1)                                       -- changes Spawn to class 1
 
+
    .
[[LUA:Despawn | Despawn]]
+
    .
 
+
    .
[[LUA:FaceTarget | Face Targer]]
+
    SetClass(Spawn, ''var'')                                      -- changes Spawn back to original class
 
+
  end
[[LUA:hailed | hailed]]
 
 
 
[[LUA:hailed_busy | hailed_busy]]
 
 
 
[[LUA:healthchanged | healthchanged]]
 
 
 
[[LUA:IsAlive | IsAlive]]
 
 
 
[[LUA:killed | killed]]
 
 
 
[[LUA:KillSpawn | KillSpawn]]
 
 
 
[[LUA:KillSpawnByDistance | KillSpawnByDistance]]
 
 
 
[[LUA:MoveToLocation | MoveToLocation]]
 
 
 
[[LUA:MovementLoopAddLocation | MovementLoopAddLocation(Spawn, x, y, z, speed, delay, function)]]
 
 
 
[[LUA:PlayFlavor | PlayFlavor]]
 
 
 
[[LUA:PlaySound | PlaySounds]]
 
 
 
[[LUA:PlayVoice| PlayVoice]]
 
 
 
[[LUA:RemoveLootItem | RemoveLootItem]]
 
 
 
[[LUA:respawn | respawn]]
 
 
 
[[LUA:Say | Say]]
 
 
 
[[LUA:SayOOC | SayOOC]]
 
 
 
[[LUA:Shout | Shout]]
 
 
 
[[LUA:spawn | spawn]]
 
 
 
[[LUA:SpawnMob | SpawnMob]]
 
 
 
[[LUA:StartConversation | StartConversation]]
 
 
 
[[LUA:targeted | targeted]]
 
 
 
 
 
 
 
=== General Functions ===
 
These are general functions that are either to set/retrieve player or ''target'' data, or get references to nearby objects.
 
  
Developer: [[Team:LethalEncounter | LethalEncounter]], [[Team:Scatman | Scatman]]
+
Sets variable ''var'' to the value of the function for use in other parts of the script, for example returning to original value after function has completed.
  
  
[[LUA:GetCurrentZoneSafeLocation | GetCurrentZoneSafeLocation]]
+
{{Header|SpawnScripts|BackgroundColor=3d78b4|FontColor=ffffff}}
 +
[[ContentDesigner:SpawnScripts|SpawnScripts]] are what gives your NPC's life. The emulator uses LUA as its scripting engine, and combined with spawnscripts a NPC can preform actions like move, attack, and have conversations.
  
[[LUA:HasMoved | HasMoved]]
 
  
[[LUA:IsPlayer | IsPlayer]]
+
{{Header|Quests|BackgroundColor=3d78b4|FontColor=ffffff}}
 +
Coming Soon
  
[[LUA:SetPlayerProximityFunction | SetPlayerProximityFunction]]
 
  
[[LUA:Zone | Zone]]
+
{{Header|Conclusion|BackgroundColor=3d78b4|FontColor=ffffff}}
 +
LUA functions are added often, usually when we discover some new way that DayBreak does their spawns, quests or other content. If you find you are unable to achieve your goal in your scripting, it is possible you need a LUA function added. You can either choose to develop your own LUA function and submit it to the core Devs for inclusion, or post your requirements in the Feature Request forum for a script dev to add to the server.
  
  
== Conclusion ==
+
[[Systems|Back to Systems]]
LUA functions are added often, usually when we discover some new way that SOE does their spawns, quests or other content. If you find you are unable to achieve your goal in your scripting, it is possible you need a LUA function added. You can either choose to develop your own LUA function and submit it to the core Devs for inclusion, or post your requirements in the Feature Request forum for a script dev to add to the server.
 

Latest revision as of 07:03, 29 July 2016


EQ2Emulator: LUA Scripting

LUA Scripting is extending the functionality of the server without the need to recompile the code each time you wish to add some form of interaction with an NPC, an event happening in a zone, quest steps for players to work through, etc.


What is "LUA"?

For a comprehensive look at what LUA is, please visit the lua.org website and read their own About information. On this Wiki, we shall only discuss our own implementation of LUA.


We have chosen LUA as our script engine for EQ2Emulator. Things like Quests, Spawn movement or interaction, Spells, and Zone-wide events are scripted in LUA using custom functions specific to the emulator core. Below you will find a list of current EQ2Emulator LUA Functions with links to what they do and examples of how to use them.

You will quickly see that the ease of the LUA Scripting language and it's tight integration with EQ2Emulator make our server extremely dynamic and customizable.


Currently, EQ2Emulator employs LUA scripting for the following systems:

Spawns

Spells

Quests

Items

Zones


Follow any of these links for a closer look at the system. Below is a general list of LUA functions we'll keep at this top-level for easier reference.


LUA Parameter Basics

EQ2Emulator LUA Functions normally have parameters - that is, some value required to be passed from the World to the Script or vice-versa. An example of this is the function hailed(NPC, Spawn). Note that there are 2 parameters for function hailed(). What the parameter names are is up to you, as long as there are the proper number of parameters in the () parens.


Example: Here, the Player says Hello to the NPC.

 function hailed(NPC, Player)
   Say(Player, "Hello NPC!")
 end

Current standards we have adopted are to use NPC as the value for the NPCs parameters, and depending on the type of script, Spawn or Player for the Players parameters. Nearly all other parameter values are dynamic - that is, they can be any valid variable name you choose. But when coding scripts for the Official EQ2Emulator Project, be sure to follow our guidelines or your scripts will get rejected.


LUA Functions

Our LUA Functions list is broken into several categories for clarity of functionality. New functions are added often, so check this page often for changes.


IMPORTANT

When adding LUA Command documentation to this Wiki, please be sure to use the 
LUA Command Template provided to maintain consistency across all our pages.


Below are the function names and a brief description of what the function does. For details on required parameters and usage, click the function name.


All Functions

All the LUA functions EQ2Emu currently has.

All Functions


Get Functions

This set of functions will GET info from the World or Database for use within any LUA script.

Get Functions


Set Functions

This set of functions will SET info in the World or Database from within any LUA script

Set Functions


Item Functions

This set of function are used to make game Items perform special tasks (clickies or quest items)

Item Functions


Quest Functions

These functions are for use within Quest scripts, and are some of the more complex LUA Functions in the EQ2Emulator.

Quest Functions


Spell Functions

These functions are used within Spell scripts to generate the expected effect of casting spells or using abilities.

Spell Functions


Spawn Functions

These are functions that normally go into SpawnScripts for interacting with NPCs or other types of Spawns.

Spawn Functions


General Functions

These are general functions that do not fall under any other classification.

Miscellaneous Functions


LUA Script Examples

Just a few examples of what you can do with LUA Scripting and EQ2Emulator custom functions... This is by no means a comprehensive list, just some concepts in use:

 function hailed(NPC, Spawn)
   Say(NPC, "Your class is " .. GetClass(Spawn) .. "!")
 end

This makes the NPC respond to the player who hails it with the players class.


 function ChangePlayerClass(NPC, Spawn)
   var = GetClass(Spawn)
   SetClass(Spawn, 1)                                        -- changes Spawn to class 1
   .
   .
   .
   SetClass(Spawn, var)                                      -- changes Spawn back to original class
 end

Sets variable var to the value of the function for use in other parts of the script, for example returning to original value after function has completed.


SpawnScripts

SpawnScripts are what gives your NPC's life. The emulator uses LUA as its scripting engine, and combined with spawnscripts a NPC can preform actions like move, attack, and have conversations.


Quests

Coming Soon


Conclusion

LUA functions are added often, usually when we discover some new way that DayBreak does their spawns, quests or other content. If you find you are unable to achieve your goal in your scripting, it is possible you need a LUA function added. You can either choose to develop your own LUA function and submit it to the core Devs for inclusion, or post your requirements in the Feature Request forum for a script dev to add to the server.


Back to Systems