[SOLVED] ESX GCPhone not generating numbers/returning nil value (local 'xPlayer')/(global 'xPlayer')

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).

When trying to call someone


mstsc_SGvaI43lQb

Trying to add someone as a contact


mstsc_SYMShzKCBB

Trying to text someone


mstsc_8FqcWsNUPA

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:
mstsc_3uYV8ZE0D3
I used the SQL’s that came with the GCPhone… and even modified it in hopes that it would work properly.


This is what it looks like in depth.

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.

The phone only shows its numbers as ###-####
FiveM_GTAProcess_7di5KU4CPB

This is the GCPhone I’m using right now: GitHub - manueljlz/gcphone: Telephone for FiveM by ElBichop
I’m using v3.2.0 of mysql-async.
I’m using this essentialmode: GitHub - kanersps/essentialmode: A FiveM project
I’m using this es_extended: https://github.com/esx-community/es_extended

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.

gcphone is definitely starting after es_extended, here’s how my server.cfg looks like

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.

The numbers on the phone still appear as ###-#### as well

Cause there hasn’t been a phone number set in your db. It can’t return anything if there is nothing there… LOL !

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.

I can take a look at it, if you attach the server.lua in the comments below.

Best Regards,
Nikwitz

@Nikwitz1
Here’s the server.lua we’re using.

server.lua (26.4 KB)

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.

Best Regards,
Nikwitz

I’m not sure I understand? I added an SQL under items:

INSERT INTO essentialmode.items (name, label, limit) VALUES (‘sim_card’, ‘Sim Card’, ‘10’);

but it still returns as NULL.

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.)

4 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.