Skip to content

Examples

Kiminaze edited this page Nov 29, 2022 · 1 revision

Prerequisites

All examples below assume that you call the exports by shortening the function call:

local CB = exports["kimi_callbacks"]

Client side code

Return player position to server:

CB:Register("getPlayerPosition", function()
    return GetEntityCoords(PlayerPedId())
end)

Return player position and heading to server:

CB:Register("getPlayerPositionAndHeading", function()
    local playerPed = PlayerPedId()
    return GetEntityCoords(playerPed), GetEntityHeading(playerPed)
end)

Return distance from a player to a given point to server:

CB:Register("getPlayerDistanceToPosition", function(position)
    return #(GetEntityCoords(PlayerPedId()) - position)
end)

Get player money from server:

function GetMoney()
    return CB:Trigger("getMoney")
end

Get player cash money from server with a timeout:

function GetCashMoneyTimeout()
    return CB:TriggerWithTimeout("getMoney", 500, "cash") or 0
end

Server side code

Return money to client:

CB:Register("getMoney", function(source, moneyType)
    -- get money from player with source
    local cash, bank = GetMoneyFromPlayer(source)

    if (moneyType == "cash") then
        return cash
    elseif (moneyType == "bank") then
        return bank
    end

    return cash, bank
end)

Get player position from client:

function GetPlayerPosition(playerId)
    return CB:Trigger("getPlayerPosition", playerId)
end

Get player position and heading from client:

function GetPlayerPositionAndHeading(playerId)
    return CB:Trigger("getPlayerPositionAndHeading", playerId)
end

Get player distance to a specified position from client with a timeout:

function GetPlayerDistanceToPosition(playerId, position)
    return CB:TriggerWithTimeout("getPlayerDistanceToPosition", playerId, 500, position)
end