Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ yarn.lock
server/created_doors_data.txt

/server/db
server/server.ptr.cfg
server/server.ptr.cfg
server/resources/\[sandbox\]/sandbox-phone/server/bizphone.lua
server/resources/\[sandbox\]/sandbox-dealerships/server/sales.lua
server/config/database.ptr.cfg
7 changes: 2 additions & 5 deletions server/resources/[sandbox]/sandbox-laptop/client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ AddEventHandler("Characters:Client:Updated", function()
_settings = LocalPlayer.state.Character:GetData("LaptopSettings")
exports['sandbox-laptop']:SetData("player", LocalPlayer.state.Character:GetData())

if
LocalPlayer.state.laptopOpen
and not (exports.ox_inventory:Search('count', 'laptop') == 0)
then
if LocalPlayer.state.laptopOpen and (exports.ox_inventory:Search('count', 'laptop') == 0) then
exports['sandbox-laptop']:Close(true)
end
end)
Expand Down Expand Up @@ -78,7 +75,7 @@ RegisterNetEvent("UI:Client:Reset", function(manual)
end)

AddEventHandler("UI:Client:Close", function(context)
if context ~= "laptop" then
if context == "laptop" then
exports['sandbox-laptop']:Close()
end
end)
Expand Down
181 changes: 87 additions & 94 deletions server/resources/[sandbox]/sandbox-phone/client/bizphone.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
local phoneModel = `vw_prop_casino_phone_01a`
local phoneModel = `v_ret_gc_phone`
local _createdPhones = {}

local function HasBizAccess(jobName)
if not LocalPlayer.state.loggedIn then return false end

if type(LocalPlayer.state.onDuty) == "string" then
return LocalPlayer.state.onDuty == jobName
end

local jobs = LocalPlayer.state.jobs
if type(jobs) == "table" and jobs[jobName] then
return true
end

return false
end

function CreateBizPhoneObject(coords, rotation)
RequestModel(phoneModel)
while not HasModelLoaded(phoneModel) do
Wait(1)
end

local obj = CreateObject(phoneModel, coords.x, coords.y, coords.z, false, true, false)
SetEntityRotation(obj, rotation.x, rotation.y, rotation.z)
local obj = CreateObject(phoneModel, coords.x, coords.y, coords.z, false, false, false)
SetEntityCoordsNoOffset(obj, coords.x, coords.y, coords.z, false, false, false)
SetEntityRotation(obj, rotation.x, rotation.y, rotation.z, 2, true)
FreezeEntityPosition(obj, true)
SetEntityCoords(obj, coords.x, coords.y, coords.z)
SetEntityAsMissionEntity(obj, true, true)

while not DoesEntityExist(obj) do
Wait(1)
Expand All @@ -24,128 +40,91 @@ function CreateBizPhones()
Wait(100)
end

for k, v in pairs(GlobalState.BizPhones) do
for _, v in pairs(GlobalState.BizPhones) do
local object = CreateBizPhoneObject(v.coords, v.rotation)

exports.ox_target:addEntity(object, {
exports.ox_target:addLocalEntity(object, {
{
icon = "phone-volume",
label = "Phone",
icon = "phone",
label = "Answer Call",
onSelect = function()
TriggerEvent("Phone:Client:MakeBizCall", { id = v.id })
TriggerEvent("Phone:Client:AcceptBizCall", nil, { id = v.id })
end,
groups = { v.job },
canInteract = function(data)
if data then
local pData = GlobalState[string.format("BizPhone:%s", data.id)]
if pData and pData.state > 1 then
return true
end
end
end,
label = function(data)
if data then
local pData = GlobalState[string.format("BizPhone:%s", data.id)]
if pData then
if pData.state == 2 then
return string.format("On Call (%s)", pData.callingStr)
else
return string.format("Dialing (%s)", pData.number)
end
end
end
return ""
canInteract = function()
local pData = GlobalState[("BizPhone:%s"):format(v.id)]
return HasBizAccess(v.job) and pData and pData.state == 1
end,
},
{
icon = "phone",
label = "Make Call",
event = "Phone:Client:MakeBizCall",
onSelect = function()
TriggerEvent("Phone:Client:MakeBizCall", { id = v.id })
TriggerEvent("Phone:Client:MakeBizCall", nil, { id = v.id })
end,
groups = { v.job },
canInteract = function(data)
if data then
local pData = GlobalState[string.format("BizPhone:%s", data.id)]
if not pData then
return true
end
end
canInteract = function()
local pData = GlobalState[("BizPhone:%s"):format(v.id)]
return HasBizAccess(v.job) and not pData
end,
},
{
icon = "phone",
label = "Answer Phone",
icon = "phone-volume",
label = "Dialing…",
onSelect = function()
TriggerEvent("Phone:Client:AcceptBizCall", { id = v.id })
TriggerEvent("Phone:Client:MakeBizCall", { id = v.id })
end,
groups = { v.job },
canInteract = function(data)
if data then
local pData = GlobalState[string.format("BizPhone:%s", data.id)]
if pData and pData.state == 1 then
return true
end
end
canInteract = function()
local pData = GlobalState[("BizPhone:%s"):format(v.id)]
return HasBizAccess(v.job) and pData and pData.state > 1 and pData.state ~= 2
end,
label = function(data)
if data then
local pData = GlobalState[string.format("BizPhone:%s", data.id)]
if pData and pData.state == 1 then
return string.format("Answer Call From %s", pData.callingStr)
end
},
{
icon = "phone-volume",
label = "On Call",
onSelect = function()
local pData = GlobalState[("BizPhone:%s"):format(v.id)]
if pData then
exports["sandbox-hud"]:Notification("inform", ("On Call: %s"):format(pData.callingStr or "Unknown"))
end
return ""
end,
canInteract = function()
local pData = GlobalState[("BizPhone:%s"):format(v.id)]
return HasBizAccess(v.job) and pData and pData.state == 2
end,
},
{
icon = "phone",
label = "Hang Up",
onSelect = function()
TriggerEvent("Phone:Client:DeclineBizCall", { id = v.id })
TriggerEvent("Phone:Client:DeclineBizCall", nil, { id = v.id })
end,
groups = { v.job },
canInteract = function(data)
if data then
local pData = GlobalState[string.format("BizPhone:%s", data.id)]
if pData then
return true
end
end
canInteract = function()
local pData = GlobalState[("BizPhone:%s"):format(v.id)]
return HasBizAccess(v.job) and pData ~= nil
end,
},
{
icon = "phone-slash",
label = "Mute Phone",
event = "Phone:Client:MuteBiz",
label = "Toggle Mute",
onSelect = function()
TriggerEvent("Phone:Client:MuteBiz", { id = v.id })
TriggerEvent("Phone:Client:MuteBiz", nil, { id = v.id })
end,
groups = { v.job },
label = function(data)
if data then
local pData = GlobalState[string.format("BizPhone:%s:Muted", data.id)]
if pData then
return "Unmute Phone"
end
end
return "Mute Phone"
canInteract = function()
return HasBizAccess(v.job)
end,
}
},
})

table.insert(_createdPhones, object)
end
end

function CleanupBizPhones()
for k, v in ipairs(_createdPhones) do
if DoesEntityExist(v) then
DeleteEntity(v)
for _, ent in ipairs(_createdPhones) do
if DoesEntityExist(ent) then
exports.ox_target:removeLocalEntity(ent)
DeleteEntity(ent)
end
end

_createdPhones = {}
end

Expand Down Expand Up @@ -212,23 +191,37 @@ AddEventHandler("Phone:Client:MakeBizCallConfirm", function(values, data)
end
end)

RegisterNetEvent("Phone:Client:Phone:AcceptBizCall", function(number)
RegisterNetEvent("Phone:Client:AcceptBizCall", function(number)
if LocalPlayer.state.bizCall then
exports['sandbox-hud']:InfoOverlayShow("On Call", string.format("To Number: %s", number))
exports["sandbox-sounds"]:StopOne("ringing.ogg")
end
end)

RegisterNetEvent("Phone:Client:Biz:Recieve", function(id, coords, radius)
if LocalPlayer.state.loggedIn and not GlobalState[string.format("BizPhone:%s:Muted", id)] then
local myCoords = GetEntityCoords(LocalPlayer.state.ped)
if #(myCoords - coords) <= 150.0 then
exports["sandbox-sounds"]:LoopLocation(string.format("bizphones-%s", id), coords, radius, "bizphone.ogg", 0.1)
SetTimeout(30000, function()
exports["sandbox-sounds"]:StopDistance(string.format("bizphones-%s", id), "bizphone.ogg")
end)
end
if not LocalPlayer.state.loggedIn or GlobalState[("BizPhone:%s:Muted"):format(id)] then return end

-- Coerce coords into vector3 (handles table or json-string coords)
if type(coords) == 'string' then
local ok, decoded = pcall(json.decode, coords)
if ok and decoded then coords = decoded end
end
if type(coords) == 'table' then
coords = vector3(coords.x + 0.0, coords.y + 0.0, coords.z + 0.0)
end

radius = tonumber(radius) or 15.0

local ped = PlayerPedId()
local myCoords = GetEntityCoords(ped)

if #(myCoords - coords) <= 150.0 then
exports["sandbox-sounds"]:LoopLocation(("bizphones-%s"):format(id), coords, radius, "bizphone.ogg", 0.1)
SetTimeout(30000, function()
exports["sandbox-sounds"]:StopDistance(("bizphones-%s"):format(id), "bizphone.ogg")
end)
end
print("BIZ RING coords type:", type(coords), coords)
end)

AddEventHandler("Phone:Client:DeclineBizCall", function(entityData, data)
Expand Down Expand Up @@ -277,4 +270,4 @@ RegisterNetEvent("Phone:Client:Biz:End", function(id)
LocalPlayer.state.bizCall = nil
exports["sandbox-sounds"]:PlayOne("ended.ogg", 0.15)
end
end)
end)
13 changes: 12 additions & 1 deletion server/resources/[sandbox]/sandbox-phone/server/apps/phone.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
local _calls = {}
local _bizCallHandlers = {} -- The people who answered the business call

local function normalizePhoneNumber(num)
if not num then return nil end
-- keep it consistent with your generator/format (you use ###-###-####)
return tostring(num)
end

local function getBizIdFromNumber(number)
number = normalizePhoneNumber(number)
return number and _bizPhoneNumbersCheck[number] or nil
end

exports("CallEnd", function(source, business)
if business then
if _bizPhones[business] and _bizPhones[business].call then
Expand Down Expand Up @@ -747,4 +758,4 @@ AddEventHandler("Phone:Server:RegisterCallbacks", function()
cb(false)
end
end)
end)
end)
4 changes: 2 additions & 2 deletions server/resources/[sandbox]/sandbox-phone/server/bizphone.lua
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ function InitBizPhones()
for k, v in ipairs(bP) do
_bizPhoneNumbers[v.id] = v.number
_bizPhoneNumbersCheck[v.number] = v.id
GlobalState[string.format("BizPhone:%s:Muted", v.id)] = v.muted
GlobalState[("BizPhone:%s:Muted"):format(v.id)] = (v.muted == 1 or v.muted == true)
end

local trans = {}
Expand Down Expand Up @@ -269,4 +269,4 @@ function InitBizPhones()
MySQL.transaction.await(trans)

GlobalState.BizPhones = _bizPhones
end
end
Loading