FxEvents: An Advanced Event Subsystem for FiveM
FxEvents is a powerful event system for FiveM, providing robust features for event handling with an emphasis on security and ease of use. Whether you’re building multiplayer scripts or custom client-server communication systems, FxEvents offers powerful features to enhance your development workflow.
Features
1. Robust Event Handling
- Simple integration into both client and server scripts.
- Support for both synchronous and asynchronous events.
- Use of MsgPack binary serialization for efficient and fast data transmission.
- Encrypted signatures for data security and integrity.
2. Automatic Event Initialization (v3.0.0+)
- Internal events are now automatically generated using SHA-256 based on the resource name and a random seed.
- Simplified process eliminates the need for manual event initialization.
3. Advanced Event Mounting
- Mount events using lambda style or classic methods for greater flexibility.
- Support for customizable parameters with
FromSourceattribute for player-specific event handling. - The system is not limited to specific parameters; event parameters can now be dynamically cast between different types.
4. Encryption and Anti-Tamper Features
- Events are safeguarded against tampering with an anti-tamper system that flags suspicious events.
- The library supports encryption and decryption with customizable passkeys for added security.
- Protect against attacks like repeated messages, edited encrypted data, and public key spoofing.
5. Native ValueTuple Support
- FxEvents supports ValueTuples natively from version 3.0.0, which makes it easier to work with structured data without needing external libraries.
6. Server and Client-Side Event Triggering
- Trigger events from both server and client sides.
- Use the
EventHub.Sendmethod for both global and targeted events, including triggering for all connected players or specific ones.
7. Event Binding Options (v3.0.0+)
- Define event bindings using four types:
None,Local,Remote, andAll. - More control over how and when events are triggered based on context.
8. Support for FiveM Types
- Send FiveM-specific types such as Player, Ped, Vehicle, Prop, and Entity as event parameters.
- Handle networked entities and math structures like Vectors and Quaternions seamlessly.
9. Callbacks and Response Handling
- Use callbacks for synchronous responses from the other side.
- Mount callbacks using either lambda style or with the
[FxEvent("EventName")]attribute.
10. Serialization Features
- Serialize and deserialize objects with built-in ToJson() and FromJson() methods.
- Convert objects to and from byte arrays using ToBytes() and FromBytes().
- Support for encryption during serialization with the
EncryptObject()andDecryptObject()methods.
11. Easy Debugging and Customization
- Includes extensive debugging tools, like the ability to generate SHA-256 hashes for custom data, making it easier to track event integrity.
- Convert byte arrays to readable strings and vice versa using
BytesToString()andStringToBytes().
12. Community and Support
- For more details, join our Discord server to ask questions, request support, or share your ideas with other developers.
- If you find this library useful, consider supporting me via PayPal—you can buy a coffee, a donut, or even a Tesla!
Usage Example
To integrate FxEvents into your project, you’ll need to initialize it first and mount events for your specific use cases. Below is an example of how to get started:
Initialize FxEvents:
public class Main : BaseScript
{
public Main()
{
// Initialize the FxEvents library. Call this once at script start to enable EventHub usage anywhere.
EventHub.Initialize();
}
}
Mounting an Event:
EventHub.Mount("eventName", Binding.All, new Action<ISource, string, int>(([FromSource] source, string val1, int val2) =>
{
// Code to execute inside the event.
Logger.Info($"Event triggered with values: {val1}, {val2}");
}));
Conclusion
FxEvents provides a comprehensive, flexible, and secure event-handling system for FiveM developers. With its advanced features such as encryption, MsgPack serialization, and anti-tampering, it ensures efficient and safe communication across client-server boundaries in multiplayer environments.