Hi,
I’d like to start by saying I’ve been following mono_v2_get_started and Examples.md and I have searched Google and CFX forums to no avail. So I heard about the new Mono V2 runtime that’s available as a prerelease and wanted to try it out. I am currently in the process of converting my project from Mono V1 to Mono V2.
- My first problem is the CallbackDelegate type that was available in V1 isn’t available in V2.
This is what I had used previously:
RegisterNuiCallbackType("Example");
EventHandlers["__cfx_nui:Example"] += new Action<dynamic, CallbackDelegate>(Example);
private void Example(dynamic data, CallbackDelegate callback)
{
SetNuiFocus(false, false); callback("OK");
}
I believe the EventHandler is still fine but can now also be replaced with:
RegisterNuiCallbackType("Example");
[EventHandlers("__cfx_nui:Example", Binding.Local)]
private void Example(dynamic data, CallbackDelegate callback)
{
SetNuiFocus(false, false); callback("OK");
}
The exception being CallbackDelegate. When I first switched to C# I used nui-callbacks and I also used CallbackDelegate outside of NUI callbacks as well (wrongfully I suspect). I’ve switch some of my code to using Action instead of CallbackDelegate but what would be the replacement for NUI callbacks?
- My next question isn’t really a problem but I’m curious if there’s a similar way to the old of sending an event to every client.
Old:
TriggerClientEvent("Example", data);
New:
PlayerList players = new PlayerList();
foreach (Player player in players)
{
TriggerClientEvent("Example", player, data);
}