Hey there,
i was trying to send arrays from the client side to the server, but it returned a cast exception on the server side:
Error invoking callback for event saveClothing: System.InvalidCastException: Could not cast event argument for saveClothing from List`1 to Int32[,]
at CitizenFX.Core.EventHandlerEntry.<Invoke>g__ChangeType5_0 (System.Object value, System.Type type) [0x00020] in /src/code/client/clrcore/EventHandlerDictionary.cs:99
at CitizenFX.Core.EventHandlerEntry+<Invoke>d__5.MoveNext () [0x000f4] in /src/code/client/clrcore/EventHandlerDictionary.cs:137
Heres my code as example:
Style playerStyle = Game.PlayerPed.Style;
PedComponent[] playerStyleComp = playerStyle.GetAllComponents();
PedProp[] playerStyleProp = playerStyle.GetAllProps();
int playerPedHash = Game.PlayerPed.Model.Hash;
Debug.WriteLine(playerPedHash.ToString());
int[,] pedComps = new int[playerStyleComp.Length, 3];
int[,] pedProps = new int[playerStyleProp.Length, 3];
for (int i = 0; i < playerStyleComp.Length; i++)
{
PedComponents pedComp = StringToPedComponents(playerStyleComp[i].ToString());
Debug.WriteLine("Cat: {0} | Index: {1} | Texture: {2}", (int)pedComp, playerStyleComp[i].Index, playerStyleComp[i].TextureIndex);
pedComps[i, 0] = (int)pedComp;
pedComps[i, 1] = playerStyleComp[i].Index;
pedComps[i, 2] = playerStyleComp[i].TextureIndex;
}
Debug.WriteLine("--------------");
for (int i = 0; i < playerStyleProp.Length; i++)
{
PedProps pedProp = StringToPedProps(playerStyleProp[i].ToString());
Debug.WriteLine("Cat: {0} | Index: {1} | Texture: {2}", (int)pedProp, playerStyleProp[i].Index, playerStyleProp[i].TextureIndex);
pedProps[i, 0] = (int)pedProp;
pedProps[i, 1] = playerStyleProp[i].Index;
pedProps[i, 2] = playerStyleProp[i].TextureIndex;
}
Debug.WriteLine("--------------");
TriggerServerEvent("saveClothing", playerPedHash, pedComps, pedProps);
EventHandlers["saveClothing"] += new Action<Player, int, int[,], int[,]>(saveClothing);
private void saveClothing([FromSource] Player caller, int modelHash, int[,] pedComps, int[,] pedProps)
{
Debug.WriteLine("{0} -- {1} -- {2}//{3}", caller.Name, modelHash, pedComps.Length, pedProps.Length);
DB.saveClothing(caller.Identifiers["steam"], modelHash);
}
Redid it with List<>:
EventHandlers["saveClothing"] += new Action<Player, int, List<int>, List<int>>(saveClothing);
private void saveClothing([FromSource] Player caller, int modelHash, List<int> pedComps, List<int> pedProps)
{
Debug.WriteLine("{0} -- {1} -- {2}//{3}", caller.Name, modelHash, pedComps.Count, pedProps.Count);
DB.saveClothing(caller.Identifiers["steam"], modelHash);
}
Error invoking callback for event saveClothing: System.InvalidCastException: Could not cast event argument for saveClothing from List`1 to List`1
at CitizenFX.Core.EventHandlerEntry.<Invoke>g__ChangeType5_0 (System.Object value, System.Type type) [0x00020] in /src/code/client/clrcore/EventHandlerDictionary.cs:99
at CitizenFX.Core.EventHandlerEntry+<Invoke>d__5.MoveNext () [0x000f4] in /src/code/client/clrcore/EventHandlerDictionary.cs:137
What is the propper way to do this?
I also tried to use json/xml serialization, but couldn’t get it even working on the client side.