C# chatMessage error


#1

I am trying to use the chatMessage event but I get the following FormatException error…

7393094] Error invoking callback for event chatMessage: System.FormatException: Input string was not in a correct format.

[   7393094]   at System.Number.StringToNumber (System.String str, System.Globalization.NumberStyles options, System.Number+NumberBuffer& number, System.Globalization.NumberFormatInfo info, System.Boolean parseDecimal) [0x00057] in <a4e3abdd630b4c98a9d6f31a99197de6>:0 

[   7393094]   at System.Number.ParseInt32 (System.String s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) [0x00015] in <a4e3abdd630b4c98a9d6f31a99197de6>:0 

[   7393094]   at System.Int32.Parse (System.String s, System.Globalization.NumberStyles style, System.IFormatProvider provider) [0x0000e] in <a4e3abdd630b4c98a9d6f31a99197de6>:0 

[   7393094]   at System.Convert.ToInt32 (System.String value, System.IFormatProvider provider) [0x00005] in <a4e3abdd630b4c98a9d6f31a99197de6>:0 

[   7393094]   at System.String.System.IConvertible.ToInt32 (System.IFormatProvider provider) [0x00000] in <a4e3abdd630b4c98a9d6f31a99197de6>:0 

[   7393094]   at System.Convert.ChangeType (System.Object value, System.Type conversionType, System.IFormatProvider provider) [0x0011a] in <a4e3abdd630b4c98a9d6f31a99197de6>:0 

[   7393094]   at System.Convert.ChangeType (System.Object value, System.Type conversionType) [0x0000c] in <a4e3abdd630b4c98a9d6f31a99197de6>:0 

[   7393094]   at CitizenFX.Core.CallUtilities.<GetPassArguments>g__ChangeType0_0 (System.Object value, System.Type type) [0x00018] in C:\gl\builds\aaf2d114\0\cfx\fivem\code\client\clrcore\EventHandlerDictionary.cs:118 

[   7393094]   at CitizenFX.Core.CallUtilities.GetPassArguments (System.Reflection.MethodInfo method, System.Object[] args, System.String sourceString) [0x00066] in C:\gl\builds\aaf2d114\0\cfx\fivem\code\client\clrcore\EventHandlerDictionary.cs:159 

[   7393094]   at CitizenFX.Core.EventHandlerEntry+<Invoke>d__5.MoveNext () [0x00047] in C:\gl\builds\aaf2d114\0\cfx\fivem\code\client\clrcore\EventHandlerDictionary.cs:84 
[   7393094] 

The code looks like…

    public class Client : BaseScript
    {
        private bool firstTick = false;

        public Client()
        {
            Tick += OnTick;

            EventHandlers.Add("chatMessage", new Action<int, string, string>(OnChatMessage));
        }

        private async Task OnTick()
        {
            await Delay(100);

            if (!firstTick)
            {
                firstTick = true;
            }
        }

        public void OnChatMessage(int id, string playerName, string message)
        {
            Debug.WriteLine("**** OnChatMessage ****");
            Debug.WriteLine("id: {0}", id);
            Debug.WriteLine("playerName: {0}", playerName);
            Debug.WriteLine("message: {0}", message);
        }

#2

That code should be on the server side


#3

Thank you @Briglair, I am rolling now.