public void AddRemove() { var events = new EventHandlers<String>(this); Boolean firstAdded = events.Add<AEventArgs>("a", AEventHandler); Assert.IsTrue(firstAdded); firstAdded = events.Add<AEventArgs>("a", AEventHandler); Assert.IsFalse(firstAdded); firstAdded = events.Add<BEventArgs>("b", BEventHandler); Assert.IsTrue(firstAdded); firstAdded = events.Add<BEventArgs>("b", BEventHandler); Assert.IsFalse(firstAdded); Boolean lastRemoved = events.Remove<BEventArgs>("b", BEventHandler); Assert.IsFalse(lastRemoved); lastRemoved = events.Remove<BEventArgs>("b", BEventHandler); Assert.IsTrue(lastRemoved); lastRemoved = events.Remove<AEventArgs>("a", AEventHandler); Assert.IsFalse(lastRemoved); lastRemoved = events.Remove<AEventArgs>("a", AEventHandler); Assert.IsTrue(lastRemoved); }
public void Contravariance() { var events = new EventHandlers<String>(this); Boolean firstAdded = events.Add<AEventArgs>("v", AEventHandler); Assert.IsTrue(firstAdded); firstAdded = events.Add<AEventArgs>("v", AEventHandler); Assert.IsFalse(firstAdded); var e = new BEventArgs(); events.Raise("v", e); Assert.IsTrue(e.Handled); }
public Checkpoint() { Tick += CheckpointTick; EventHandlers.Add("ARP:OnPlayerExitCheckpoint", new Action <int, string>(OnPlayerExitCheckpoint)); EventHandlers.Add("ARP:OnPlayerEnterCheckpoint", new Action <int, string>(OnPlayerEnterCheckpoint)); }
public ScriptServer() { // Register our events, all of them Tick += OnTickCheckStart; EventHandlers.Add("ggo:onPlayerSpawnHUB", new Action <Player>(OnPlayerSpawnHUB)); EventHandlers.Add("playerDropped", new Action <Player, string>(OnPlayerDropped)); }
public void On(string eventName, EventHandler handler) { if (!EventHandlers.ContainsKey(eventName)) { EventHandlers.Add(eventName, handler); } }
protected void AddEvent(string eventKey, Action <UIEvent> handler) { if (!EventHandlers.ContainsKey(eventKey)) { EventHandlers.Add(eventKey, handler); } }
public ClientScript() { // Events EventHandlers.Add("startcpr", new Action <int, int>(revive)); // Commands API.RegisterCommand("cpr", new Action <int, List <object>, string>(cprCommand), false); }
public void RegisterEventHandler <THandler>() where THandler : IIntegrationEventHandler { var type = typeof(THandler); EventHandlers.Add(type); }
public Ping_FPS__Checker() { string resource_name = API.GetCurrentResourceName(); string resource_author = "MasterZyper"; Debug.Write($"{resource_name} by {resource_author} started"); try { cmd_show_fps = API.GetResourceMetadata(resource_name, "cmd_show_fps", 0); display_x = Convert.ToSingle(API.GetResourceMetadata(resource_name, "ui_display_x", 0)); display_y = Convert.ToSingle(API.GetResourceMetadata(resource_name, "ui_display_y", 0)); text_offset = Convert.ToSingle(API.GetResourceMetadata(resource_name, "ui_text_offset", 0)); text_size = Convert.ToSingle(API.GetResourceMetadata(resource_name, "ui_text_size", 0)); } catch (Exception) { Debug.Write($"Error while loading {resource_name} "); } EventHandlers.Add("MZ:RequestPlayerFPS", new Action <bool>(RequestPlayerFPS)); EventHandlers.Add("MZ:SendCurrentConectionInfos", new Action <List <dynamic> >(SendCurrentConectionInfos)); Tick += DrawPlayerInfos; API.RegisterCommand(cmd_show_fps, new Action <int, List <object>, string>(async(player, value, raw) => { show_fps = !show_fps; }), false); }
public PickupManager() { RegisterCommand("dropmoney", new Action <int, List <object>, string>((source, args, raw) => { int MaxPickups; int MoneyAmount = int.Parse(args[0].ToString()); try { MaxPickups = int.Parse(config["MaxPickupCount"].ToString()); } catch (Exception e) { MaxPickups = 3; } if (ActivePickups.Count < MaxPickups) { if (MoneyAmount < 20000) { TriggerServerEvent("rFramework:VerifyDropMoney", MoneyAmount, CashPickup, 0); } else { TriggerServerEvent("rFramework:VerifyDropMoney", MoneyAmount, CasePickup, 0); } } else { bool removed = false; foreach (Prop p in ActivePickups) { if (!p.Exists()) { ActivePickups.Remove(p); removed = true; break; } } if (removed) { if (MoneyAmount < 20000) { TriggerServerEvent("rFramework:VerifyDropMoney", MoneyAmount, CashPickup, 0); } else { TriggerServerEvent("rFramework:VerifyDropMoney", MoneyAmount, CasePickup, 0); } } else { SetNotificationTextEntry("STRING"); AddTextComponentString("Max Pickup Count Met"); DrawNotification(true, false); } } }), false); EventHandlers.Add("gameEventTriggered", new Action <string, List <dynamic> >(OnGameEventTriggered)); EventHandlers.Add("rFramework:CreatePickup", new Action <int, long, string>(DropPickup)); }
public Chat() { //Tick += ChatTimer; //OnLoad(); EventHandlers.Add("chatMessageCallback", new Action <string, string>(ChatMessageCallback)); EventHandlers.Add("ARP:SendRadiusMessageToClient", new Action <string, string, float, float, float, bool>(SendRadiusMessageToClient)); }
public Main() { EventHandlers.Add("911:AddBlipToMap", new Action <Vector3, string, int>(AddBlipToMap)); RegisterCommand("911", new Action <int, List <dynamic>, string>((source, args, rawCommand) => { if (!callActive) { string name = Game.Player.Name; string msg = string.Join(" ", args); Vector3 coords = GetEntityCoords(Game.PlayerPed.Handle, true); string location = World.GetStreetName(coords); TriggerServerEvent("911:SendMessage", coords, name, location, msg); } else { TriggerEvent("chatMessage", "You have a call currently active please wait."); } }), false); TriggerEvent("chat:addSuggestion", "/911", "Call for emergency services", new[] { new { name = "Report", help = "Enter your report here" } }); }
public Flatbed() { PP = Game.PlayerPed; LV = Game.PlayerPed.LastVehicle; DecorRegister(modDecor, 2); DecorRegister(towVehDecor, 3); DecorRegister(lastFbVehDecor, 3); DecorRegister(helpDecor, 2); DecorRegister(gHeightDecor, 1); DecorRegister(scoopDecor, 1); EventHandlers.Add("flatbed:AddRope", new Action <int, int, int>(WorldAddRope)); EventHandlers.Add("flatbed:SetTowingVehicle", new Action <int, int, int>(SetTowingVehicle)); EventHandlers.Add("flatbed:SendFlatbedVehicles", new Action <List <FlatbedData> >(SendFlatbedVehicles)); LoadSettings(); //LoadVehicles(); TriggerServerEvent("flatbed:SendFlatbedVehicles"); RegisterCommand("stopwinch", new Action <int, List <object>, string>((src, args, raw) => { ES = true; }), false); RegisterCommand("unfreezeflatbed", new Action <int, List <object>, string>((src, args, raw) => { FreezeEntityPosition(LF.Handle, false); }), false); Tick += OnTick; Tick += OnTick2; }
private void BindEvents() { EventHandlers .Add <IncomeCreated>(this) .Add <IncomeDeleted>(this) .Add <PulledToRefresh>(this); }
protected override void OnInitialized() { base.OnInitialized(); Navigator.LocationChanged += OnLocationChanged; EventHandlers.Add <UserSignedOut>(this); }
public MainServer() { if (GetCurrentResourceName() != "zBounties") { Exception invalidNameException = new Exception("[zBounties] Installation Error:\r\nThe name of the resource is invalid. " + "Please change the folder name from '^3" + GetCurrentResourceName() + "^1' to ^2'zBounties' (case sensitive) and restart the resource.\r\n\r\n\r\n^7"); try { throw invalidNameException; } catch (Exception e) { Debug.Write(e.Message); } } else { Config.Initialize(); Debug.WriteLine("zBounties Started!"); Tick += PopulatePlayerList; EventHandlers.Add("zBounties:setPlayerBounty", new Action <Player, int>(ServerHandler.SetBountyForPlayer)); EventHandlers.Add("zBounties:requestBountyData", new Action <Player>(ServerHandler.RequestBountyData)); EventHandlers.Add("zBounties:resetBounty", new Action <Player>(ServerHandler.ResetBounty)); ServerHandler.InitializeOnlinePlayers(); } }
public MapBuilderClient() : base() { _accessor = this; FreecamConfig config = new FreecamConfig { FieldOfView = 75, PositionSensitivity = 1.0f, PositionBase = 100.0f, RotationSensitivity = 1.0f, RotationBase = 500.0f, KeySmoothTime = 500, }; input = locator.CreateService <Input>(); //@TODO(bma) #state-manager: Move this to #move-toggle-to-class. input.RegisterKey(0, 37, InputKeyType.Once); input.RegisterKey(0, 261, InputKeyType.Once); input.RegisterKey(0, 262, InputKeyType.Once); freeCam = locator.CreateService <Freecam>(config); ui = locator.CreateService <UserInterface>(); builder = locator.CreateService <Builder>(); EventHandlers.Add("onResourceStop", new Action <string>(OnResourceStopped)); }
/// <summary> /// Constructor. /// </summary> public EventManager() { if (GetCurrentResourceName() != "vMenu") { Exception InvalidNameException = new Exception("\r\n\r\n[vMenu] INSTALLATION ERROR!\r\nThe name of the resource is not valid. Please change the folder name from '" + GetCurrentResourceName() + "' to 'vMenu' (case sensitive) instead!\r\n\r\n\r\n"); try { throw InvalidNameException; } catch (Exception e) { Debug.Write(e.Message); } } else { // Add event handlers. EventHandlers.Add("vMenu:SummonPlayer", new Action <Player, int>(SummonPlayer)); EventHandlers.Add("vMenu:KillPlayer", new Action <Player, int>(KillPlayer)); EventHandlers.Add("vMenu:KickPlayer", new Action <Player, int, string>(KickPlayer)); EventHandlers.Add("vMenu:RequestPermissions", new Action <Player>(SendPermissionsAsync)); EventHandlers.Add("vMenu:UpdateServerWeather", new Action <string, bool, bool>(UpdateWeather)); EventHandlers.Add("vMenu:UpdateServerWeatherCloudsType", new Action <bool>(UpdateWeatherCloudsType)); EventHandlers.Add("vMenu:UpdateServerTime", new Action <int, int, bool>(UpdateTime)); Tick += WeatherLoop; Tick += TimeLoop; } }
public Taxi() { EventHandlers.Add("ARP:AcceptTaxi", new Action <string>(AcceptTaxi)); EventHandlers.Add("ARP:GetTaxi", new Action(GetTaxi)); EventHandlers.Add("ARP:SendNotifTaxi", new Action <string, int, string, string, float, float, float>(SendNotifTaxi)); Tick += SecTimer; }
/// <summary> /// Constructor. /// </summary> public EventManager() { // Add event handlers. EventHandlers.Add("vMenu:SetAddons", new Action(SetAddons)); EventHandlers.Add("vMenu:SetPermissions", new Action <string>(MainMenu.SetPermissions)); EventHandlers.Add("vMenu:GoToPlayer", new Action <string>(SummonPlayer)); EventHandlers.Add("vMenu:KillMe", new Action <string>(KillMe)); EventHandlers.Add("vMenu:Notify", new Action <string>(NotifyPlayer)); EventHandlers.Add("vMenu:SetClouds", new Action <float, string>(SetClouds)); EventHandlers.Add("vMenu:GoodBye", new Action(GoodBye)); EventHandlers.Add("vMenu:SetBanList", new Action <string>(UpdateBanList)); EventHandlers.Add("vMenu:ClearArea", new Action <float, float, float>(ClearAreaNearPos)); EventHandlers.Add("vMenu:updatePedDecors", new Action(UpdatePedDecors)); EventHandlers.Add("playerSpawned", new Action(SetAppearanceOnFirstSpawn)); EventHandlers.Add("vMenu:GetOutOfCar", new Action <int, int>(GetOutOfCar)); EventHandlers.Add("vMenu:PrivateMessage", new Action <string, string>(PrivateMessage)); EventHandlers.Add("vMenu:UpdateTeleportLocations", new Action <string>(UpdateTeleportLocations)); if (GetSettingsBool(Setting.vmenu_enable_weather_sync)) { Tick += WeatherSync; } if (GetSettingsBool(Setting.vmenu_enable_time_sync)) { Tick += TimeSync; } RegisterNuiCallbackType("disableImportExportNUI"); RegisterNuiCallbackType("importData"); }
public Ping_FPS_Checker() { string resource_name = API.GetCurrentResourceName(); string resource_author = "MasterZyper"; Debug.Write($"{resource_name} by {resource_author} started"); try { highest_ping = Convert.ToInt32(API.GetResourceMetadata(resource_name, "highest_ping", 0)); ping_attemps = Convert.ToInt32(API.GetResourceMetadata(resource_name, "ping_attemps", 0)); fps_attemps = Convert.ToInt32(API.GetResourceMetadata(resource_name, "fps_attemps", 0)); lowest_fps = Convert.ToInt32(API.GetResourceMetadata(resource_name, "lowest_fps", 0)); lg_kicked_high_ping = API.GetResourceMetadata(resource_name, "lg_kicked_high_ping", 0); lg_kicked_low_fps = API.GetResourceMetadata(resource_name, "lowest_fps", 0); lg_kicked_slow_response_time = API.GetResourceMetadata(resource_name, "lg_kicked_slow_response_time", 0); } catch (Exception) { Debug.Write($"Error while loading {resource_name} "); } Tick += CheckPing; Tick += SendConnectionInfos; EventHandlers.Add("MZ:SendCurrentFPSToServer", new Action <Player, float>(SendCurrentFPSToServer)); EventHandlers.Add("MZ:ClientConnectionComplete", new Action <Player, bool>(ClientConnectionComplete)); }
protected void RegisterEvent <T1, T2>(string msg, Action <T1, T2> callback) { List <int> sources = new List <int>(); foreach (var param in callback.Method.GetParameters()) { foreach (var attr in param.CustomAttributes) { if (param.ParameterType == typeof(Player) && attr.AttributeType == typeof(FromSourceAttribute)) { sources.Add(callback.Method.GetParameters().ToList().IndexOf(param)); } } } EventHandlers.Add(msg, new Action <dynamic, dynamic>((body1, body2) => { dynamic arg1 = sources.Contains(0) ? new PlayerList()[body1.GetType() == typeof(string) ? Int32.Parse(body1) : body1] : JsonConvert.DeserializeObject <T1>(body1); dynamic arg2 = sources.Contains(1) ? new PlayerList()[body2.GetType() == typeof(string) ? Int32.Parse(body2) : body2] : JsonConvert.DeserializeObject <T2>(body2); callback.Invoke(arg1, arg2); })); }
public Main() { //Register Commands for Server Action API.RegisterCommand("+panicbutton", new Action <int, List <object>, string>((source, arguments, raw) => { TriggerServerEvent("PanicButton:GetInformation"); }), false); API.RegisterCommand("clearpb", new Action <int, List <object>, string>((source, arguments, raw) => { TriggerServerEvent("PanicButton:ClearPanicButtonSend"); }), false); //Create Event EventHandlers.Add("PanicButton:SendInformation", new Action <int, string, Vector3>(OnSendVariable)); EventHandlers.Add("PanicButton:AlreadyActive", new Action(PBAlreadyActive)); EventHandlers.Add("PanicButton:ClearPanicButtonResult", new Action <string>(ClearPB)); //Create Basic Commands API.RegisterCommand("activeLeo", new Action(SetLEO), false); //Tick Tick += OnTick; Tick += DrawDetails; //Log Messages Debug.WriteLine("PanicButton has loaded"); }
public MainServer() { EventHandlers.Add("npcspawner:onPlayerLoaded", new Action <Player>(OnPlayerLoaded)); EventHandlers.Add("npcspawner:onPositionUpdate", new Action <Player, dynamic>(OnPositionUpdate)); Initialize(); }
public EssentialClient() { Debug.WriteLine($"Client Script Initiated for player {GetPlayerServerId(-1)}"); //events EventHandlers["onClientResourceStart"] += new Action <string>(OnClientResourceStart); EventHandlers["playerSpawned"] += new Action(SpawnInitialize); EventHandlers.Add("GiveAllGuns", new Action(GiveAllGuns)); EventHandlers.Add("SpawnVehicle", new Action <string>(SpawnVehicle)); EventHandlers.Add("Teleport", new Action(TeleportPlayer)); EventHandlers.Add("Emote", new Action <string>(UseEmote)); EventHandlers.Add("Animate", new Action <string>(UseAnimation)); EventHandlers.Add("CancelEmoteNow", new Action(CancelEmoteNow)); EventHandlers.Add("CancelAnimationNow", new Action(CancelAnimation)); EventHandlers.Add("GetLoadedPlayer", new Action(GetLoadedPlayer)); EventHandlers.Add("SetPlayer", new Action <int, string>(SetPlayer)); EventHandlers.Add("BankUI", new Action <bool>(EnableBankingUI)); EventHandlers.Add("SetPlayerBalance", new Action <int, int>(SetPlayerBalance)); EventHandlers.Add("BalanceChange", new Action <string, int>(BalanceChange)); EventHandlers.Add("PlayerListUI", new Action <bool, string>(EnablePlayerListGUI)); EventHandlers.Add("SetModel", new Action <string>(SetModel)); //register callbacks RegisterNUICallback("escapebalance", EscapeBalanceUI); RegisterNUICallback("escapeplayerlist", EscapePlayerListUI); //configuration Initialize(); //Ticks Tick += OnTick; }
protected override void OnInitialized() { base.OnInitialized(); Client = typeof(AppVersion).Assembly.GetName().Version; EventHandlers.Add <ApiVersionChanged>(this); }
//private List<int> TrainNetworkHandles { get; set; } = new List<int>() { 0, 0, 0, 0 }; /// <summary> /// Constructor, adds 2 event handlers. /// </summary> public Main() { //EventHandlers.Add(GetCurrentResourceName() + ":SetTrainNetHandle", new Action<Player, List<dynamic>>(SetTrain)); //EventHandlers.Add(GetCurrentResourceName() + ":RequestTrainNetworkHandle", new Action<Player>(GetTrain)); EventHandlers.Add(GetCurrentResourceName() + ":SetTrainNetHandle", new Action <Player>(SetTrain)); EventHandlers.Add(GetCurrentResourceName() + ":RequestTrainNetworkHandle", new Action <Player>(GetTrain)); }
public XikeonBrClient() { Debug.WriteLine("XikeonBrClient initialized"); sync = new XikeonBrShared.Sync(OnSyncPropertyChange); sync.Notify = OnSyncNotify; baseEvents = new BaseEvents(); Tick += baseEvents.OnTick; Tick += baseEvents.CountDownTick; spawnManager = new SpawnManager(); Tick += spawnManager.OnTick; EventHandlers.Add("getMapDirectives", new Action <CallbackDelegate>(spawnManager.OnGetMapDirectives)); inventoryManager = new InventoryManager(); Tick += inventoryManager.OnTick; Tick += OnTick; EventHandlers.Add("onClientMapStart", new Action <string>(OnClientMapStart)); EventHandlers.Add("sendMotd", new Action <string>(ReceivedMotd)); EventHandlers.Add("playerSpawned", new Action <Player, Object, CallbackDelegate>(OnPlayerSpawned)); EventHandlers.Add("xbr:showNotification", new Action <string>(Notification.OnNotification)); EventHandlers.Add("xbr:showNotificationDetails", new Action <string, string, string, string>(Notification.OnNotificationDetails)); EventHandlers.Add("xbr:showNotificationDetailsPlayer", new Action <ExpandoObject, string, string, string, string>(Notification.OnNotificationDetails)); EventHandlers.Add("xbr:setTime", new Action <int, int, int>(OnSetTime)); EventHandlers.Add("xbr:freezePlayer", new Action <int, bool>(OnFreezePlayer)); EventHandlers.Add("xbr:playerRestart", new Action(OnPlayerRestart)); EventHandlers.Add("xbr:countdown", new Action <int>(OnCountdown)); EventHandlers.Add("xbr:sync", new Action <string, string, dynamic>(sync.HandleSyncEvent)); // EventHandlers.Add("xbr:onPlayerDied", new Action<int, double, double, double>(OnPlayerDied)); }
// Initial BaseScript Call public Server() { EventHandlers.Add("ExtractionSaw:GetInitializedData", new Action <Player>(GetInitializedData)); EventHandlers.Add("ExtractionSaw:StartSawCutSync", new Action <Player, int>(StartSawCutSync)); EventHandlers.Add("ExtractionSaw:StopSawCutSync", new Action <Player, int>(StopSawCutSync)); EventHandlers.Add("ExtractionSaw:SyncDoorCut", new Action <Player, List <object>, int>(SyncDoorCut)); }
public Data() { EventHandlers.Add("Sync:Client:Data:Get", new Action <object>(GetServer)); EventHandlers.Add("Sync:Client:Data:GetAll", new Action <dynamic>(GetAllServer)); EventHandlers.Add("Sync:Client:Data:Has", new Action <bool>(HasServer)); Exports.Add("client_sync_data_enable_debug", new Action <bool, CallbackDelegate>((enableDebug, callback) => { Debug = enableDebug; })); Exports.Add("client_sync_data_set", new Action <int, string, object>(Set)); Exports.Add("client_sync_data_reset", new Action <int, string>(Reset)); Exports.Add("client_sync_data_get", new Func <int, string, Task <object> >(async(id, key) => await Get(id, key))); Exports.Add("client_sync_data_getall", new Func <int, Task <object> >(async id => await GetAll(id))); Exports.Add("client_sync_data_has", new Func <int, string, Task <bool> >(async(id, key) => await Has(id, key))); Exports.Add("client_sync_data_set_locally", new Action <int, string, object>(SetLocally)); Exports.Add("client_sync_data_reset_locally", new Action <int, string>(ResetLocally)); Exports.Add("client_sync_data_get_locally", new Func <int, string, object>(GetLocally)); Exports.Add("client_sync_data_getall_locally", new Func <int, object>(GetAllKeyLocally)); Exports.Add("client_sync_data_has_locally", new Func <int, string, bool>(HasLocally)); TriggerEvent("OnClientSyncDataLoaded", CitizenFX.Core.Native.API.GetCurrentResourceName()); }
protected void RegisterEvent(string msg, Action callback) { EventHandlers.Add(msg, new Action(() => { callback.Invoke(); })); }
protected void RegisterEvent <T1, T2, T3, T4, T5>(string msg, Action <T1, T2, T3, T4, T5> callback) { EventHandlers.Add(msg, new Action <dynamic, dynamic, dynamic, dynamic, dynamic>((body1, body2, body3, body4, body5) => { if (!(body1 is string)) { body1 = JsonConvert.SerializeObject(body1); } if (!(body2 is string)) { body2 = JsonConvert.SerializeObject(body2); } if (!(body3 is string)) { body3 = JsonConvert.SerializeObject(body3); } if (!(body4 is string)) { body4 = JsonConvert.SerializeObject(body4); } if (!(body5 is string)) { body5 = JsonConvert.SerializeObject(body5); } var response1 = JsonConvert.DeserializeObject <T1>(body1); var response2 = JsonConvert.DeserializeObject <T2>(body2); var response3 = JsonConvert.DeserializeObject <T3>(body3); var response4 = JsonConvert.DeserializeObject <T4>(body4); var response5 = JsonConvert.DeserializeObject <T5>(body5); callback.Invoke(response1, response2, response3, response4, response5); })); }
public void UnknownEventArgs() { var events = new EventHandlers<String>(this); Boolean firstAdded = events.Add<AEventArgs>("v", AEventHandler); Assert.IsTrue(firstAdded); firstAdded = events.Add<AEventArgs>("v", AEventHandler); Assert.IsFalse(firstAdded); EventArgs e = new AEventArgs(); events.Raise("v", e); Assert.IsTrue(((AEventArgs)e).Handled); e = new BEventArgs(); events.Raise("v", e); Assert.IsTrue(((BEventArgs)e).Handled); }