Sign in to follow this  
notsosmart

C# - Events in style of RemoteEvent [Outdated]

Recommended Posts

A similar but official and better system has been integrated into RageMP.

 

 

To initialize at startup

Call this anywhere

public MainClass() : Script
{
	//call before any events
    public MainClass()
    {
	RageEventHelper helper = new RageEventHelper();
    }
}

 

Usage

1. Copy and paste the spoiler code in a new .cs file (Make sure to use needed libraries like LINQ)

2. See example below

Notes
1. You are responsible for properly delegating every event at startup. Look in the example below. Only do this once in the main script file and you are set.

2. Events must be public static void methods

Example (How to delegate the events properly at startup)

public class MainClass : Script
{
    public MainClass()
    {
	RageEventHelper helper = new RageEventHelper();
        Event.OnPlayerEnterVehicleAttempt += OnPlayerEnterVehicleAttempt;
        Event.OnUpdate += OnUpdate;
    }
    
    public void OnPlayerEnterVehicleAttempt(Client player, Vehicle veh, sbyte seat)
    {
        RageEventExtender.InvokeAllMethods<OnPlayerEnterVehicleAttemptEvent>(RageEventExtender.OnPlayerEnterVehicleAttemptEvents, player, veh, seat);
    }
    
    public void OnUpdate()
    {
        RageEventExtender.InvokeAllMethods<OnUpdateEvent>(RageEventExtender.OnUpdateEvents, null);
    }
}

In another file (How to use the events)

public class AnotherClass
{
	[OnPlayerEnterVehicleAttempt]
	public static void OnEnterAttempt(Client player, Vehicle veh, sbyte seat)
	{
		//enter
	}
	
	[OnUpdate]
	public static void OnUpdateThing()
	{
		//update
	}
}
Spoiler
namespace RageServer.Wrappers
{
    public static class RageEventExtender
    {
        public static void InvokeAllMethods<T1>(Dictionary<T1, MethodInfo> dict, params object[] args)
        {
            foreach (T1 key in dict.Keys)
            {
                dict[key].Invoke(null, args);
            }
        }

        public static Dictionary<OnPlayerEnterVehicleAttemptEvent, MethodInfo> OnPlayerEnterVehicleAttemptEvents = new Dictionary<OnPlayerEnterVehicleAttemptEvent, MethodInfo>();
        public static Dictionary<OnPlayerExitVehicleAttemptEvent, MethodInfo> OnPlayerExitVehicleAttemptEvents = new Dictionary<OnPlayerExitVehicleAttemptEvent, MethodInfo>();
        public static Dictionary<OnPlayerExitVehicleEvent, MethodInfo> OnPlayerExitVehicleEvents = new Dictionary<OnPlayerExitVehicleEvent, MethodInfo>();
        public static Dictionary<OnVehicleSirenToggleEvent, MethodInfo> OnVehicleSirenToggleEvents = new Dictionary<OnVehicleSirenToggleEvent, MethodInfo>();
        public static Dictionary<OnVehicleDeathEvent, MethodInfo> OnVehicleDeathEvents = new Dictionary<OnVehicleDeathEvent, MethodInfo>();
        public static Dictionary<OnVehicleHornToggleEvent, MethodInfo> OnVehicleHornToggleEvents = new Dictionary<OnVehicleHornToggleEvent, MethodInfo>();
        public static Dictionary<OnVehicleDoorBreakEvent, MethodInfo> OnVehicleDoorBreakEvents = new Dictionary<OnVehicleDoorBreakEvent, MethodInfo>();
        public static Dictionary<OnVehicleWindowSmashEvent, MethodInfo> OnVehicleWindowSmashEvents = new Dictionary<OnVehicleWindowSmashEvent, MethodInfo>();
        public static Dictionary<OnVehicleTyreBurstEvent, MethodInfo> OnVehicleTyreBurstEvents = new Dictionary<OnVehicleTyreBurstEvent, MethodInfo>();
        public static Dictionary<OnEntityCreatedEvent, MethodInfo> OnEntityCreatedEvents = new Dictionary<OnEntityCreatedEvent, MethodInfo>();
        public static Dictionary<OnEntityModelChangeEvent, MethodInfo> OnEntityModelChangeEvents = new Dictionary<OnEntityModelChangeEvent, MethodInfo>();
        public static Dictionary<OnResourceStartEvent, MethodInfo> OnResourceStartEvents = new Dictionary<OnResourceStartEvent, MethodInfo>();
        public static Dictionary<OnResourceStopEvent, MethodInfo> OnResourceStopEvents = new Dictionary<OnResourceStopEvent, MethodInfo>();
        public static Dictionary<OnUpdateEvent, MethodInfo> OnUpdateEvents = new Dictionary<OnUpdateEvent, MethodInfo>();
        public static Dictionary<OnServerResourceStartEvent, MethodInfo> OnServerResourceStartEvents = new Dictionary<OnServerResourceStartEvent, MethodInfo>();
        public static Dictionary<OnServerResourceStopEvent, MethodInfo> OnServerResourceStopEvents = new Dictionary<OnServerResourceStopEvent, MethodInfo>();
        public static Dictionary<OnMapChangeEvent, MethodInfo> OnMapChangeEvents = new Dictionary<OnMapChangeEvent, MethodInfo>();
        public static Dictionary<OnPlayerEnterVehicleEvent, MethodInfo> OnPlayerEnterVehicleEvents = new Dictionary<OnPlayerEnterVehicleEvent, MethodInfo>();
        public static Dictionary<OnEntityDeletedEvent, MethodInfo> OnEntityDeletedEvents = new Dictionary<OnEntityDeletedEvent, MethodInfo>();
        public static Dictionary<OnVehicleDamageEvent, MethodInfo> OnVehicleDamageEvents = new Dictionary<OnVehicleDamageEvent, MethodInfo>();
        public static Dictionary<OnPlayerDetonateStickiesEvent, MethodInfo> OnPlayerDetonateStickiesEvents = new Dictionary<OnPlayerDetonateStickiesEvent, MethodInfo>();
        public static Dictionary<OnPlayerSpawnEvent, MethodInfo> OnPlayerSpawnEvents = new Dictionary<OnPlayerSpawnEvent, MethodInfo>();
        public static Dictionary<OnChatMessageEvent, MethodInfo> OnChatMessageEvents = new Dictionary<OnChatMessageEvent, MethodInfo>();
        public static Dictionary<OnPlayerConnectedEvent, MethodInfo> OnPlayerConnectedEvents = new Dictionary<OnPlayerConnectedEvent, MethodInfo>();
        public static Dictionary<OnPlayerDisconnectedEvent, MethodInfo> OnPlayerDisconnectedEvents = new Dictionary<OnPlayerDisconnectedEvent, MethodInfo>();
        public static Dictionary<OnPlayerDeathEvent, MethodInfo> OnPlayerDeathEvents = new Dictionary<OnPlayerDeathEvent, MethodInfo>();
        public static Dictionary<OnPlayerConnectEvent, MethodInfo> OnPlayerConnectEvents = new Dictionary<OnPlayerConnectEvent, MethodInfo>();
        public static Dictionary<OnPlayerEnterColShapeEvent, MethodInfo> OnPlayerEnterColShapeEvents = new Dictionary<OnPlayerEnterColShapeEvent, MethodInfo>();
        public static Dictionary<OnPlayerExitColShapeEvent, MethodInfo> OnPlayerExitColShapeEvents = new Dictionary<OnPlayerExitColShapeEvent, MethodInfo>();
        public static Dictionary<OnPlayerEnterCheckpointEvent, MethodInfo> OnPlayerEnterCheckpointEvents = new Dictionary<OnPlayerEnterCheckpointEvent, MethodInfo>();
        public static Dictionary<OnPlayerExitCheckpointEvent, MethodInfo> OnPlayerExitCheckpointEvents = new Dictionary<OnPlayerExitCheckpointEvent, MethodInfo>();
        public static Dictionary<OnPlayerWeaponSwitchEvent, MethodInfo> OnPlayerWeaponSwitchEvents = new Dictionary<OnPlayerWeaponSwitchEvent, MethodInfo>();
        public static Dictionary<OnPlayerDamageEvent, MethodInfo> OnPlayerDamageEvents = new Dictionary<OnPlayerDamageEvent, MethodInfo>();
        public static Dictionary<OnPlayerPickupEvent, MethodInfo> OnPlayerPickupEvents = new Dictionary<OnPlayerPickupEvent, MethodInfo>();
        public static Dictionary<OnVehicleTrailerChangeEvent, MethodInfo> OnVehicleTrailerChangeEvents = new Dictionary<OnVehicleTrailerChangeEvent, MethodInfo>();
        public static Dictionary<OnClientEvent, MethodInfo> OnClientEvents = new Dictionary<OnClientEvent, MethodInfo>();
        public static Dictionary<OnCharacterLoginEvent, MethodInfo> OnCharacterLoginEvents = new Dictionary<OnCharacterLoginEvent, MethodInfo>();
    }

    public class RageEventHelper
    {
        public RageEventHelper()
        {
            LoadUpEvents<OnPlayerExitVehicleEvent, OnPlayerExitVehicleAttribute>(ref RageEventExtender.OnPlayerExitVehicleEvents);
            LoadUpEvents<OnVehicleSirenToggleEvent, OnVehicleSirenToggleAttribute>(ref RageEventExtender.OnVehicleSirenToggleEvents);
            LoadUpEvents<OnVehicleDeathEvent, OnVehicleDeathAttribute>(ref RageEventExtender.OnVehicleDeathEvents);
            LoadUpEvents<OnVehicleHornToggleEvent, OnVehicleHornToggleAttribute>(ref RageEventExtender.OnVehicleHornToggleEvents);
            LoadUpEvents<OnVehicleDoorBreakEvent, OnVehicleDoorBreakAttribute>(ref RageEventExtender.OnVehicleDoorBreakEvents);
            LoadUpEvents<OnVehicleWindowSmashEvent, OnVehicleWindowSmashAttribute>(ref RageEventExtender.OnVehicleWindowSmashEvents);
            LoadUpEvents<OnVehicleTyreBurstEvent, OnVehicleTyreBurstAttribute>(ref RageEventExtender.OnVehicleTyreBurstEvents);
            LoadUpEvents<OnEntityCreatedEvent, OnEntityCreatedAttribute>(ref RageEventExtender.OnEntityCreatedEvents);
            LoadUpEvents<OnEntityModelChangeEvent, OnEntityModelChangeAttribute>(ref RageEventExtender.OnEntityModelChangeEvents);
            LoadUpEvents<OnResourceStartEvent, OnResourceStartAttribute>(ref RageEventExtender.OnResourceStartEvents);
            LoadUpEvents<OnResourceStopEvent, OnResourceStopAttribute>(ref RageEventExtender.OnResourceStopEvents);
            LoadUpEvents<OnUpdateEvent, OnUpdateAttribute>(ref RageEventExtender.OnUpdateEvents);
            LoadUpEvents<OnServerResourceStartEvent, OnServerResourceStartAttribute>(ref RageEventExtender.OnServerResourceStartEvents);
            LoadUpEvents<OnServerResourceStopEvent, OnServerResourceStopAttribute>(ref RageEventExtender.OnServerResourceStopEvents);
            LoadUpEvents<OnMapChangeEvent, OnMapChangeAttribute>(ref RageEventExtender.OnMapChangeEvents);
            LoadUpEvents<OnPlayerExitVehicleAttemptEvent, OnPlayerExitVehicleAttemptAttribute>(ref RageEventExtender.OnPlayerExitVehicleAttemptEvents);
            LoadUpEvents<OnPlayerEnterVehicleEvent, OnPlayerEnterVehicleAttribute>(ref RageEventExtender.OnPlayerEnterVehicleEvents);
            LoadUpEvents<OnEntityDeletedEvent, OnEntityDeletedAttribute>(ref RageEventExtender.OnEntityDeletedEvents);
            LoadUpEvents<OnVehicleDamageEvent, OnVehicleDamageAttribute>(ref RageEventExtender.OnVehicleDamageEvents);
            LoadUpEvents<OnPlayerEnterVehicleAttemptEvent, OnPlayerEnterVehicleAttemptAttribute>(ref RageEventExtender.OnPlayerEnterVehicleAttemptEvents);
            LoadUpEvents<OnPlayerDetonateStickiesEvent, OnPlayerDetonateStickiesAttribute>(ref RageEventExtender.OnPlayerDetonateStickiesEvents);
            LoadUpEvents<OnPlayerSpawnEvent, OnPlayerSpawnAttribute>(ref RageEventExtender.OnPlayerSpawnEvents);
            LoadUpEvents<OnChatMessageEvent, OnChatMessageAttribute>(ref RageEventExtender.OnChatMessageEvents);
            LoadUpEvents<OnPlayerConnectedEvent, OnPlayerConnectedAttribute>(ref RageEventExtender.OnPlayerConnectedEvents);
            LoadUpEvents<OnPlayerDisconnectedEvent, OnPlayerDisconnectedAttribute>(ref RageEventExtender.OnPlayerDisconnectedEvents);
            LoadUpEvents<OnPlayerDeathEvent, OnPlayerDeathAttribute>(ref RageEventExtender.OnPlayerDeathEvents);
            LoadUpEvents<OnPlayerConnectEvent, OnPlayerConnectAttribute>(ref RageEventExtender.OnPlayerConnectEvents);
            LoadUpEvents<OnPlayerEnterColShapeEvent, OnPlayerEnterColShapeAttribute>(ref RageEventExtender.OnPlayerEnterColShapeEvents);
            LoadUpEvents<OnPlayerExitColShapeEvent, OnPlayerExitColShapeAttribute>(ref RageEventExtender.OnPlayerExitColShapeEvents);
            LoadUpEvents<OnPlayerEnterCheckpointEvent, OnPlayerEnterCheckpointAttribute>(ref RageEventExtender.OnPlayerEnterCheckpointEvents);
            LoadUpEvents<OnPlayerExitCheckpointEvent, OnPlayerExitCheckpointAttribute>(ref RageEventExtender.OnPlayerExitCheckpointEvents);
            LoadUpEvents<OnPlayerWeaponSwitchEvent, OnPlayerWeaponSwitchAttribute>(ref RageEventExtender.OnPlayerWeaponSwitchEvents);
            LoadUpEvents<OnPlayerDamageEvent, OnPlayerDamageAttribute>(ref RageEventExtender.OnPlayerDamageEvents);
            LoadUpEvents<OnPlayerPickupEvent, OnPlayerPickupAttribute>(ref RageEventExtender.OnPlayerPickupEvents);
            LoadUpEvents<OnVehicleTrailerChangeEvent, OnVehicleTrailerChangeAttribute>(ref RageEventExtender.OnVehicleTrailerChangeEvents);
            LoadUpEvents<OnClientEvent, OnClientEventAttribute>(ref RageEventExtender.OnClientEvents);
            LoadUpEvents<OnCharacterLoginEvent, OnCharacterLoginAttribute>(ref RageEventExtender.OnCharacterLoginEvents);
        }

        public void LoadUpEvents<T1, T2>(ref Dictionary<T1, MethodInfo> dict)
        {
            List<MethodInfo> attribs = GetType().Assembly.GetTypes().SelectMany(q => q.GetMethods(BindingFlags.Public | BindingFlags.Static)).Where(q => q.GetCustomAttributes(typeof(T2), false).Length > 0).Where(q => q.ReturnType == typeof(void)).ToList();
            foreach (MethodInfo mInfo in attribs)
            {
                if (typeof(T2) == typeof(OnPlayerExitVehicleAttribute))
                {
                    OnPlayerExitVehicleAttribute info = mInfo.GetCustomAttribute<OnPlayerExitVehicleAttribute>();
                    OnPlayerExitVehicleEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnClientEventAttribute))
                {
                    OnClientEventAttribute info = mInfo.GetCustomAttribute<OnClientEventAttribute>();
                    OnClientEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnVehicleSirenToggleAttribute))
                {
                    OnVehicleSirenToggleAttribute info = mInfo.GetCustomAttribute<OnVehicleSirenToggleAttribute>();
                    OnVehicleSirenToggleEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnVehicleDeathAttribute))
                {
                    OnVehicleDeathAttribute info = mInfo.GetCustomAttribute<OnVehicleDeathAttribute>();
                    OnVehicleDeathEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnVehicleHornToggleAttribute))
                {
                    OnVehicleHornToggleAttribute info = mInfo.GetCustomAttribute<OnVehicleHornToggleAttribute>();
                    OnVehicleHornToggleEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnVehicleDoorBreakAttribute))
                {
                    OnVehicleDoorBreakAttribute info = mInfo.GetCustomAttribute<OnVehicleDoorBreakAttribute>();
                    OnVehicleDoorBreakEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnVehicleWindowSmashAttribute))
                {
                    OnVehicleWindowSmashAttribute info = mInfo.GetCustomAttribute<OnVehicleWindowSmashAttribute>();
                    OnVehicleWindowSmashEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnVehicleTyreBurstAttribute))
                {
                    OnVehicleTyreBurstAttribute info = mInfo.GetCustomAttribute<OnVehicleTyreBurstAttribute>();
                    OnVehicleTyreBurstEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnEntityCreatedAttribute))
                {
                    OnEntityCreatedAttribute info = mInfo.GetCustomAttribute<OnEntityCreatedAttribute>();
                    OnEntityCreatedEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnEntityModelChangeAttribute))
                {
                    OnEntityModelChangeAttribute info = mInfo.GetCustomAttribute<OnEntityModelChangeAttribute>();
                    OnEntityModelChangeEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnResourceStartAttribute))
                {
                    OnResourceStartAttribute info = mInfo.GetCustomAttribute<OnResourceStartAttribute>();
                    OnResourceStartEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnResourceStopAttribute))
                {
                    OnResourceStopAttribute info = mInfo.GetCustomAttribute<OnResourceStopAttribute>();
                    OnResourceStopEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnMapChangeAttribute))
                {
                    OnMapChangeAttribute info = mInfo.GetCustomAttribute<OnMapChangeAttribute>();
                    OnMapChangeEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnPlayerExitVehicleAttemptAttribute))
                {
                    OnPlayerExitVehicleAttemptAttribute info = mInfo.GetCustomAttribute<OnPlayerExitVehicleAttemptAttribute>();
                    OnPlayerExitVehicleAttemptEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnPlayerEnterVehicleAttribute))
                {
                    OnPlayerEnterVehicleAttribute info = mInfo.GetCustomAttribute<OnPlayerEnterVehicleAttribute>();
                    OnPlayerEnterVehicleEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnEntityDeletedAttribute))
                {
                    OnEntityDeletedAttribute info = mInfo.GetCustomAttribute<OnEntityDeletedAttribute>();
                    OnEntityDeletedEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnVehicleDamageAttribute))
                {
                    OnVehicleDamageAttribute info = mInfo.GetCustomAttribute<OnVehicleDamageAttribute>();
                    OnVehicleDamageEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
          		else if(typeof(T2) == typeof(OnUpdateAttribute))
                {
                    OnUpdateAttribute info = mInfo.GetCustomAttribute<OnUpdateAttribute>();
                    OnUpdateEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnPlayerEnterVehicleAttemptAttribute))
                {
                    OnPlayerEnterVehicleAttemptAttribute info = mInfo.GetCustomAttribute<OnPlayerEnterVehicleAttemptAttribute>();
                    OnPlayerEnterVehicleAttemptEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnPlayerDetonateStickiesAttribute))
                {
                    OnPlayerDetonateStickiesAttribute info = mInfo.GetCustomAttribute<OnPlayerDetonateStickiesAttribute>();
                    OnPlayerDetonateStickiesEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnPlayerSpawnAttribute))
                {
                    OnPlayerSpawnAttribute info = mInfo.GetCustomAttribute<OnPlayerSpawnAttribute>();
                    OnPlayerSpawnEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnChatMessageAttribute))
                {
                    OnChatMessageAttribute info = mInfo.GetCustomAttribute<OnChatMessageAttribute>();
                    OnChatMessageEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnPlayerConnectedAttribute))
                {
                    OnPlayerConnectedAttribute info = mInfo.GetCustomAttribute<OnPlayerConnectedAttribute>();
                    OnPlayerConnectedEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnPlayerDisconnectedAttribute))
                {
                    OnPlayerDisconnectedAttribute info = mInfo.GetCustomAttribute<OnPlayerDisconnectedAttribute>();
                    OnPlayerDisconnectedEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnPlayerDeathAttribute))
                {
                    OnPlayerDeathAttribute info = mInfo.GetCustomAttribute<OnPlayerDeathAttribute>();
                    OnPlayerDeathEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnPlayerConnectAttribute))
                {
                    OnPlayerConnectAttribute info = mInfo.GetCustomAttribute<OnPlayerConnectAttribute>();
                    OnPlayerConnectEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnPlayerEnterColShapeAttribute))
                {
                    OnPlayerEnterColShapeAttribute info = mInfo.GetCustomAttribute<OnPlayerEnterColShapeAttribute>();
                    OnPlayerEnterColShapeEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnPlayerExitColShapeAttribute))
                {
                    OnPlayerExitColShapeAttribute info = mInfo.GetCustomAttribute<OnPlayerExitColShapeAttribute>();
                    OnPlayerExitColShapeEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnPlayerEnterCheckpointAttribute))
                {
                    OnPlayerEnterCheckpointAttribute info = mInfo.GetCustomAttribute<OnPlayerEnterCheckpointAttribute>();
                    OnPlayerEnterCheckpointEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnPlayerExitCheckpointAttribute))
                {
                    OnPlayerExitCheckpointAttribute info = mInfo.GetCustomAttribute<OnPlayerExitCheckpointAttribute>();
                    OnPlayerExitCheckpointEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnPlayerWeaponSwitchAttribute))
                {
                    OnPlayerWeaponSwitchAttribute info = mInfo.GetCustomAttribute<OnPlayerWeaponSwitchAttribute>();
                    OnPlayerWeaponSwitchEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnPlayerDamageAttribute))
                {
                    OnPlayerDamageAttribute info = mInfo.GetCustomAttribute<OnPlayerDamageAttribute>();
                    OnPlayerDamageEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnPlayerPickupAttribute))
                {
                    OnPlayerPickupAttribute info = mInfo.GetCustomAttribute<OnPlayerPickupAttribute>();
                    OnPlayerPickupEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnVehicleTrailerChangeAttribute))
                {
                    OnVehicleTrailerChangeAttribute info = mInfo.GetCustomAttribute<OnVehicleTrailerChangeAttribute>();
                    OnVehicleTrailerChangeEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
                else if (typeof(T2) == typeof(OnCharacterLoginAttribute))
                {
                    OnCharacterLoginAttribute info = mInfo.GetCustomAttribute<OnCharacterLoginAttribute>();
                    OnCharacterLoginEvent evnt = info.ToEvent(mInfo);
                    dict.Add((T1)Convert.ChangeType(evnt, typeof(T1)), mInfo);
                }
            }
        }
    }

    public class OnClientEvent
    {
        public MethodInfo Method { get; }

        public OnClientEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnCharacterLoginEvent
    {
        public MethodInfo Method { get; }

        public OnCharacterLoginEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnPlayerExitVehicleEvent
    {
        public MethodInfo Method { get; }

        public OnPlayerExitVehicleEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnVehicleSirenToggleEvent
    {
        public MethodInfo Method { get; }

        public OnVehicleSirenToggleEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnVehicleDeathEvent
    {
        public MethodInfo Method { get; }

        public OnVehicleDeathEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnVehicleHornToggleEvent
    {
        public MethodInfo Method { get; }

        public OnVehicleHornToggleEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnVehicleDoorBreakEvent
    {
        public MethodInfo Method { get; }

        public OnVehicleDoorBreakEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnVehicleWindowSmashEvent
    {
        public MethodInfo Method { get; }

        public OnVehicleWindowSmashEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnVehicleTyreBurstEvent
    {
        public MethodInfo Method { get; }

        public OnVehicleTyreBurstEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnEntityCreatedEvent
    {
        public MethodInfo Method { get; }

        public OnEntityCreatedEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnEntityModelChangeEvent
    {
        public MethodInfo Method { get; }

        public OnEntityModelChangeEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnResourceStartEvent
    {
        public MethodInfo Method { get; }

        public OnResourceStartEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnResourceStopEvent
    {
        public MethodInfo Method { get; }

        public OnResourceStopEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnUpdateEvent
    {
        public MethodInfo Method { get; }

        public OnUpdateEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnServerResourceStartEvent
    {
        public MethodInfo Method { get; }

        public OnServerResourceStartEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnServerResourceStopEvent
    {
        public MethodInfo Method { get; }

        public OnServerResourceStopEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnMapChangeEvent
    {
        public MethodInfo Method { get; }

        public OnMapChangeEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnPlayerEnterVehicleEvent
    {
        public MethodInfo Method { get; }

        public OnPlayerEnterVehicleEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnEntityDeletedEvent
    {
        public MethodInfo Method { get; }

        public OnEntityDeletedEvent(MethodInfo method)
        {
            Method = method;
        }
    }
    public class OnVehicleDamageEvent
    {
        public MethodInfo Method { get; }

        public OnVehicleDamageEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnPlayerDetonateStickiesEvent
    {
        public MethodInfo Method { get; }

        public OnPlayerDetonateStickiesEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnPlayerSpawnEvent
    {
        public MethodInfo Method { get; }

        public OnPlayerSpawnEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnChatMessageEvent
    {
        public MethodInfo Method { get; }

        public OnChatMessageEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnPlayerConnectedEvent
    {
        public MethodInfo Method { get; }

        public OnPlayerConnectedEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnPlayerDisconnectedEvent
    {
        public MethodInfo Method { get; }

        public OnPlayerDisconnectedEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnPlayerDeathEvent
    {
        public MethodInfo Method { get; }

        public OnPlayerDeathEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnPlayerConnectEvent
    {
        public MethodInfo Method { get; }

        public OnPlayerConnectEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnPlayerEnterColShapeEvent
    {
        public MethodInfo Method { get; }

        public OnPlayerEnterColShapeEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnPlayerExitColShapeEvent
    {
        public MethodInfo Method { get; }

        public OnPlayerExitColShapeEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnPlayerEnterCheckpointEvent
    {
        public MethodInfo Method { get; }

        public OnPlayerEnterCheckpointEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnPlayerExitCheckpointEvent
    {
        public MethodInfo Method { get; }

        public OnPlayerExitCheckpointEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnPlayerWeaponSwitchEvent
    {
        public MethodInfo Method { get; }

        public OnPlayerWeaponSwitchEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnPlayerDamageEvent
    {
        public MethodInfo Method { get; }

        public OnPlayerDamageEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnPlayerPickupEvent
    {
        public MethodInfo Method { get; }

        public OnPlayerPickupEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnVehicleTrailerChangeEvent
    {
        public MethodInfo Method { get; }

        public OnVehicleTrailerChangeEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnPlayerEnterVehicleAttemptEvent
    {
        public MethodInfo Method { get; }

        public OnPlayerEnterVehicleAttemptEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnPlayerExitVehicleAttemptEvent
    {
        public MethodInfo Method { get; }

        public OnPlayerExitVehicleAttemptEvent(MethodInfo method)
        {
            Method = method;
        }
    }

    public class OnClientEventAttribute : Attribute
    {
        public OnClientEvent ToEvent(MethodInfo method) => new OnClientEvent(method);
    }

    public class OnCharacterLoginAttribute : Attribute
    {
        public OnCharacterLoginEvent ToEvent(MethodInfo method) => new OnCharacterLoginEvent(method);
    }

    public class OnPlayerExitVehicleAttribute : Attribute
    {
        public OnPlayerExitVehicleEvent ToEvent(MethodInfo method) => new OnPlayerExitVehicleEvent(method);
    }

    public class OnVehicleSirenToggleAttribute : Attribute
    {
        public OnVehicleSirenToggleEvent ToEvent(MethodInfo method) => new OnVehicleSirenToggleEvent(method);
    }

    public class OnVehicleDeathAttribute : Attribute
    {
        public OnVehicleDeathEvent ToEvent(MethodInfo method) => new OnVehicleDeathEvent(method);
    }

    public class OnVehicleHornToggleAttribute : Attribute
    {
        public OnVehicleHornToggleEvent ToEvent(MethodInfo method) => new OnVehicleHornToggleEvent(method);
    }

    public class OnVehicleDoorBreakAttribute : Attribute
    {
        public OnVehicleDoorBreakEvent ToEvent(MethodInfo method) => new OnVehicleDoorBreakEvent(method);
    }

    public class OnVehicleWindowSmashAttribute : Attribute
    {
        public OnVehicleWindowSmashEvent ToEvent(MethodInfo method) => new OnVehicleWindowSmashEvent(method);
    }

    public class OnVehicleTyreBurstAttribute : Attribute
    {
        public OnVehicleTyreBurstEvent ToEvent(MethodInfo method) => new OnVehicleTyreBurstEvent(method);
    }

    public class OnEntityCreatedAttribute : Attribute
    {
        public OnEntityCreatedEvent ToEvent(MethodInfo method) => new OnEntityCreatedEvent(method);
    }

    public class OnEntityModelChangeAttribute : Attribute
    {
        public OnEntityModelChangeEvent ToEvent(MethodInfo method) => new OnEntityModelChangeEvent(method);
    }

    public class OnResourceStartAttribute : Attribute
    {
        public OnResourceStartEvent ToEvent(MethodInfo method) => new OnResourceStartEvent(method);
    }

    public class OnResourceStopAttribute : Attribute
    {
        public OnResourceStopEvent ToEvent(MethodInfo method) => new OnResourceStopEvent(method);
    }

    public class OnUpdateAttribute : Attribute
    {
        public OnUpdateEvent ToEvent(MethodInfo method) => new OnUpdateEvent(method);
    }

    public class OnServerResourceStartAttribute : Attribute
    {
        public OnServerResourceStartEvent ToEvent(MethodInfo method) => new OnServerResourceStartEvent(method);
    }

    public class OnServerResourceStopAttribute : Attribute
    {
        public OnServerResourceStopEvent ToEvent(MethodInfo method) => new OnServerResourceStopEvent(method);
    }

    public class OnMapChangeAttribute : Attribute
    {
        public OnMapChangeEvent ToEvent(MethodInfo method) => new OnMapChangeEvent(method);
    }

    public class OnPlayerEnterVehicleAttribute : Attribute
    {
        public OnPlayerEnterVehicleEvent ToEvent(MethodInfo method) => new OnPlayerEnterVehicleEvent(method);
    }

    public class OnEntityDeletedAttribute : Attribute
    {
        public OnEntityDeletedEvent ToEvent(MethodInfo method) => new OnEntityDeletedEvent(method);
    }

    public class OnVehicleDamageAttribute : Attribute
    {
        public OnVehicleDamageEvent ToEvent(MethodInfo method) => new OnVehicleDamageEvent(method);
    }

    public class OnPlayerDetonateStickiesAttribute : Attribute
    {
        public OnPlayerDetonateStickiesEvent ToEvent(MethodInfo method) => new OnPlayerDetonateStickiesEvent(method);
    }

    public class OnPlayerSpawnAttribute : Attribute
    {
        public OnPlayerSpawnEvent ToEvent(MethodInfo method) => new OnPlayerSpawnEvent(method);
    }

    public class OnChatMessageAttribute : Attribute
    {
        public OnChatMessageEvent ToEvent(MethodInfo method) => new OnChatMessageEvent(method);
    }

    public class OnPlayerConnectedAttribute : Attribute
    {
        public OnPlayerConnectedEvent ToEvent(MethodInfo method) => new OnPlayerConnectedEvent(method);
    }

    public class OnPlayerDisconnectedAttribute : Attribute
    {
        public OnPlayerDisconnectedEvent ToEvent(MethodInfo method) => new OnPlayerDisconnectedEvent(method);
    }

    public class OnPlayerDeathAttribute : Attribute
    {
        public OnPlayerDeathEvent ToEvent(MethodInfo method) => new OnPlayerDeathEvent(method);
    }

    public class OnPlayerConnectAttribute : Attribute
    {
        public OnPlayerConnectEvent ToEvent(MethodInfo method) => new OnPlayerConnectEvent(method);
    }

    public class OnPlayerEnterColShapeAttribute : Attribute
    {
        public OnPlayerEnterColShapeEvent ToEvent(MethodInfo method) => new OnPlayerEnterColShapeEvent(method);
    }

    public class OnPlayerExitColShapeAttribute : Attribute
    {
        public OnPlayerExitColShapeEvent ToEvent(MethodInfo method) => new OnPlayerExitColShapeEvent(method);
    }

    public class OnPlayerEnterCheckpointAttribute : Attribute
    {
        public OnPlayerEnterCheckpointEvent ToEvent(MethodInfo method) => new OnPlayerEnterCheckpointEvent(method);
    }

    public class OnPlayerExitCheckpointAttribute : Attribute
    {
        public OnPlayerExitCheckpointEvent ToEvent(MethodInfo method) => new OnPlayerExitCheckpointEvent(method);
    }

    public class OnPlayerWeaponSwitchAttribute : Attribute
    {
        public OnPlayerWeaponSwitchEvent ToEvent(MethodInfo method) => new OnPlayerWeaponSwitchEvent(method);
    }

    public class OnPlayerDamageAttribute : Attribute
    {
        public OnPlayerDamageEvent ToEvent(MethodInfo method) => new OnPlayerDamageEvent(method);
    }

    public class OnPlayerPickupAttribute : Attribute
    {
        public OnPlayerPickupEvent ToEvent(MethodInfo method) => new OnPlayerPickupEvent(method);
    }

    public class OnVehicleTrailerChangeAttribute : Attribute
    {
        public OnVehicleTrailerChangeEvent ToEvent(MethodInfo method) => new OnVehicleTrailerChangeEvent(method);
    }

    public class OnPlayerEnterVehicleAttemptAttribute : Attribute
    {
        public OnPlayerEnterVehicleAttemptEvent ToEvent(MethodInfo method) => new OnPlayerEnterVehicleAttemptEvent(method);
    }

    public class OnPlayerExitVehicleAttemptAttribute : Attribute
    {
        public OnPlayerExitVehicleAttemptEvent ToEvent(MethodInfo method) => new OnPlayerExitVehicleAttemptEvent(method);
    }
}

 

 

Edited by notsosmart

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.