Files
new-phone-who-dis/resources/server/sv_contacts.lua
T
erik-sn cb75d2f5cc add database config object
Adds a DatabaseConfig dictionary which will allow an admin to specify a
custom table/columns that exist outside of ESX. This gives us
flexibility between ESX versions as well as making the phone frameworkas
decoupled from ESX as possible.

Also updates the contacts table to be namespaces with npwd
2020-10-04 15:08:44 -04:00

38 lines
1.1 KiB
Lua

ESX = nil
db = DatabaseConfig -- helper variable for use in server functions
TriggerEvent('esx:getSharedObject', function(obj)
ESX = obj
end)
ESX.RegisterServerCallback('phone:getContacts', function(source, cb)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local _identifier = xPlayer.getIdentifier()
MySQL.Async.fetchAll('SELECT * FROM npwd_phone_contacts WHERE `identifier`=@identifier',
{
['@identifier'] = _identifier
}, function(contacts)
cb(contacts)
print("Contacts:")
for k,v in pairs(contacts) do
print(v.number, v.display)
end
end)
end)
RegisterServerEvent('phone:addContacts')
AddEventHandler('phone:addContacts', function(display, number)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local _identifier = xPlayer.getIdentifier()
print(display, number)
MySQL.Async.execute('INSERT INTO npwd_phone_contacts (`identifier`, `number`, `display`) VALUES (@identifier, @number, @display)',
{
identifier = _identifier,
number = number,
display = display
}, function()
end)
end)