Skip to content

Server structure

Here you will learn how to work with the server structure.

Basic Server Functions

lua
getMaxLevel() -- Get current max level
getRequiredEvent() -- Get the currently required event.
isVoucher() -- Check if an item is a voucher.
getCurrentServerDailyEvent() -- Get today's server daily event.
getServerCurrentEvent() -- Get the current active event on the server.
getItemID() -- Get the item's ID.
getTitle() -- Get the title of the item or event.
getAmount() -- Get the quantity or amount.
getIOTMItem() -- Get the Item of the Month.
getPrice() -- Get the item's price.
isGrowtoken() -- Check if an item is a Growtoken.
getCategory() -- Get the item category.
getRealGTItemsCount() -- Get the actual Growtopia item count.
getTexture() -- Get the item's texture.
getEventOffers() -- Get current event offers.
getActiveDailyOffers() -- Get today's active daily offers.
getDescription() -- Get item or event description.
getItemsDescription() -- Get description of multiple items.
isRPC() -- Check if the item is an RPC.
getTexturePosX() -- Get X position of texture.
getTexturePosY() -- Get Y position of texture.
getTopPlayerByBalance() -- Get the richest player.
getTopWorldByVisitors() -- Get the most visited world.
getStoreItems() -- Get available store items.
getID() -- Get the ID.
getTileID() -- Get tile ID.
tile:getTileItem() -- Does the same as getItem(id) but its easier to use.
tile:getPosX() -- Get tile X position.
tile:getPosY() -- Get tile Y position.
getExpireTime() -- Get the expiration time.
getServerName() -- Get the server name.
getNewsBanner() -- Get the current news banner.
getNewsBannerDimensions() -- Get the size of the news banner.
getTodaysDate() -- Get today's date.
getTodaysEvents() -- Get all events for today.
getCurrentEventDescription() -- Get description of the current event.
getCurrentDailyEventDescription() -- Get daily event description.
getCurrentRoleDayDescription() -- Get role day description.
getServerID() -- Get the server's ID.
getServerPlayers() -- Get all online players.
getAllPlayers() -- Get all players (Including online & offline)
getCurrentServerEvent() -- Get current server event.

Economy Tracking

lua
getEcoQuantity(item_id)
-- Returns the total number of items with the provided item ID in the economy (players & worlds)

getEcoQuantityPlayers(item_id)
-- Returns the number of items with the provided item ID in the economy (players only)

getEcoQuantityWorlds(item_id)
-- Returns the number of items with the provided item ID in the economy (worlds only)

Example:

lua
local worldLockID = 242
local totalWLs = getEcoQuantity(worldLockID)
local wlsInPlayers = getEcoQuantityPlayers(worldLockID)
local wlsInWorlds = getEcoQuantityWorlds(worldLockID)

print("Total World Locks in economy:", totalWLs)
print("In player inventories:", wlsInPlayers)
print("In worlds:", wlsInWorlds)

Broadcast World (Global)

lua
setBroadcastWorld(world_name)
-- Sets the broadcast world for all players online (same as player:setBroadcastWorld but affects everyone)

Purchase & Modding Functions

lua
makePurchaseItem(amount) -- (Server only) Purchase an item.
onStorePurchaseResult() -- (Server only) Show store purchase result.
onPurchaseItem(player, item, true/false) -- Handle an item purchase.
onPurchaseItemReq(player, itemID) -- Request to purchase item.
addDailyOfferPurchased(userID, itemID) -- Mark daily offer as bought.
registerLuaPlaymod(playmodData) -- Register a custom player mod.
addMod(modID, amount) -- Add a mod to a player.

Script & Data Control

lua
reloadScripts() -- Reload server scripts.
loadDataFromServer(key) -- Load saved server data.
saveDataToServer(key, data) -- Save data to server.
onAutoSaveRequest(function()
 -- Script needs to save things
end)

-- Can be very helpful for those who work with json for saving and storing data, works better than traditional data saving and loading methods.
loadStringFromServer("key")
saveStringToServer("key", "value")

Redeem Codes

Create custom redeem codes in Lua with various requirements and rewards:

lua
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 means true, 0 means false)
    requirePlaytime = 60,
    requireAccountAge = 7,
    redeemTitles = {
        { titleID = 5 },
        { titleID = 9 },
    }
}

local result = createRedeemCode(redeemData)

if result ~= "" then
    print("Created redeem code:", result)
end

Fields:

  • redeemCode - The code string players will enter
  • obtainGems - Gems to give
  • obtainCoins - Coins to give
  • obtainRole - Role ID to grant
  • redeemItems - Array of items with id and count
  • maxUses - Maximum number of times the code can be redeemed
  • requireLevel - Minimum level required
  • requireRole - Minimum role required
  • requireGrowID - Whether GrowID is required (1 = yes, 0 = no)
  • requirePlaytime - Minimum playtime in minutes
  • requireAccountAge - Minimum account age in days
  • redeemTitles - Array of titles to grant with titleID

World Menu Functions

lua
addWorldMenuWorld(worldID, name, color, priority) -- Add a world to menu. || color is Growtopia style decimal number. || priority can be 0 and 1, if it's 0 then its shown after our special worlds (GROWMINES, LOCKE...) if it's 1 then its shown before our special worlds.
removeWorldMenuWorld(worldID) -- Remove a world from menu.
hideWorldMenuDefaultSpecialWorlds(1 or 0) -- Show/hide default worlds.

Dialog Data Keys

lua
data["selection"]
data["item"]
data["buttonClicked"]
data["dialog_name"]

Example: Creating a Playmod

lua
local greenBeerModData = {
    modID = -1100, -- Use a unique negative ID
    modName = "Envious",
    onAddMessage = "It ain't easy being you.",
    onRemoveMessage = "Healthy color restored.",
    iconID = getEnumItem("ITEM_GREEN_BEER"):getID(),
    changeSkin = {52, 235, 107, 255},
    modState = {StateFlags.STATE_DOUBLE_JUMP, StateFlags.STATE_SHINING},
    changeMovementSpeed = 500,
    changeAcceleration = 0,
    changeGravity = 0,
    changePunchStrength = 0,
    changeBuildRange = 0,
    changePunchRange = 0,
    changeWaterMovementSpeed = 0
}

registerLuaPlaymod(greenBeerModData)

Example: Add Sidebar Buttons

lua
local lunarFestivalSidebarButton = {
    active = true,
    buttonAction = "lunarfestivalmenu",
    buttonTemplate = "BaseEventButton",
    counter = 0,
    counterMax = 0,
    itemIdIcon = 13054,
    name = "LunarFestival",
    order = lunarFestivalEventData.id,
    rcssClass = "daily_challenge",
    text = "`#Lunar``"
}

addSidebarButton(json.encode(lunarFestivalSidebarButton))

GTPS Cloud Documentation