Every functionality works besides the calling/texture feature. Practically whenever I try to call, text, or add a number it will return with “Script Error: @gcphone/server/server.lua:xxx; attempt to index a nul value (global 'xPlayer)” – or even (local 'xPlayer).
To me it seems like somewhere in the code it has trouble generating numbers under a player’s ID in the database (Subjective opinion).
Here’s how my SQL DB looks like
This is under the users table:
I used the SQL’s that came with the GCPhone… and even modified it in hopes that it would work properly.
I just really want to understand how to get the numbers to generate on the database. I’m 99.9% sure it’s not a database error considering the only errors I get are from lines of code with the “xPlayer” part.
I’ve looked pretty much through thick and thin for any sort of fix for this. I’ve done code changes, I’ve switched the phones around to newer versions or made by different people, I’ve even switched around versions for es_extended, esx_addons_gcphone, mysql-async… and it still poses the same “errors”, sometimes even added more errors or didn’t even show numbers anymore. I’ve watched tutorials on installing it, even foreign tutorials, nothing has worked.
Make sure gcphone is starting after es_extended in your server.cfg (or whatever file you chose to use). If ESX does not start first before anything else relying on it, the ESX object in this case gcphone attempts to retrieve on start will return nil. Or if there are errors starting es_extended it likely did not fully execute and you will need to get es_extended to start cleanly first.
Okay, I actually updated essentialmode to the NEWEST possible version. It now registers people in the database but it returns the phone_number as NULL.
I’m not quite sure. Like I said, I’m using the SQL’s that were given to me from the GCPhone, which would be in the base.sql. It sets it as NULL, which I’m quite unsure how to modify it so it doesn’t set it as NULL and actually assigns a number to the player’s identifier.
Edit #2:
I manually modified the phone_number with an number, but it still doesn’t show in-game. Still just ###-#### displayed on the phone. But I want phone number’s to be assigned automatically.
Here is your problem. You have to get a SIM Card before you can get a number.
RegisterServerEvent('gcPhone:useSimCard')
AddEventHandler('gcPhone:useSimCard', function(source, identifier)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local myPhoneNumber = nil
repeat
myPhoneNumber = getPhoneRandomNumber()
local id = getIdentifierByPhoneNumber(myPhoneNumber)
until id == nil
MySQL.Async.insert("UPDATE users SET phone_number = @myPhoneNumber WHERE identifier = @identifier", {
['@myPhoneNumber'] = myPhoneNumber,
['@identifier'] = xPlayer.identifier
}, function (rows)
xPlayer.removeInventoryItem('sim_card', 1)
local num = getNumberPhone(xPlayer.identifier)
TriggerClientEvent("gcPhone:myPhoneNumber", _source, num)
TriggerClientEvent("gcPhone:contactList", _source, getContacts(identifier))
TriggerClientEvent("gcPhone:allMessage", _source, getMessages(identifier))
TriggerClientEvent('gcPhone:getBourse', _source, getBourse())
sendHistoriqueCall(_source, num)
end)
end)
ESX.RegisterUsableItem('sim_card', function (source)
TriggerEvent('gcPhone:useSimCard', source)
end)
You need to make sure that you have added the item sim_card to the database and then give yourself that one, before it generates a random phone number for you.
You have to give yourself the sim_card in-game as an item and then use it from your inventory system. Afterwards you should get a random number into your phone because it calls the function getPhoneRandomNumber
Okay. I actually got a number to generate finally. I switched out es_extended for extendedmode and removed esplugin_mysql from the config. The phone works PERFECTLY now. Thank you guys for the help!
I completely removed the sim_card code as well. (So I don’t know if that has any effect on generating the number.)