🌐
TPZ-CORE DOCUMENTATION
  • Introduction
  • CLIENT
    • Events
    • Functions
    • Callbacks
    • Inventory
  • SERVER
    • Functions
    • Player
    • Callbacks
    • Inventory
Powered by GitBook
On this page
  1. SERVER

Callbacks

The callback in the code below has already been registered in tpz_core, we show this as an example to understand properly how it works to receive data from server to client properly.

PreviousPlayerNextInventory

Last updated 3 months ago

Checkout to see how it is also used in the client.

local TPZ = exports.tpz_core:getCoreAPI()

exports.tpz_core:getCoreAPI().addNewCallBack("tpz_core:getPlayerData", function(source, cb)
    local _source = source
    local xPlayer = TPZ.GetPlayer(_source)
    
    -- If player is in session we return the rest of the code and we dont request for data.
    if not xPlayer.loaded() then
        return cb(nil)
    end

    -- There is also a function called xPlayer.loaded() in case if you want to get
    -- the data or wait to receive after the player has loaded.
    return cb(
        { 
            source          = tonumber(_source),
            loaded          = xPlayer.loaded(),
            identifier      = xPlayer.getIdentifier(),
            charIdentifier  = xPlayer.getCharacterIdentifier(),
            money           = xPlayer.getAccount(0), 
            gold            = xPlayer.getAccount(1), 
            blackmoney      = xPlayer.getAccount(2),
            firstname       = xPlayer.getFirstName(),
            lastname        = xPlayer.getLastName(),
            gender          = xPlayer.getGender(),
            dob             = xPlayer.getDob(),
            job             = xPlayer.getJob(),
            jobGrade        = xPlayer.getJobGrade(),
            identityId      = xPlayer.getIdentityId(),
        } 
    ) 
end)

Client Callbacks