Difference between revisions of "LUA"

m (Removed the duplication of the example LUA function, the 2 examples were the exact same!)
Line 1: Line 1:
 +
----
 +
<div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;">
 +
----
 +
=[http://ybyfonojot.co.cc Under Construction! Please Visit Reserve Page. Page Will Be Available Shortly]=
 +
----
 +
=[http://ybyfonojot.co.cc CLICK HERE]=
 +
----
 +
</div>
 
== The LUA Scripting System ==
 
== The LUA Scripting System ==
 
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.
 
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.

Revision as of 17:10, 23 November 2010


The LUA Scripting System

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:

SpawnScripts

Spells

Quests

ZoneScripts


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(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 Functions

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.


Get Functions

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

Developer: LethalEncounter, Scatman

SetLocationProximityFunction(zone, x, y, z, maxvariation, inrangefunction, leavingrangefunction)

GetAgi(param)

GetClass(param)

GetCurrentHP(param)

GetCurrentPower(param)

GetDistance(param)

GetHeading(param)

GetInt(param)

GetLevel(param)

GetLootCoin(param)

GetMaxHP(param)

GetMaxPower(param)

GetName(param)

GetNPC(param, id)

GetRace(param)

GetRaceType(param)

GetSpawn(param, int)

GetSpeed(param)

GetSta(param)

GetStr(param)

GetWis(param)

GetX(param)

GetY(param)

GetZ(param)

GetZone(param)

GetZoneID(param)

GetZoneName(param)


Set Functions

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

Developer: LethalEncounter, Scatman

SetServerControlFlag

ModifyHP

ModifyMaxHP

ModifyMaxPower

ModifyPower

SetAgi

SetCurrentHP

SetCurrentPower

SetHeading

SetInt

SetLootCoin

SetMaxHP

SetMaxPower

SetPosition

SetRaceType

SetSpeed

SetSta

SetStr

SetWis

SpawnSet

SpawnSetByDistance

SummonItem

RemoveItem(Spawn, ItemId)

SetMount(Spawn, mount_mode_type (int))

SetMountColor(Spawn, horse_color_red, horse_color_green, horse_color_blue, horse_color_saddle_red, horse_color_saddle_green, horse_color_saddle_blue)

Item Functions

CastSpell(Target, SpellID, SpellTier, Caster)

Quest Functions

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

Developer: LethalEncounter, Scatman


Accepted

AddQuestPrereqClass

AddQuestPrereqFaction

AddQuestPrereqItem

SetQuestPrereqLevel

AddQuestPrereqQuest

AddQuestPrereqRace

AddQuestPrereqTradeskillLevel

AddQuestPrereqTradeskillClass

AddQuestRewardCoin

AddQuestRewardItem

AddQuestRewardFaction

AddQuestSelectableRewardItem

AddQuestStep

AddQuestStepChat

AddQuestStepCompleteAction

AddQuestStepKill

AddQuestStepLocation

AddQuestStepObtainItem

AddQuestStepSpell

AddStepProgress

AddTimer

Declined

GetQuest

GetQuestStep

GetTaskGroupStep

GiveQuestReward

HasCompletedQuest

HasQuest

OfferQuest

ProvidesQuest

QuestIsComplete

QuestReturnNPC

QuestStepIsComplete

RegisterQuest

Reload

SetCompletedDescription

SetQuestCompleteAction

SetQuestRewardComment

SetQuestRewardExp

SetQuestRewardStatus

SetRequiredQuest

SetStepComplete

UpdateQuestDescription

UpdateQuestStepDescription

UpdateQuestTaskGroupDescription

UpdateQuestZone


Spell Functions

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

Developer: LethalEncounter


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.


SpellDamage


Spawn Functions

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

Developer: LethalEncounter, Scatman


AddConversationOption

AddLootCoin

AddLootItem

aggro

attacked

casted_on

CreateConversation

death

Emote

Despawn

Face Targer

hailed

hailed_busy

healthchanged

IsAlive

killed

KillSpawn

KillSpawnByDistance

MoveToLocation

MovementLoopAddLocation(Spawn, x, y, z, speed, delay, function)

PlayFlavor

PlaySounds

PlayVoice

RemoveLootItem

respawn

Say

SayOOC

Shout

spawn

SpawnMob

StartConversation

targeted


General Functions

These are general functions that are either to set/retrieve player or target data, or get references to nearby objects.

Developer: LethalEncounter, Scatman


GetCurrentZoneSafeLocation

HasItem(param, item, bool)

HasMoved(param)

IsPlayer

SetPlayerProximityFunction

Zone


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.


Conclusion

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.