I’m trying to use the playerConnecting event to insert people onto my database, which works fine at first.
But after a few restarts or so, the param “source” does not return the true value anymore…?
Any reason behind this, or is there any other way to reliably get the player source Id at all times?
It works fine with any other script, just not this one, which makes it extremely strange…
I think’s the better solution is to check if player is in the database in playerConnecting: if player is in database do nothing but if not in database insert informations
That is what I am doing…
But to do so, I need to get the steamID from the “player source ID(the source param)”. Which again, works fine at first, and then it breaks and returns a “table: xxxxxx” instead of serverID.
Use this for get identifier
function getPlayerID(source)
local identifiers = GetPlayerIdentifiers(source)
local player = getIdentifiant(identifiers)
return player
end
function getIdentifiant(id)
for _, v in ipairs(id) do
return v
end
end
Usage:
TriggerEvent('playerConnecting', function()
local user_id = getPlayerID(source)
end)
Once again, That is what I am doing, but I can’t get the steamID from “table: xxxxxxx”, Only way I get it working with is “source” (player server ID)
Can you show your code ?
You clearly already know what I am doing, so what’s the point?
And again, the SOURCE PARAM returns something DIFFERENT from what it is supposed to do.
AddEventHandler('playerConnecting', function(source)
local user = GetSteamId(source)
local StartingMoney = 100
MySQL.Async.fetchAll("SELECT * FROM test WHERE identifier = '"..user.."'", {}, function(result)
if(result[1] == nil) then
MySQL.Async.execute("INSERT INTO test(`identifier`,`money`,`admin`) VALUES (@identifier,@money,@admin)",{['@identifier'] = user,['@money'] = StartingMoney, ['@admin'] = false})
end
end)
end)
function GetSteamId(user)
local identifiers = GetPlayerIdentifiers(user)[1]
return identifiers
end
Try the functions I have send
I have more than one of these events going on, and all but this one works perfectly, but after a while, this particular one returns “source = table: xxxxxxx” instead of “source = id(x)”
The issue isn’t the script itself, the PARAMETER is returning the wrong thing.
So, is there any reliable way to always get the serverID before a player spawns, or any fix to this(parameter)?
It looks like the function was changed up a bit. I’m not sure if this would apply to your issue, but try using the new one here http://runtime.fivem.net/doc/reference.html#_0x7302dbcf
Otherwise, I had some issues with ‘source’ randomly changing on me. 1 out of 5-ish times it would change to a different number. I was able to fix that by putting local source = source
at the top of my event handler. Not sure if this would apply to you either, but might be worth a shot.
Thank you, will give this a try!
EDIT: Tested source = source, same problem still occurs…
Having “playerConnect” print source through 2 different files returns:
Broken file = “source = table: 0000019FCD155080” OR “source = nil”
Working file = “source = 65540”
AddEventHandler('playerConnecting', function()
print('Source = '..source)
end)
EDIT 2:
I seem to have “fixed” it by adding another EMPTY playerConnecting event.
But now the working file is returning the wrong thing…?!
Should sources even be numbers like that (65540)? Shouldn’t they be relatively low numbers – player ids?
It should return a temporary serverID just before the player connects, after that, the player is given an actual serverID
Ah, this might be a legitimate code issue: source not being reset between multiple event handlers in the same resource.
Yeah it probably is, I’m trying to use playerConnecting and every time I get in my source is a crazy high number and causes loads of issues. It was 65536 a second ago.
It is supposed to be a high number, it’s a Temporary Server ID, not a Server ID as the player has not yet connected.
The issue is two playerConnecting events in 1 resource interfere with one another so the source param bugs and returns the wrong thing
Bump. I am currently experiencing this issue. Code:
AddEventHandler("playerConnecting", function(name, setKickReason, deferrals)
print(source)
end
Outputs nil
in console.
Can reproduce.
Can’t reproduce if I define source
in a variable:
AddEventHandler("playerConnecting", function(name, setKickReason, deferrals)
local src = source
print(src)
end
Maybe this will help.
Yeah, I found a solution on another thread. Link here. You simply have to define the source somewhere as soon as possible.
Link: Source shows as nil on playerConnecting event - #5 by MasiBall