Skip to Content

GTPS Cloud Callback Templates

ℹ️

About Callbacks

Callbacks are event handlers that trigger when specific game actions occur. Return true from most callbacks to prevent the default behavior, or false to allow it.


onPlayerCommandCallback(world, player, commandName)

Includes:

onPlayerCommandCallback(function(world, player, fullCommand) -- world = World Object -- player = Player Object -- fullCommand = command player trigger -- return false to disable command on situation -- code here end)

onPlayerDialogCallback(world, player, data)

Includes:

onPlayerDialogCallback(function(world, player, data) -- world = World Object -- player = Player Object -- data = table -- data["dialog_name"]: string, dialog name -- data["buttonClicked"]: string, button clicked -- return true to prevent default behavior, false to allow -- code here end)

onPlayerConsumableCallback(world, player, tile, clickedPlayer, itemID)

Includes:

onPlayerConsumableCallback(function(world, player, tile, clickedPlayer, itemID) -- world = World Object -- player = Player Object -- tile = Tile Object -- clickedPlayer = Player Object (may be nil) -- itemID = number (link to Item Object) -- return true to prevent default use, false to allow -- code here end)

onTileWrenchCallback(world, player, tile)

Includes:

onTileWrenchCallback(function(world, player, tile) -- world = World Object -- player = Player Object -- tile = Tile Object -- return true to prevent default wrench behavior, false to allow -- code here end)

onPlayerPunchPlayerCallback(player,world,target_player)

Includes:

onPlayerPunchPlayerCallback(function(player,world,target_player) -- world = World Object -- player = Player Object -- target_player = Player Object end)

onPlayerPunchNPCCallback(player,world,target_npc)

Includes:

onPlayerPunchNPCCallback(function(player,world,target_npc) -- world = World Object -- player = Player Object -- target_npc = Player Object end)

onPlayerLoginCallback(player)

Includes:

onPlayerLoginCallback(function(player) -- player = Player Object -- code here end)

onTilePlaceCallback(world, player, tile, placingID)

Includes:

onTilePlaceCallback(function(world, player, tile, placingID) -- world = World Object -- player = Player Object -- tile = Tile Object -- placingID = number -- return true to prevent placement, false to allow -- code here end)

onPlayerTick(player)

Includes:

onPlayerTick(function(player) -- player = Player Object -- called every 1000ms per player -- code here end)
⚠️

Performance Warning

onPlayerTick runs every second for each player. Keep logic lightweight to avoid performance issues!


onWorldTick(world)

Includes:

onWorldTick(function(world) -- world = World Object -- called every 100ms per world -- code here end)
⚠️

Performance Warning

onWorldTick runs 10 times per second per active world. Optimize your code carefully!


onPlayerFirstTimeLoginCallback(player)

Includes:

onPlayerFirstTimeLoginCallback(function(player) -- player = Player Object -- called only on first login -- code here end)

onPlayerEnterWorldCallback(world, player)

Includes:

onPlayerEnterWorldCallback(function(world, player) -- world = World Object -- player = Player Object -- code here end)

onPlayerLeaveWorldCallback(world, player)

Includes:

onPlayerLeaveWorldCallback(function(world, player) -- world = World Object -- player = Player Object -- code here end)

onTilePunchCallback(world, avatar, tile)

Includes:

onTilePunchCallback(function(world, avatar, tile) -- world = World Object -- avatar = Player Object -- tile = Tile Object -- return true to prevent breaking, false to allow default -- code here end)

onPlayerActivateTileCallback(world, player, tile)

Includes:

onPlayerActivateTileCallback(function(world, player, tile) -- world = World Object -- player = Player Object -- tile = Tile Object -- return true to prevent activation, false to allow default -- Triggers when player activates special tiles -- code here end)
ℹ️

Special Tile Activation

This callback detects when players step on or activate special tiles such as:

  • Legendary Orb
  • Wolf Totem
  • Spirit Board
  • And other activatable tiles

Return true to block the default behavior or false to allow it.

Example:

onPlayerActivateTileCallback(function(world, player, tile) local itemID = tile:getTileID() if itemID == 5666 then -- Legendary Orb player:onConsoleMessage("You stepped on a Legendary Orb!") -- Return true to prevent default legendary orb behavior return true end return false -- Allow default behavior for other tiles end)

onPlayerDisconnectCallback(player)

Includes:

onPlayerDisconnectCallback(function(player) -- player = Player Object -- code here end)

onPlayerDeathCallback(world, player, isRespawn)

Includes:

onPlayerDeathCallback(function(world, player, isRespawn) -- world = World Object -- player = Player Object -- isRespawn = boolean -- code here end)

onPlayerDropCallback(world, player, itemID, itemCount)

Includes:

onPlayerDropCallback(function(world, player, itemID, itemCount) -- world = World Object -- player = Player Object -- itemID = number (link to Item Object) -- itemCount = number -- return true to prevent drop, false to allow -- code here end)

onPlayerPickupItemCallback(world, player, itemID, itemCount)

Includes:

onPlayerPickupItemCallback(function(world, player, itemID, itemCount) -- world = World Object -- player = Player Object -- itemID = number -- itemCount = number -- return true to prevent pickup, false to allow -- code here end)

onPlayerEquipClothingCallback(world, player, itemID)

Includes:

onPlayerEquipClothingCallback(function(world, player, itemID) -- world = World Object -- player = Player Object -- itemID = number -- return true to prevent equip, false to allow -- code here end)

onPlayerUnequipClothingCallback(world, player, itemID)

Includes:

onPlayerUnequipClothingCallback(function(world, player, itemID) -- world = World Object -- player = Player Object -- itemID = number -- return true to prevent unequip, false to allow -- code here end)

onPlayerEnterDoorCallback(world, player, targetWorldName, doorID)

Includes:

onPlayerEnterDoorCallback(function(world, player, targetWorldName, doorID) -- world = World Object -- player = Player Object -- targetWorldName = string -- doorID = number -- return true to prevent enter, false to allow -- code here end)

onPlayerPlantCallback(world, player, tile)

Includes:

onPlayerPlantCallback(function(world, player, tile) -- world = World Object -- player = Player Object -- tile = Tile Object -- code here end)

onPlayerHarvestCallback(world, player, tile)

Includes:

onPlayerHarvestCallback(function(world, player, tile) -- world = World Object -- player = Player Object -- tile = Tile Object -- code here end)

onPlayerCatchFishCallback(world, player, itemID, itemCount)

Includes:

onPlayerCatchFishCallback(function(world, player, itemID, itemCount) -- world = World Object -- player = Player Object -- itemID = number -- itemCount = number -- code here end)

onPlayerCrimeCallback(world, player, itemID, itemCount)

Includes:

onPlayerCrimeCallback(function(world, player, itemID, itemCount) -- code here end)

onPlayerSurgeryCallback(world, player, reward_id, reward_count, target_player)

Includes:

onPlayerSurgeryCallback(function(world, player, reward_id, reward_count, target_player) -- world = World Object -- player = Player Object (the surgeon) -- reward_id = number (item ID of reward) -- reward_count = number (quantity of reward) -- target_player = Player Object (patient) or nil if surgery was on a Surg-E machine if target_player then print(player:getName() .. " performed surgery on " .. target_player:getName()) else print(player:getName() .. " used a Surg-E machine") end end)
ℹ️

Surgery Callback Update

The target_player parameter is now included, allowing you to distinguish between player-to-player surgery and Surg-E machine usage!


onPlayerKillCallback(world, player, killedPlayer)

Includes:

onPlayerKillCallback(function(world, player, killedPlayer) -- code here end)

onPlayerProviderCallback(world, player, tile, itemID, itemCount)

onPlayerProviderCallback(function(world, player, tile, itemID, itemCount) -- code here end)

onPlayerHarmonicCallback(world, player, tile, itemID, itemCount)

onPlayerHarmonicCallback(function(world, player, tile, itemID, itemCount) -- code here end)

onPlayerGeigerCallback(world, player, itemID, itemCount)

onPlayerGeigerCallback(function(world, player, itemID, itemCount) -- code here end)

onPlayerCatchGhostCallback(world, player, itemID, itemCount)

onPlayerCatchGhostCallback(function(world, player, itemID, itemCount) -- code here end)

onPlayerXPCallback(world, player, amount)

onPlayerXPCallback(function(world, player, amount) -- code here end)

onPlayerFirePutOutCallback(world, player, tile)

onPlayerFirePutOutCallback(function(world, player, tile) -- code here end)

onPlayerEarnGrowtokenCallback(world, player, itemCount)

onPlayerEarnGrowtokenCallback(function(world, player, itemCount) -- code here end)

onPlayerTrainFishCallback(world, player)

onPlayerTrainFishCallback(function(world, player) -- called once the player has trained a fish -- code here end)

onPlayerStartopiaCallback(world, player, item_id, item_count)

Includes:

onPlayerStartopiaCallback(function(world, player, item_id, item_count) -- world = World Object -- player = Player Object -- item_id = number (item received from startopia) -- item_count = number (quantity received) player:onConsoleMessage("You got " .. item_count .. "x Item ID " .. item_id .. " from Startopia!") end)

onPlayerCookingCallback(world, player, item_id, item_count)

Includes:

onPlayerCookingCallback(function(world, player, item_id, item_count) -- world = World Object -- player = Player Object -- item_id = number (cooked item received) -- item_count = number (quantity received) player:onConsoleMessage("You cooked " .. item_count .. "x Item ID " .. item_id .. "!") end)

onPlayerDungeonEntitySlainCallback(world, player, entity_type)

Includes:

onPlayerDungeonEntitySlainCallback(function(world, player, entity_type) -- world = World Object -- player = Player Object -- entity_type = number (type of dungeon entity killed) -- Useful for custom dungeon quests player:onConsoleMessage("You defeated a dungeon entity!") end)

onPlayerGemsObtainedCallback(world, player, amount)

onPlayerGemsObtainedCallback(function(world, player, amount) -- code here end)

onPlayerLevelUPCallback(world, player, currentLevel)

Includes:

onPlayerLevelUPCallback(function(world, player, currentLevel) -- world = World Object -- player = Player Object -- currentLevel = number (current level before level-up) -- return true to block level-up, false to allow if currentLevel >= 10 then -- Example: don't allow past level 10 player:onConsoleMessage("`4You cannot level up past level 10!") return true -- Block level-up end return false -- Allow level-up end)
ℹ️

Advanced Level-Up Control

This callback allows you to implement custom leveling logic. Return true to prevent the player from leveling up, or false to allow it. This is useful for level caps, quest requirements, or custom progression systems!


onPlayerPunchCallback(world, player, x, y)

Includes:

onPlayerPunchCallback(function(world, player, x, y) -- world = World Object -- player = Player Object -- x = number (tile X position) -- y = number (tile Y position) -- Detects when player punches air or specific positions player:onConsoleMessage("You punched at: " .. x .. ", " .. y) end)
ℹ️

Air Punch Detection

This callback detects when a player punches, including punching air or specific tile positions. Useful for custom mechanics or gesture detection!


onPlayerDepositCallback(world, player, tile, itemid, itemcount)

Includes:

onPlayerDepositCallback(function(world, player, tile, itemid, itemcount) -- world = World Object -- player = Player Object -- tile = Tile Object (donation box or storage box) -- itemid = number (item being deposited) -- itemcount = number (amount being deposited) -- return true to block deposit, false to allow if itemid == 242 then -- World Lock player:onConsoleMessage("`4You cannot deposit World Locks!") return true -- Block deposit end player:onConsoleMessage("Deposited " .. itemcount .. "x Item ID " .. itemid) return false -- Allow deposit end)
ℹ️

Storage Detection

Detects when players place items into donation boxes or other storage-type boxes. Return true to prevent the deposit, or false to allow it!


onPlayerSpliceSeedCallback(world, player, tile, seed_id)

Includes:

onPlayerSpliceSeedCallback(function(world, player, tile, seed_id) -- world = World Object -- player = Player Object -- tile = Tile Object (where splicing is happening) -- seed_id = number (ID of seed being spliced) -- return true to block splicing, false to allow if seed_id == 5040 then -- Chandelier Seed player:onConsoleMessage("`4You cannot splice this seed!") return true -- Block splicing end return false -- Allow splicing end)
ℹ️

Custom Splicing Logic

Detects when a player splices seeds. Return true to block the splicing, or false to allow it. Note: Splicing recipes can also be modified by editing JSON data!


onPlayerVendingBuyCallback(world, player, tile, item_id, item_count)

Includes:

onPlayerVendingBuyCallback(function(world, player, tile, item_id, item_count) -- world = World Object -- player = Player Object -- tile = Tile Object (vending machine) -- item_id = number (item being purchased) -- item_count = number (amount being purchased) -- return true to block purchase, false to allow if item_count > 100 then player:onConsoleMessage("`4Cannot buy more than 100 items at once!") return true -- Block purchase end player:onConsoleMessage("Purchased " .. item_count .. "x Item ID " .. item_id) return false -- Allow purchase end)
ℹ️

Vending Purchase Control

Detects when a player purchases items from vending machines. Return true to prevent the purchase, or false to allow it!


onTick()

Global server tick called every 100ms.

onTick(function() -- Called every 100ms on the server -- Use sparingly - high frequency callback end)
⚠️

High Frequency Warning

This callback runs 10 times per second globally. Keep logic extremely lightweight to avoid severe performance issues!


onPlayerDNACallback(world, player, resultID, resultAmount)

Includes:

onPlayerDNACallback(function(world, player, resultID, resultAmount) -- world = World Object -- player = Player Object -- resultID = item ID created from DNA Combiner -- resultAmount = quantity created player:onConsoleMessage("You created " .. resultAmount .. "x Item ID " .. resultID .. " from DNA!") end)

onPlayerTradeCallback(world, player1, player2, items1, items2)

Includes:

onPlayerTradeCallback(function(world, player1, player2, items1, items2) -- world = World Object -- player1 = First player Object -- player2 = Second player Object -- items1 = table of items from player1 -- items2 = table of items from player2 print(player1:getName() .. " traded with " .. player2:getName()) -- Log traded items for i, item in ipairs(items1) do print("Player1 gave: " .. item.itemID .. " x" .. item.count) end end)
ℹ️

Successful Trades Only

This callback triggers upon successful trade completion. Both items1 and items2 are tables containing item objects with itemID and count properties.


onPlayerTrashCallback(world, player, item_id, item_amount)

Includes:

onPlayerTrashCallback(function(world, player, item_id, item_amount) -- world = World Object -- player = Player Object -- item_id = item being trashed -- item_amount = amount being trashed -- return true to prevent trashing, false to allow if item_id == 242 then -- World Lock player:onConsoleMessage("`4You cannot trash World Locks!") return true -- Block trashing end return false -- Allow trashing end)

onPlayerActionCallback(world, player, data)

Includes:

onPlayerActionCallback(function(world, player, data) -- world = World Object -- player = Player Object -- data = table containing action information -- data["action"] = action name if data["action"] == "custom_action" then player:onConsoleMessage("Custom action triggered!") end end)
ℹ️

Generic Action Handler

This callback handles various player actions, often from UI buttons. Check data["action"] to determine which action was triggered.


onPlayerWrenchCallback(world, player, wrenchingPlayer)

Includes:

onPlayerWrenchCallback(function(world, player, wrenchingPlayer) -- world = World Object -- player = Player being wrenched -- wrenchingPlayer = Player/NPC doing the wrenching -- Check if wrenching an NPC if wrenchingPlayer:getType() == 25 then player:onConsoleMessage("You wrenched a Lua-spawned NPC!") return end player:onConsoleMessage("You wrenched " .. wrenchingPlayer:getName()) end)
ℹ️

NPC Detection

Check wrenchingPlayer:getType() to determine if it’s an NPC. Type 25 indicates a Lua-spawned NPC.


onPlayerRecycleCallback(world, player, item_id, item_amount, gems_earned)

Includes:

onPlayerRecycleCallback(function(world, player, item_id, item_amount, gems_earned) -- world = World Object -- player = Player Object -- item_id = item being recycled -- item_amount = amount being recycled -- gems_earned = gems player will receive -- return true to prevent recycling, false to allow player:onConsoleMessage("Recycling " .. item_amount .. "x for " .. gems_earned .. " gems") return false -- Allow recycling end)

onPlayerVariantCallback(player, variant, delay, netID)

Includes:

onPlayerVariantCallback(function(player, variant, delay, netID) -- player = Player Object -- variant = variant packet table -- delay = packet delay -- netID = network ID -- Advanced use only - handles client variant packets end)
⚠️

Advanced Users Only

This is a low-level callback for handling various client packets (variants). Use only if you understand packet structures!


onPlayerRegisterCallback(world, player)

Includes:

onPlayerRegisterCallback(function(world, player) -- world = World Object -- player = Player Object -- Called when a player registers a new account -- Give starter pack player:changeItem(2, 10, true) -- 10 Dirt player:addGems(1000, true, true) player:onConsoleMessage("`2Welcome! Here's a starter pack!") end)

Perfect for Starter Packs

This callback is ideal for giving new players starter items, gems, or welcoming them to your server!


onPlayerAddFriendCallback(world, player, addedPlayer)

Includes:

onPlayerAddFriendCallback(function(world, player, addedPlayer) -- world = World Object -- player = Player who added friend -- addedPlayer = Player who was added player:onConsoleMessage("You added " .. addedPlayer:getName() .. " as a friend!") end)

onPlayerRawPacketCallback(player, data)

Includes:

onPlayerRawPacketCallback(function(player, data) -- player = Player Object -- data = raw network packet data -- Very low-level handling of raw packets - advanced use only end)
⚠️

Very Advanced - Use with Extreme Caution

This callback handles raw network packets from players. Incorrect use can break client-server communication!


onPlayerBoostClaimCallback(player)

Includes:

onPlayerBoostClaimCallback(function(player) -- player = Player Object -- Called when player claims a boost player:onConsoleMessage("You claimed a boost!") end)

onPlayerConvertItemCallback(world, player, item_id)

Includes:

onPlayerConvertItemCallback(function(world, player, item_id) -- world = World Object -- player = Player Object -- item_id = item being converted (e.g., 100 WLs to 1 DL) -- return true to prevent conversion, false to allow if item_id == 242 then -- World Lock -- Custom conversion logic return true -- Block default conversion end return false -- Allow default conversion end)
ℹ️

Item Conversion

Triggered when a player double-taps specific items to convert them (e.g., 100 World Locks to 1 Diamond Lock). Return true to prevent default behavior!


onPlayerEquippedClothingCallback(world, player, item_id)

Includes:

onPlayerEquippedClothingCallback(function(world, player, item_id) -- world = World Object -- player = Player Object -- item_id = item that was successfully equipped -- Called AFTER item is equipped player:onConsoleMessage("You equipped: " .. getItem(item_id):getName()) end)
ℹ️

Post-Equip Event

Called AFTER a player successfully equips an item. Use onPlayerEquipClothingCallback to prevent equipping.


onPlayerUnequippedClothingCallback(world, player, item_id)

Includes:

onPlayerUnequippedClothingCallback(function(world, player, item_id) -- world = World Object -- player = Player Object -- item_id = item that was successfully unequipped -- Called AFTER item is unequipped player:onConsoleMessage("You unequipped: " .. getItem(item_id):getName()) end)

onTileBreakCallback(world, player, tile)

Includes:

onTileBreakCallback(function(world, player, tile) -- world = World Object -- player = Player Object -- tile = Tile Object that was broken local item = tile:getTileItem() player:onConsoleMessage("You broke: " .. item:getName()) end)

onWorldLoaded(world)

Includes:

onWorldLoaded(function(world) -- world = World Object -- Called when a world is loaded into memory print("World loaded: " .. world:getName()) end)

onWorldOffloaded(world)

Includes:

onWorldOffloaded(function(world) -- world = World Object -- Called when a world is removed from memory print("World unloaded: " .. world:getName()) end)

onEventChangedCallback(newEventID, oldEventID)

onEventChangedCallback(function(newEventID, oldEventID) -- newEventID = new event ID -- oldEventID = previous event ID -- Called when the server-wide event changes print("Event changed from " .. oldEventID .. " to " .. newEventID) end)
Last updated on