Server Data Structure and Global
The Server Data API provides various global functions for managing game-wide data, events, store systems, player rankings, and server-level interactions.
Event & Offer Management
getRequiredEvent() -- Returns the required event.
getCurrentServerDailyEvent() -- Returns the current server's daily event.
getServerCurrentEvent() -- Returns the current server's event.
getIOTMItem() -- Returns the IOTM (Item of the Month) item.
addDailyOfferPurchased(player:getUserID(), changethis:getItemID()) -- Adds a daily offer purchased entry.
getRealGTItemsCount() -- Returns the total number of real GT items.
getEventOffers() -- Returns the list of current event offers.
getActiveDailyOffers() -- Returns all active daily offers.
setEvent(event_id) -- Sets the current server event.
setDailyEvent(event_id) -- Sets the current daily event.Custom Daily Events:
local eventData = {
id = 50,
title = "Example event",
description = "Example description"
}
registerLuaDailyEvent(eventData)Custom Event Registration:
registerLuaEvent(eventData) -- Registers a custom server-wide event.Economy Management
Get item counts across the server economy:
getEcoQuantity(item_id) -- Returns total count of item in economy (players + worlds).
getEcoQuantityPlayers(item_id) -- Returns count of item in player inventories only.
getEcoQuantityWorlds(item_id) -- Returns count of item in worlds only.Economy Tracking
These functions help you track item circulation across your entire server, useful for balancing economy and detecting duplication.
Redeem Code System
Create custom redeem codes with various requirements and rewards:
local redeemData = {
redeemCode = "SPECIAL123",
obtainGems = 50,
obtainCoins = 1000,
obtainRole = 2,
redeemItems = {
{ id = 1001, count = 3 },
{ id = 2002, count = 1 },
},
maxUses = 5,
requireLevel = 10,
requireRole = 1,
requireGrowID = 1, -- (1 = true, 0 = false)
requirePlaytime = 60,
requireAccountAge = 7,
redeemTitles = {
{ titleID = 5 },
{ titleID = 9 },
}
}
local result = createRedeemCode(redeemData)
if result ~= "" then
print("Created redeem code:", result)
endFlexible Reward System
Redeem codes support gems, coins, items, titles, and roles with granular requirement controls!
Broadcast World Management
setBroadcastWorld(world_name) -- Sets broadcast world for all online players (/go command).Purchase & Store System
onPurchaseItem(player, item, true/false) -- Fires the item purchase event.
onPurchaseItemReq(player, itemID) -- Fires the item purchase request event.
getStoreItems() -- Returns the list of store items.
getEnumItem("ITEM_[NAME]") -- Returns the item object using its enum name.Player & World Rankings
getTopPlayerByBalance() -- Returns the top player based on balance.
getTopWorldByVisitors() -- Returns the top world based on visitors.Lua Module & Playmod System
registerLuaPlaymod(PLAYMODDATA) -- Registers a Lua-based playmod configuration.
addMod(MODID, amount) -- Adds a specific playmod modifier.
reloadScripts() -- Reloads all Lua scripts.Data Management
loadDataFromServer(data) -- Loads data from the server.
loadData() -- Loads general saved data.
saveDataToServer(data, data2) -- Saves data to the server.
onAutoSaveRequest(function()) -- Executes on auto-save event.Server Information
getExpireTime() -- Returns the server's expire time.
getServerName() -- Returns the server name.
getServerID() -- Returns the server ID.
getServerPlayers() -- Returns a list of players currently on the server.
getAllPlayers() -- Get all players (use this over getServerPlayers).
getServerWorlds() -- Returns all active (loaded in-memory) worlds.
getNewsBanner() -- Returns the current news banner.
getNewsBannerDimensions() -- Returns the dimensions of the news banner.
getTodaysDate() -- Returns today's date.
getTodaysEvents() -- Returns today's events.
getCurrentEventDescription() -- Returns the description of the current event.
getCurrentDailyEventDescription() -- Returns the description of the current daily event.
getCurrentRoleDayDescription() -- Returns the description of the current role day.
getServerDefaultPort() -- Returns the server's port number.Server Management & Control
queueRestart(in_seconds, full_restart, message) -- Restarts server after delay.
-- full_restart: 0 = soft restart, 1 = full restart
-- message: optional restart message to players
deleteAccount(user_id) -- ⚠️ EXPERIMENTAL: Permanently deletes account data.
deleteWorld(world_id) -- ⚠️ EXPERIMENTAL: Permanently deletes world data.Dangerous Operations
Warning: Deletion is permanent. Deleted users/worlds show as “ERROR” in ownership data. Always backup before using!
Lua Modules System
Load other Lua scripts as modules for better code organization:
local Person = require("example_module")
local me = Person.new("Yuki")
me:say("Hello!")Creating a Module:
Add -- MODULE at the start of your module file:
-- MODULE
local person = {}
function person.new(name)
local self = {name = name}
function self:say(msg)
print(self.name .. " says: " .. msg)
end
return self
end
return personModule System
Modules are only loaded when required, not on startup. This keeps your server efficient and your code organized!
File System Operations
Create, read, and manage files via Lua:
file.read(path) -- Read file contents as string.
file.write(path, content) -- Write content to file.
file.exists(path) -- Check if file exists.
file.delete(path) -- Delete a file.
dir.create(path) -- Create a directory.
dir.exists(path) -- Check if directory exists.
dir.delete(path) -- Delete a directory.Example:
local server_conf = file.read("config/conf.json")
print(server_conf)
file.write("config/random_file.txt", "hi")
local content = file.read("config/random_file.txt")
print(content)File System Safety
Be extremely careful with delete operations - you can accidentally delete critical server files!
SQL Database Support
Use SQLite databases to store custom data:
local db = sqlite.open("test1.db")
db:query("CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT)")
local ok, last_id = db:query("INSERT INTO users(name) VALUES('Nyaa')")
if ok then
print("Created new user: " .. last_id)
end
local rows = db:query("SELECT * FROM users")
for i, row in ipairs(rows) do
print(i, row.id, row.name)
end
db:close()Persistent Data Storage
SQLite provides a robust way to store structured data that persists across server restarts!
HTTP Request Handling
Handle HTTP requests to your server via Lua:
print("HTTP Lua API running on port: " .. getServerDefaultPort())
onHTTPRequest(function(req) -- MUST return a response!
-- Access original request headers
local userAgent = req.headers["User-Agent"]
if req.method == "get" and req.path == "/hello" then
return {
status = 200,
body = "Hello back",
headers = { ["Content-Type"] = "text/plain" }
}
end
if req.method == "post" and req.path == "/echo" then
return {
status = 200,
body = "Body: " .. req.body,
headers = { ["Content-Type"] = "text/plain" }
}
end
return {
status = 404,
body = "Not found",
headers = {}
}
end)HTTP API URL Format
https://api.gtps.cloud/g-api/{server_port}/...
The callback shows the real request IP instead of localhost.
JSON Encoding
Pretty print JSON data:
json.encode(data) -- Compact encoding
json.encode(data, 4) -- Pretty print with 4-space indentationDiscord Integration
Handle Discord bot events via Lua callbacks:
Message Create Callback
onDiscordMessageCreateCallback(function(event)
if event:isBot() then return end
local content = event:getContent()
local channel_id = event:getChannelID() -- String
print("Message: " .. content .. " (Channel " .. channel_id .. ")")
if content:sub(1, 6) == "-hello" then
event:reply(
"This is a test message with a button",
{
{
type = "button",
label = "Click me!",
style = "success",
emoji = "🔓",
id = "click_click"
}
}
)
end
end)Button Click Callback
onDiscordButtonClickCallback(function(event)
local custom_id = event:getCustomID()
local channel_id = event:getChannelID()
if custom_id == "click_click" then
event:dialog({
id = "random_modal",
title = "Hello World",
components = {
{
type = "text",
label = "Enter some text",
id = "entered_text",
placeholder = "Text",
min = 3,
max = 32,
style = "short"
}
}
})
end
end)Form Submit Callback
onDiscordFormSubmitCallback(function(event)
local custom_id = event:getCustomID()
if custom_id == "random_modal" then
local entered_value = event:getValue("entered_text")
event:reply("You entered " .. entered_value)
end
end)Discord Bot Integration
Create interactive Discord bots with buttons, modals, and forms directly from Lua!
World Menu Management
addWorldMenuWorld(worldID, displayName, color, priority) -- Adds a world to the world menu.
removeWorldMenuWorld(worldID) -- Removes a world from the world menu.
hideWorldMenuDefaultSpecialWorlds(0/1) -- Hides or shows default special worlds (1 = hide, 0 = show).Server Persistence (Key-Based)
loadDataFromServer(key) -- Loads a Lua table using a key from the server.
saveDataToServer(key, dataTable) -- Saves a Lua table to the server using a specific key.
loadStringFromServer(key) -- Loads a string value from the server.
saveStringToServer(key, value) -- Saves a string value to the server.UI & Event Registration
registerLuaEvent(eventData) -- Registers a custom server-wide event.
addSidebarButton(buttonJson) -- Adds a button to the player's sidebar UI using a JSON definition.
addSocialPortalButton(buttonDef, callback) -- Adds a button to the social portal with an assigned callback.