Class Events
- Namespace
- VsGlobal
- Assembly
- VSGlobal.dll
Events allows you to add callbacks to VsGlobal events.
Events.OnConnect += (e) => {}; // Where e is type OnConnectEventArgs
Using a function:
public void MyCustomHandler(OnPayloadReceivedEventArgs e)
{
Console.WriteLine(e.payload.Module); // "core"
}
Events.OnPayloadReceived += MyCustomHandler;
public static class Events
- Inheritance
-
Events
- Inherited Members
Events
OnClientReady
Invoked when the ICoreClientAPI.World.Player is fully loaded
Events.OnClientReady += (e) =>
{
e.config.api.Logger.Info(e.config.module);
};
Using a function:
public void MyCoolOnClientReady(OnClientReadyEventArgs e)
{
// Do some stuff with e.config
e.config.api.ShowChatMessage(e.config.player.PlayerName);
}
// Then later, in a function body somewhere we register the handler.
Events.OnClientReady += MyCoolOnClientReady;
public static event OnClientReadyHandler OnClientReady
Event Type
- See Also
OnConnect
Invoked when VsGlobal has connected
Events.OnConnect += (e) =>
{
if(e.module == "my_module_name")
{
// Do stuff just for our module!
}
else
{
// Do stuff for any other module!
}
};
Using a function:
public void MyCoolOnConnect(OnConnectedEventArgs e)
{
// Do some stuff with e.module
}
// Then later, in a function body somewhere we register the handler.
Events.OnConnect += MyCoolOnConnect;
public static event OnConnectHandler OnConnect
Event Type
- See Also
OnDisconnect
Invoked when VsGlobal has disconnected (banned, server issue, skill issue)
Events.OnDisconnect += (e) =>
{
if(e.module == "my_module_name")
{
// Cleanup our mod code because we're DC'd.
}
else
{
// Likely don't care, but might care.
}
};
Using a function:
public void MyCoolOnDisconnect(OnDisconnectEventArgs e)
{
// Do some stuff with e.module
}
// Then later, in a function body somewhere we register the handler.
Events.OnDisconnect += MyCoolOnDisconnect;
public static event OnDisconnectHandler OnDisconnect
Event Type
- See Also
OnPayloadReceived
Invoked when VsGlobal receives a payload
Events.OnPayloadReceived += (e) =>
{
// This will be called whenever a packet arrives, regardless of module or sender.
if(e.payload.Module == "my_module_name")
{
// Now that we know the payload is for our module, we can try converting it to our expected types.
MyCustomClass? myCustomThing = e.payload.DeserializePacket<MyCustomClass>();
if(myCustomThing is MyCustomClass packet)
{
DoSomething(myCustomThing.value);
}
}
else
{
// It's someone else's packet. Could be handy for extension mods!
}
};
Using a function:
public void ReceiveMessagePacket(OnPayloadReceivedEventArgs e)
{
// Same as the lambda, we have access to any payload coming in here.
Message? maybeMessage = e.payload.DeserializePacket<Message>();
// We can also be quite cheeky and attempt to deserialize it to our custom type regardless of module.
// If it doesn't, it's not ours- So I suppose that's valid as well.
if(maybeMessage is Message msg)
{
// Do something with our received custom message!
}
}
// Ideally, within `public override void StartClientside(ICoreClientAPI)`
Events.OnPayloadReceived += ReceiveMessagePacket;
public static event OnPayloadReceivedHandler OnPayloadReceived
Event Type
- See Also
OnReconnect
Invoked when VsGlobal is trying to reconnect
Events.OnReconnect += (e) =>
{
if(e.module == "my_module_name")
{
// Cleanup our mod code because we're DC'd.
var myValue = e.attempts;
}
else
{
// Likely don't care, but might care.
}
};
Using a function:
public void MyCoolOnReconnect(OnReconnectEventArgs e)
{
if(e.attempts == 3 && e.module == "my_module_name") { /* Do stuff */ }
}
// Then later, in a function body somewhere we register the handler.
Events.OnReconnect += MyCoolOnReconnect;
public static event OnReconnectHandler OnReconnect
Event Type
- See Also