-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbridge.lua
More file actions
120 lines (103 loc) · 3.66 KB
/
bridge.lua
File metadata and controls
120 lines (103 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
local QBCore = nil
local ESX = nil
Citizen.CreateThread(function()
if Config.Framework == "esx" then
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
print("[src-payphone] ESX Framework initialized")
elseif Config.Framework == "esxnew" then
ESX = exports["es_extended"]:getSharedObject()
print("[src-payphone] ESX New Framework initialized")
elseif Config.Framework == "qbcore" then
QBCore = exports['qb-core']:GetCoreObject()
print("[src-payphone] QBCore Framework initialized")
elseif Config.Framework == "qbox" then
if not QBX then return error("^4[src-payphone]^7 ^1QBX not found.^7 ^2Uncomment line in fxmanifest.lua^7") end
print("[src-payphone] QBox Framework initialized")
else
print("[src-payphone] Standalone mode initialized")
end
end)
Bridge = {}
Bridge.HasEnoughMoney = function(amount)
if Config.Debug then
return true
end
if Config.RemoveMoney == "ox_inventory" then
return exports.ox_inventory:GetItemCount("cash") >= amount
elseif Config.Framework == "esx" or Config.Framework == "esxnew" then
local xPlayer = ESX.GetPlayerData()
return xPlayer.money >= amount
elseif Config.Framework == "qbcore" then
local Player = QBCore.Functions.GetPlayerData()
return Player.money.cash >= amount
elseif Config.Framework == "qbox" then
return QBX.PlayerData.money.cash >= amount
else
return true
end
end
Bridge.RemoveMoney = function(amount)
if Config.Debug then
print("[src-payphone] Debug mode: Removing money: " .. amount)
return true
end
if Config.RemoveMoney == "ox_inventory" then
return lib.callback.await('src-payphone:removeMoney', false, amount, "ox_inventory")
else
return lib.callback.await('src-payphone:removeMoney', false, amount, Config.Framework)
end
end
Bridge.Notify = function(message, type)
if Config.Framework == "esx" or Config.Framework == "esxnew" then
ESX.ShowNotification(message)
elseif Config.Framework == "qbcore" then
QBCore.Functions.Notify(message, type)
elseif Config.Framework == "qbox" then
exports.qbx_core:Notify(message, type)
else
lib.notify({
title = 'Payphone',
description = message,
type = type or 'info'
})
end
end
Bridge.RegisterTarget = function(models, options)
if Config.Target == "ox_target" then
exports.ox_target:addModel(models, options)
elseif Config.Target == "qb-target" then
local qbOptions = {
options = {},
distance = 2.0
}
for _, option in ipairs(options) do
table.insert(qbOptions.options, {
type = "client",
event = "src-payphone:usePayphone",
icon = option.icon,
label = option.label,
entity = option.entity,
canInteract = function(entity)
entity = entity
return true
end
})
end
exports['qb-target']:AddTargetModel(models, qbOptions)
else
print("[src-payphone] No target system specified in config")
end
end
function splitString(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t = {}
for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do
table.insert(t, str)
end
return t
end