Quick question I hope.
I'm trying to get the player name from OnPlayerChat - the syntax I want is the name with steamID like:
I tried:Code:playername[0123456/7656123456789]
But I get an error about converting to string, if I leave as a BasePlayer I get a recursive error in my JSON serialization (sorry, can't remember exact wording).Code:string player = (BasePlayer)arg.connection.player;
Is there a quick way to get this?
Thanks, as always, for any help
Tony.
Getting player name with steamID in OnPlayerChat?
Discussion in 'Rust Development' started by Rebajas, Jan 4, 2017.
-
More detail of how I'm using this:
Code:void OnPlayerChat(ConsoleSystem.Arg arg) { BasePlayer player = (BasePlayer)arg.connection.player; string playerName = arg.connection.player; // string playerName = player.displayName; // var playerName = player; Vector3 location = player.transform.position; string chat = arg.GetString(0, ""); chat = Uri.EscapeDataString(chat); chatLog.Add(new { Timestamp = nowTimestamp, Player = playerName, Chat = chat, LocationX = location.x, LocationY = location.y, LocationZ = location.z });...
Code:public void SendLog() { var serializedChatLog = JsonConvert.SerializeObject(chatLog);
-
Wulf Community Admin
-
For now I have built the string up using displayName and UserIDString - it works for my purposes but feels a bit hacky.
If you think this is a reasonable approach then I'll move onto more important things -
Code:
void OnPlayerChat(ConsoleSystem.Arg arg) { BasePlayer player = arg.Player(); string playerName = player.displayName; Vector3 location = player.transform.position; string chat = arg.ArgsStr; chatLog.Add(new { Timestamp = nowTimestamp, Player = playerName, Chat = chat, LocationX = location.x, LocationY = location.y, LocationZ = location.z }); }
[DOUBLEPOST=1483570949][/DOUBLEPOST]if you need more information about the player in your chatlog list you could also add in their ulong id: player.userID