Processing flow of a button click
- The player clicks a button in the window; the client-side script calls
UI.Send(command, data). - The GameServer passes the message to the interface Lua machine. The function
Ui_onUiMessagedecodes the data and calls the function you registered withUI.OnMessage(window, command, function). - Your function re-checks the data, changes game data if valid, then returns the result with
UI.Send/UI.Reply/UI.SetText...
local WINDOW = "Zu"
UI.OnMessage(WINDOW, "info", function(aIndex, data, command)
UI.Send(aIndex, WINDOW, "info", {
name = Ui_Player.GetName(aIndex),
level = Ui_Player.GetLevel(aIndex),
money = Ui_Player.GetMoney(aIndex),
})
end)
Receiving messages from the client
| Function | Purpose |
|---|---|
UI.OnMessage(window, command, handler) | Registers a function that runs when the window window sends the command command. handler(aIndex, data, command): data is a table (an empty table if the client sent nothing). command = "*" = any command that has no function of its own. Registering the same (window, command) pair again replaces the old function. Parameters of the wrong type cause the error UI.OnMessage(window, command, function): bad arguments. |
UI.OnOpen(window, handler) | Function that runs when the window has just opened on the client (hotkey, NPC, button...). handler(aIndex, data, command). Works even if the window has no client script. |
UI.OnClose(window, handler) | Function that runs when the window closes (close button, ESC...). |
Malformed data is dropped and the log [UI] window.command from aIndex: bad data (...) is written. If a handler function fails, the log [UI] window.command: error is written, and other messages keep running.
Sending to the client
| Function | Purpose |
|---|---|
UI.Send(aIndex, window, command, data) | Sends data (table, string, number...) to the window; the client script receives it with OnMessage(command, data). Encoded data exceeding UI.GetMaxData() bytes causes an error. |
UI.Open(aIndex, window, data) | Opens the window on the client (the client receives the command @open with data). |
UI.Close(aIndex, window) | Closes the window on the client. |
UI.Reply(aIndex, window, command, kind, text) | Shows the result of a button in the Text element with the same name as the button (for example the button okexchangegems and the Text okexchangegems). kind: "ok" (green), "error" (red), "warn" (blinking red / yellow), "info" (yellow, default). If there is no such Text element, it is shown in the chat window. |
UI.SetText(aIndex, window, element, text, color) | Changes the text of a Text element; color in the form "RRGGBB" (optional). Text longer than the one-line box scrolls once to the end. |
UI.SetTexts(aIndex, window, texts) | Changes several Text elements at once: { [element] = "text" or { text = "...", color = "RRGGBB" } }. Automatically split into several messages if the data is too large. |
UI.SetEnabled(aIndex, window, element, enabled) | Enables / disables (dims) a button; a disabled button cannot be clicked. If the button has a "Disabled" piece in EDITOR, that piece is shown. |
UI.SetVisible(aIndex, window, element, visible) | Shows / hides an element (Image, Button, Text...). |
UI.SendRaw(aIndex, window, command, textData) | Low level: sends an already encoded string. Returns true if sent; false if the name is wrong, over 900 bytes, or the player is invalid. UI.Send is normally used. |
UI.GetMaxData() | Maximum number of data bytes of one message (900). |
Window names and command names consist only of letters, digits and _ (1 - 31 characters).
Data format
Data between client and server is encoded into a string in a dedicated format (the same code is on the client side in Main.dll):
| Symbol | Type |
|---|---|
n | nil |
t / f | boolean |
d<number>; | number |
s<length>:<bytes> | string |
{ key value ... } | table (key is a string or number) |
UI.Encode(value): value to string (nilbecomes""). Errors if there is a function, userdata, a key that is not a string / number, or a table nested deeper than 8 levels.UI.Decode(text): string to value (an empty string becomes an empty table). Invalid data returnsnil, error message. A limit of 2000 values in one message from the client.
Item slot frame
| Function | Purpose | Returns |
|---|---|---|
UI.BoxItems(aIndex) | Lists the items currently in the window's slots. | Table { { Cell = slot, Window = windowName, Item = itemTable }, ... }; an empty table if none. |
UI.BoxConsume(aIndex, cell) | Takes away the item in slot cell (exchange succeeds). Only use while handling a button click. | true if taken; false if there is none. |
UI.BoxReturn(aIndex) | Returns all items in the slots to the inventory (if the inventory is full, to the Gremory Case). Only use while handling a button click. | none |
The function Ui_onItemPut(aIndex, window, cell, item) decides whether to accept an item placed in (see Interface Lua).
Example: equipment exchange window (module demo1)
The module demo1 in Data\Lua_Ui\Includes\demo1 is a complete example using the item slot frame. Main configuration (Config.lua, table Demo1Config):
| Key | Meaning |
|---|---|
Window | Window name (matches EDITOR and the client's GfxList.xml). |
Button | Command of the OK button (the Text element with the same name shows the result). |
Mode | "all": OK exchanges all items in the slots at once (the reward is multiplied by the number of items); "single": only 1 item may be placed. |
AnyEquipment | true: accepts any equipment (groups 0..11); false: only accepts items in Items. |
Require | Extra conditions: MinExc (minimum number of Excellent options), MinLevel, Luck, Skill, NoAncient; nil = not checked. |
Items | List used when AnyEquipment = false: Group, Index, Level (-1 = any level). |
Reward, RewardName | Reward for each item: Group, Index, Count; name shown in the window. |
Text | The window's Text elements and their text content. |
The client-side files must be copied into the client's Data\Custom\Interface\GFx folder: demo1.ozg (the window, exported from EDITOR), demo1.lua (client script) and GfxList.xml (declares the window, open hotkey, item slot type).