Phone Integration
From this section, you can learn how to integrate your own phone.
You can find phone implementations in no-payphone/integration/phone
Phone integration can be a little more complicated. To do this we need to add event listeners for payphone events and trigger phone events.
Ready Integrations
Payphone Events
This events will be triggered by payphone.
no-payphone:call:start
Triggered when payphone starts the call.
Parameters
ctx: {source: number; number: string; targetNumber: string; callId: number}
ctx.source is the caller's server id.
ctx.number is payphone's number.
ctx.targetNumber is the number payphone is calling.
ctx.callId is the call Id generated from payphone. (You don't need to use this)
no-payphone:call:answer
Triggered when payphone answers the call.
Parameters
ctx: {source: number; number: string; targetNumber: string; callId: number}
ctx.source is the caller's server id.
ctx.number is payphone's number.
ctx.targetNumber is the number payphone is calling.
ctx.callId is the call Id generated from payphone. (You don't need to use this)
Phone Events
This events expected to triggered by phone.
no-payphone:phone:start
Triggered when phone starts the call.
Parameters
ctx: {source: number; number: string; targetNumber: string; callId?: number}
ctx.source is the caller's server id.
ctx.number is the phone's number.
ctx.targetNumber is the number phone is calling.
ctx.callId: Generated call id (If nil payphone will generate itself.).
Example
This is an example for qb-phone. You can find this integration in
no-payphone/config/integration/phone/qb-phone.lua
if not _IS_SERVER or not HasResource("qb-phone") then return end
-- NOTES
--- IN ORDER TO LET PLAYERS CALL NON-PLAYER NUMBERS YOU NEED TO CHANGE CALLBACK CALLED "qb-phone:server:GetCallState" IN qb-phone/server/main.lua:163 WITH THIS
-- cb(true, true) EVEN IF TARGET IS NIL
-- QBCore.Functions.CreateCallback('qb-phone:server:GetCallState', function(_, cb, ContactData)
-- local Target = QBCore.Functions.GetPlayerByPhone(ContactData.number)
-- if Target ~= nil then
-- if Calls[Target.PlayerData.citizenid] ~= nil then
-- if Calls[Target.PlayerData.citizenid].inCall then
-- cb(false, true)
-- else
-- cb(true, true)
-- end
-- else
-- cb(true, true)
-- end
-- else
-- cb(true, true)
-- end
-- end)
-- SERVER START
local QBCore = exports["qb-core"]:GetCoreObject()
-- payphone start the call
---@param ctx table
---@field source number
---@field number string
---@field targetNumber string
---@field callId number
AddEventHandler("no-payphone:call:start", function(ctx)
local target = QBCore.Functions.GetPlayerByPhone(ctx.targetNumber)
if not target then return end
TriggerClientEvent("qb-phone:client:GetCalled", target.PlayerData.source, ctx.number, ctx.callId, false)
end)
-- payphone answer the call
---@param ctx table
---@field source number
---@field number string
---@field targetNumber string
---@field callId number
AddEventHandler("no-payphone:call:answer", function(ctx)
local target = QBCore.Functions.GetPlayerByPhone(ctx.targetNumber)
if not target then return end
TriggerClientEvent("qb-phone:client:AnswerCall", target.PlayerData.source)
end)
-- payphone end the call
---@param ctx table
---@field number string
---@field targetNumber string
AddEventHandler("no-payphone:call:end", function(ctx)
local target = QBCore.Functions.GetPlayerByPhone(ctx.targetNumber)
if not target then return end
TriggerClientEvent("qb-phone:client:CancelCall", target.PlayerData.source)
end)
-- phone start the call
RegisterNetEvent("qb-phone:server:CallContact", function(targetData, callId)
local player = QBCore.Functions.GetPlayer(source)
if not player then return end
TriggerEvent("no-payphone:phone:start", {
source = source, -- number
number = player.PlayerData.charinfo.phone, -- string
targetNumber = targetData.number, -- string
callId = callId -- number?
})
end)
-- phone answer the call
RegisterNetEvent("qb-phone:server:AnswerCall", function(ctx)
local player = QBCore.Functions.GetPlayer(source)
if not player then return end
TriggerEvent("no-payphone:phone:answer", {
source = source, -- number
number = player.PlayerData.charinfo.phone
})
end)
-- phone cancel the call
RegisterNetEvent("qb-phone:server:CancelCall", function(ctx)
local player = QBCore.Functions.GetPlayer(source)
if not player then return end
TriggerEvent("no-payphone:phone:end", player.PlayerData.charinfo.phone)
end)
Last updated