Issue
Hello everybody!
Currently I’m trying to gather the steam identifier for a player. I haven’t found any easy way to do that in C# alone, so I’ve set my code in C# to trigger a function in lua. From there, I need to know how to send the result back to C# so that I can use it properly. I’ve tried many ways, but here’s my current strategy:
Lua Code
RegisterServerEvent("ReturnPlayerIdentifier")
RegisterServerEvent("GetPlayerIdentifier")
AddEventHandler("GetPlayerIdentifier", function(id)
local player = GetPlayers()[id]
local identifiers = GetPlayerIdentifiers(player)
local identifier = identifiers[0]
TriggerEvent("ReturnPlayerIdentifier", -1, { id = identifier })
end)
C# BaseScript Tick Function
if (FirstTick)
{
EventHandlers["ReturnPlayerIdentifier"] += new Action<String>((String id) =>
{
identifier = id;
});
FirstTick = !FirstTick;
}
C# Class Needing Identifier
if (interacted)
{
Player player = Game.Player;
Main.TriggerServerEvent("GetPlayerIdentifier", player.ServerId);
identifier = Main.ReturnIdentifier();
CitizenFX.Core.UI.Screen.ShowNotification("IDENTIFIER: " + identifier);
}
I can confirm that triggering the event from the class that requires the identifier does indeed send the player’s id to the lua function and the function successfully retrieves the correct identifier. However, I can’t seem to get the identifier back to C#. I have already tried techniques like that of this post.
Any help is appreciated and I am thankful in advance.
EDIT (8/16/2017 : 9:44PM EST)
Issue solved. Realized that I wasn’t using the server CitizenFX reference.