Callback structure
Here you will learn how to work with the available Lua callbacks.
onPlayerVariantCallback
lua
onPlayerVariantCallback(function(player, variant, delay, netID)
-- your code
end)With
onPlayerVariantCallbackyou can inspect (and even modify) most things the server sends to the player.
This is very low-level and easy to break things with.
onPlayerDialogCallback
lua
onPlayerDialogCallback(function(world, player, data)
-- data is a table parsed from dialog_return
local name = data["dialog_name"]
local button = data["buttonClicked"]
end)
data["dialog_name"]anddata["buttonClicked"]are always the fields to use.
onPlayerConsumableCallback
lua
onPlayerConsumableCallback(function(world, player, tile, clickedPlayer, itemID)
-- your code
end)onPlayerEquippedClothingCallback
lua
onPlayerEquippedClothingCallback(function(world, player, item_id)
-- Called once equip completes.
-- You do NOT need to return true/false here.
end)onPlayerUnequippedClothingCallback
lua
onPlayerUnequippedClothingCallback(function(world, player, item_id)
-- Called once unequip completes.
-- You do NOT need to return true/false here.
end)onPlayerEquipClothingCallback (legacy)
lua
onPlayerEquipClothingCallback(function(world, player, itemID)
-- Return true to BLOCK equip, false to allow.
return false
end)onPlayerUnequipClothingCallback (legacy)
lua
onPlayerUnequipClothingCallback(function(world, player, itemID)
-- Return true to BLOCK unequip, false to allow.
return false
end)Use the new
onPlayerEquippedClothingCallback/onPlayerUnequippedClothingCallbackwhen you only care about the final result.
onPlayerDNACallback
lua
onPlayerDNACallback(function(world, player, resultID, resultAmount)
-- your code
end)onPlayerTrashCallback
lua
onPlayerTrashCallback(function(world, player, item_id, item_amount)
-- Return true to BLOCK trashing.
-- Return false to allow trashing.
return false
end)onPlayerRecycleCallback
lua
onPlayerRecycleCallback(function(world, player, item_id, item_amount, gems_earned)
-- Return true to BLOCK recycle.
-- Return false to allow recycle.
return false
end)onPlayerPunchPlayerCallback
lua
onPlayerPunchPlayerCallback(function(world, player, second_player)
-- Called when player punches another player.
end)onPlayerPunchNPCCallback
lua
onPlayerPunchNPCCallback(function(world, player, npc_player)
-- Called when player punches an NPC (Lua-spawned NPCs, magic orbs, etc.).
end)onTileWrenchCallback
lua
onTileWrenchCallback(function(world, player, tile)
-- Called when tile is wrenched.
end)onTileBreakCallback
lua
onTileBreakCallback(function(world, player, tile)
-- Called when tile is broken.
end)onTilePunchCallback
lua
onTilePunchCallback(function(world, avatar, tile)
-- Return true to BLOCK the default break action.
-- Return false to allow normal breaking.
return false
end)onTilePlaceCallback
lua
onTilePlaceCallback(function(world, player, tile, placingID)
-- Called when placing a tile.
end)onPlayerLoginCallback
lua
onPlayerLoginCallback(function(player)
-- Called on every login.
end)onPlayerFirstTimeLoginCallback
lua
onPlayerFirstTimeLoginCallback(function(player)
-- Called only once for brand new accounts.
end)onPlayerActionCallback
lua
onPlayerActionCallback(function(world, player, data)
-- Low-level action packet, parsed into data table.
end)onPlayerEnterWorldCallback
lua
onPlayerEnterWorldCallback(function(world, player)
-- Called after player has entered world.
end)onPlayerLeaveWorldCallback
lua
onPlayerLeaveWorldCallback(function(world, player)
-- Called when player leaves world.
end)onPlayerDisconnectCallback
lua
onPlayerDisconnectCallback(function(player)
-- Called when player disconnects from server.
end)onPlayerAddFriendCallback
lua
onPlayerAddFriendCallback(function(world, player, addedPlayer)
-- Called when player adds a friend.
end)onPlayerDropCallback
lua
onPlayerDropCallback(function(world, player, itemID, itemCount)
-- Return true to BLOCK dropping.
-- Return false to allow.
return false
end)onPlayerPickupItemCallback
lua
onPlayerPickupItemCallback(function(world, player, itemID, itemCount)
-- Return true to BLOCK pickup.
-- Return false to allow.
return false
end)onPlayerEnterDoorCallback
lua
onPlayerEnterDoorCallback(function(world, player, targetWorldName, doorID)
-- Return true to BLOCK entering the door.
-- Return false to allow normal behavior.
return false
end)onPlayerPlantCallback
lua
onPlayerPlantCallback(function(world, player, tile)
-- Called when a seed is planted.
end)onPlayerHarvestCallback
lua
onPlayerHarvestCallback(function(world, player, tile)
-- Called when a tree is harvested.
end)onPlayerCatchFishCallback
lua
onPlayerCatchFishCallback(function(world, player, itemID, itemCount)
-- Called when player catches a fish.
end)onPlayerCrimeCallback
lua
onPlayerCrimeCallback(function(world, player, itemID, itemCount)
-- Called when a crime action is performed.
end)onPlayerSurgeryCallback
lua
onPlayerSurgeryCallback(function(world, player, itemID, itemCount)
-- Called for surgery actions.
end)onPlayerKillCallback
lua
onPlayerKillCallback(function(world, player, killedPlayer)
-- Called when player kills another player.
end)onPlayerProviderCallback
lua
onPlayerProviderCallback(function(world, player, tile, itemID, itemCount)
-- Provider actions (e.g. provider blocks).
end)onPlayerHarmonicCallback
lua
onPlayerHarmonicCallback(function(world, player, tile, itemID, itemCount)
-- Harmonic actions callback.
end)onPlayerGeigerCallback
lua
onPlayerGeigerCallback(function(world, player, itemID, itemCount)
-- Geiger event callback.
end)onPlayerCatchGhostCallback
lua
onPlayerCatchGhostCallback(function(world, player, itemID, itemCount)
-- Called when catching a ghost.
end)onPlayerXPCallback
lua
onPlayerXPCallback(function(world, player, amount)
-- Called when player gains XP.
end)onPlayerFirePutOutCallback
lua
onPlayerFirePutOutCallback(function(world, player, tile)
-- Called when player puts out fire.
end)onPlayerEarnGrowtokenCallback
lua
onPlayerEarnGrowtokenCallback(function(world, player, itemCount)
-- Called when player earns Growtoken(s).
end)onPlayerTrainFishCallback
lua
onPlayerTrainFishCallback(function(world, player)
-- Called once the player has trained a fish.
end)onPlayerGemsObtainedCallback
lua
onPlayerGemsObtainedCallback(function(world, player, amount)
-- Called when player obtains gems.
end)onPlayerLevelUPCallback
lua
onPlayerLevelUPCallback(function(world, player, levelReached)
-- Called when player levels up.
end)onPlayerDeathCallback
lua
onPlayerDeathCallback(function(world, player, isRespawn)
-- isRespawn = true if this is a respawn
-- false if the player died from spikes, lava, etc.
end)onPlayerRawPacketCallback
lua
onPlayerRawPacketCallback(function(player, data)
if data then
local bytes = { data:byte(1, #data) }
local packet_type = bytes[1]
print(packet_type)
end
-- Return true to BLOCK default handling.
-- Return false to allow.
return false
end)You can block default packets here, but you need good knowledge of Growtopia packet structures.
onPlayerTradeCallback
lua
onPlayerTradeCallback(function(world, player1, player2, items1, items2)
for _, item in ipairs(items1) do
print("Traded " .. tostring(item.id) .. " x" .. tostring(item.count))
end
end)onPlayerBlessingClaimCallback
lua
onPlayerBlessingClaimCallback(function(world, player, blessingID)
-- Called when player claims a blessing from the power orb.
end)onPlayerBoostClaimCallback
lua
onPlayerBoostClaimCallback(function(player)
-- Called when player uses /claimboost after boosting your Discord server.
-- Use this to give custom boost rewards.
end)onPlayerConvertItemCallback
lua
onPlayerConvertItemCallback(function(world, player, item_id)
-- Called when player tries to convert items (e.g. 100 WL -> 1 DL).
-- Return true to BLOCK the default conversion.
-- Return false to allow it.
print(item_id)
return false
end)Works only on specific hard-coded items that support conversion in the GT client.
World Tick & Global Tick
lua
onTick(function()
-- Called every 100ms (global).
end)
onPlayerTick(function(player)
-- Called every second for each player.
end)
onWorldTick(function(world)
-- Called every 100ms per world.
end)World Load / Unload
lua
onWorldLoaded(function(world)
-- Called once when a world is loaded into memory.
end)
onWorldOffloaded(function(world)
-- Called once when a world is removed from memory.
end)Event Changes
lua
onEventChangedCallback(function(newEventID, oldEventID)
-- Called when the global event changes.
end)Discord Integration
lua
onDiscordMessageCreateCallback(function(event)
-- Called when a Discord message is created (if hooked up).
end)