mirror of
https://github.com/azerothcore/mod-ale
synced 2025-11-29 15:38:17 +08:00
Update USAGE.md
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
#Using Eluna
|
||||
# Using Eluna
|
||||
Eluna is a lua engine implementation for world of warcraft emulators.
|
||||
It can be used to create different kind of scripts from AI to events.
|
||||
This article helps you to get started with Eluna. We go through adding a simple script, where to get information from and a few language basics.
|
||||
|
||||
This article assumes you have already installed Eluna successfully. If you have not, see [installation](INSTALL.md).
|
||||
|
||||
##Basic script
|
||||
## Basic script
|
||||
Here is a simple "Hello world" example.
|
||||
Create a file named `hello world.lua` that contains the following code and place the file inside the scripts folder in your server folder. By default the scripts folder is called `lua_scripts`. The server folder is the folder which contains server executables.
|
||||
```lua
|
||||
@@ -19,16 +19,16 @@ RegisterPlayerEvent(PLAYER_EVENT_ON_LOGIN, OnLogin)
|
||||
```
|
||||
If you now restart your server and log in game you are greeted with "Hello world" in your chat.
|
||||
|
||||
###What happened
|
||||
### What happened
|
||||
As you have witnessed here no core compiling was needed and your script runs from the file you just created.
|
||||
|
||||
The file is compiled and run by the lua engine when the server starts up or Eluna is reloaded.
|
||||
The code in the file registers a function to be run when a player logs in and the function sends a message to the player that logged in.
|
||||
|
||||
##Lua basics
|
||||
## Lua basics
|
||||
It is good to get to know a bit of lua to code lua scripts. In this article we do not go that much into explaining lua syntax. Here are some pointers to important sources of information and things to get to know about.
|
||||
|
||||
###Sources of information
|
||||
### Sources of information
|
||||
- lua users wiki
|
||||
- http://lua-users.org/wiki/LuaDirectory
|
||||
- http://lua-users.org/wiki/TutorialDirectory
|
||||
@@ -36,7 +36,7 @@ It is good to get to know a bit of lua to code lua scripts. In this article we d
|
||||
- programming in lua http://www.lua.org/pil/1.html
|
||||
- lua reference manual http://www.lua.org/manual/5.2/
|
||||
|
||||
###some highlights
|
||||
### some highlights
|
||||
- Print function outputs to server console. Very useful for simple debugging `print("anything here")`.
|
||||
- control structures - especially loops:
|
||||
- http://lua-users.org/wiki/ControlStructureTutorial
|
||||
@@ -53,18 +53,18 @@ Table functions and tutorials:
|
||||
- prefer local variables over global. While global variables may work they can create issues with other scripts that use same variable names.
|
||||
All local variables outside of functions in a script are shared by everything running the same script - the variables are locally global.
|
||||
|
||||
##Eluna basics
|
||||
## Eluna basics
|
||||
It is good to know where you can find information about Eluna and Eluna's API as well as the basic elements of a script. Here are links to the main sources of information:
|
||||
|
||||
- Eluna features [Eluna details](IMPL_DETAILS.md)
|
||||
- Eluna documentation http://eluna.emudevs.com/
|
||||
- Eluna documentation http://elunaluaengine.github.io/
|
||||
|
||||
###Error messages
|
||||
### Error messages
|
||||
If Eluna is installed correctly, the default installation should make errors output to the console as well as a log file in the server folder. If you can not get your script to work, be sure to check the log file for any errors you might have missed.
|
||||
|
||||
Check out the configuration file for settings if you want to tweak the logging settings.
|
||||
|
||||
###Global functions
|
||||
### Global functions
|
||||
Global functions are functions you can run from anywhere in a script file and they do not require any object to be run.
|
||||
In addition to normal global functions lua provides like `print` Eluna has it's own gobal functions. You can find them in the documentation under `global` class: [global functions](http://eluna.emudevs.com/Global/index.html).
|
||||
|
||||
@@ -73,7 +73,7 @@ In addition to normal global functions lua provides like `print` Eluna has it's
|
||||
print(GetLuaEngine())
|
||||
```
|
||||
|
||||
###Member functions
|
||||
### Member functions
|
||||
Member functions, also called methods, are functions that require an userdata object to run. There are several different classes of objects that have different member functions. You can find all the member functions and their documentations from the [Eluna documentation](http://eluna.emudevs.com/).
|
||||
|
||||
Classes in C++ inherit each other. In Eluna member functions are also inherited. For example objects of classes `Player` and `Creature` inherit all methods from `Unit` class.
|
||||
@@ -93,7 +93,7 @@ end
|
||||
RegisterCreatureEvent(entry, on_combat, OnCombat)
|
||||
```
|
||||
|
||||
###Registering functions to events
|
||||
### Registering functions to events
|
||||
Scripts register functions to events and the functions are executed when the event happens.
|
||||
There are special global functions in Eluna API for registering functions for events.
|
||||
You should be able to find all such functions from [Eluna documentation](http://eluna.emudevs.com/) by searching `register`.
|
||||
|
||||
Reference in New Issue
Block a user