-
Notifications
You must be signed in to change notification settings - Fork 52
Sample #1
MMOMinion edited this page Oct 14, 2013
·
3 revisions
After this little tutorial you should be ablte to understand how to use lua with FFXIVMinion. This code will create a new Window with a start/stop button and a field that holds the current player hp when he is alive.
- Create a new Folder & Files for your new LUA module
- Inside the Folder from where you start GW2Minion, you have a Folder named "Lua".
- Open this Folder and you are seeing all currently existing Lua modules for GW2Minion.
- Create a new Folder with the name of your new module.
- Inside that new Folder, create two new files:
- module.def
- yourmodulename.lua
- Make sure to write module.def correctly!!
- Configurate your Module module.def holds the configuration for your module, the variables used inside are self explaining, so just enter these lines into the module.def file and change them accordingly:
[Module]
Name=MyNewLuaModule
Version=1
Files=yourmodulename.lua
Enabled=1
Dependencies=minionlib -- optional parameter, to include functions from other LUA modules, FFXIVMinion uses minionlib for example
- Write the .lua file code:
-- Create a new table for our code:
mymodule= { }
-- Some local variables we use in our module:
mymodule.running = false
mymodule.lastticks = 0
-- Initializing function, we create a new Window for our module that has 1 button and 1 field to display data:
function mymodule.ModuleInit()
GUI_NewWindow("MyNewWindow",50,50,100,50);
GUI_NewButton("MyNewWindow","Toggle","MYMODULE.TOGGLE");
GUI_NewField("MyNewWindow","HP:","hpvalue");
end
-- The function that gets called when the button is pressed:
function mymodule.ToggleRun()
mymodule.running = not mymodule.running
end
-- The Mainloop function, gets called all the time by FFXIVMinion:
function mymodule.OnUpdateHandler( Event, ticks )
if ( mymodule.running and ticks - mymodule.lastticks > 500 ) then
mymodule.lastticks = ticks
-- if the player is alive, set the current HP value into the new field of our created Window:
if (Player.alive) then
hpvalue = tostring(Player.health.current)
end
end
end
-- Registering the Events
RegisterEventHandler("Gameloop.Update",mymodule.OnUpdateHandler) -- the normal pulse from the gameloop
RegisterEventHandler("MYMODULE.TOGGLE", mymodule.ToggleRun) -- the function that gets called when our button is pressed
RegisterEventHandler("Module.Initalize",mymodule.ModuleInit) -- the initialization function, gets called only once at startup of the game