public override void Begin() { Atlas.AttachNuiHandler("MENU_DIALOG_UPDATE", new EventCallback(metadata => { if (MenuContext?.Profile != null && MenuContext.Profile.GetType() == typeof(MenuProfileDialog)) { ((MenuProfileDialog)MenuContext.Profile).Value = metadata.Find <string>(0); } return(null); })); Atlas.AttachNuiHandler("MENU_DIALOG_SELECT", new EventCallback(metadata => { if (MenuContext?.Profile == null || MenuContext.Profile.GetType() != typeof(MenuProfileDialog)) { return(null); } var operation = new MenuOperation { Type = MenuOperationType.Select }; MenuContext.Callback?.Invoke(MenuContext, null, operation); return(null); })); }
public override void Begin() { Atlas.AttachNuiHandler("CREATE_CHAR", new AsyncEventCallback(async metadata => { var firstname = metadata.Find <string>(0); var surname = metadata.Find <string>(1); var dateofbirth = metadata.Find <string>(2); var character = await EventSystem.Request <AtlasCharacter>("characters:create", firstname, surname, dateofbirth); AvailableCharacters.Add(character); API.SetNuiFocus(true, true); API.SendNuiMessage(new JsonBuilder().Add("Operation", "LOAD_CHARACTERS") .Add("Characters", AvailableCharacters).Build()); return(null); })); Atlas.AttachNuiHandler("DELETE_CHAR", new EventCallback(metadata => { var seed = metadata.Find <string>(0); EventSystem.Send("characters:delete", seed); AvailableCharacters.RemoveAll(self => self.Seed == seed); return(null); })); Atlas.AttachNuiHandler("SELECT_CHAR", new AsyncEventCallback(async metadata => { var seed = metadata.Find <string>(0); var character = AvailableCharacters.FirstOrDefault(self => self.Seed == seed); if (character != null) { Atlas.Local.Character = character; API.SetNuiFocus(false, false); API.SendNuiMessage(new JsonBuilder().Add("Operation", "CLOSE_CHARACTERS").Build()); await Load(Atlas.Local); } else { Logger.Info("[Characters] Cannot select a character that isn't yours."); } return(null); })); }
public override void Begin() { StateChanged += state => { Logger.Debug(state == InventoryStateChange.Show ? "[Inventory] Opening inventory..." : "[Inventory] Closed inventory."); }; Atlas.AttachNuiHandler("CLOSE_INVENTORY", new EventCallback(metadata => { OpenedInventory = false; if (StateChanged != null) { foreach (var invocation in StateChanged?.GetInvocationList()) { ((Action <InventoryStateChange>)invocation).Invoke(InventoryStateChange.Hide); } } API.SetNuiFocus(false, false); return(null); })); Atlas.AttachNuiHandler("INVENTORY_ITEM_CHANGE", new EventCallback(metadata => { var source = GetContainer(metadata.Find <string>(0)); var sourceItem = JsonConvert.DeserializeObject <InventoryItem>(metadata.Find <string>(1)); source.CallUpdate(source.Slots[sourceItem.Slot], InventoryUpdateType.Remove); source.Slots[sourceItem.Slot] = sourceItem; source.CallUpdate(sourceItem, InventoryUpdateType.Add); var target = GetContainer(metadata.Find <string>(2)); var targetItem = JsonConvert.DeserializeObject <InventoryItem>(metadata.Find <string>(3)); target.CallUpdate(target.Slots[targetItem.Slot], InventoryUpdateType.Remove); target.Slots[targetItem.Slot] = targetItem; target.CallUpdate(targetItem, InventoryUpdateType.Add); UpdateInventory(source); UpdateInventory(target); return(null); })); }
public override void Begin() { Atlas.AttachNuiHandler("INVENTORY_ITEM_USE", new EventCallback(metadata => { var item = JsonConvert.DeserializeObject <InventoryItem>(metadata.Find <string>(0)); // More complex solution to this later, like registering through a class or something like that rather than having everything here. if (item.Name == "bandage") { Cache.Entity.Health += 75; Cache.Player.Sound.PlayFrontend("Bus_Schedule_Pickup", "DLC_PRISON_BREAK_HEIST_SOUNDS"); ItemHelper.Remove(item); } return(null); })); }
public override void Begin() { EventSystem.Attach("job:employee:hired", new AsyncEventCallback(async metadata => { var seed = metadata.Find <string>(0); var character = CharacterManager.GetModule().AvailableCharacters.First(self => self.Seed == seed); if (Cache.Character.Seed == character.Seed) { Cache.Player.ShowNotification($"Du har blivit anställd hos {metadata.Find<string>(2)}!"); } Enum.TryParse <Employment>(metadata.Find <string>(1), out var employment); character.Metadata.Employment = employment; character.Metadata.EmploymentRole = 0; await character.Save(); return(null); })); EventSystem.Attach("job:employee:kicked", new AsyncEventCallback(async metadata => { var seed = metadata.Find <string>(0); var character = CharacterManager.GetModule().AvailableCharacters.First(self => self.Seed == seed); if (Cache.Character.Seed == character.Seed) { Cache.Player.ShowNotification("Du blev sparkad ifrån ditt jobb!"); } character.Metadata.Employment = Employment.Unemployed; character.Metadata.EmploymentRole = 0; await character.Save(); return(null); })); EventSystem.Attach("job:employment:update", new AsyncEventCallback(async metadata => { var seed = metadata.Find <string>(0); var character = CharacterManager.GetModule().AvailableCharacters.First(self => self.Seed == seed); character.Metadata.EmploymentRole = metadata.Find <int>(1); await character.Save(); return(null); })); Atlas.AttachNuiHandler("CLOSE_JOB_PANEL", new EventCallback(metadata => { API.SetNuiFocus(false, false); return(null); })); Atlas.AttachNuiHandler("KICK_EMPLOYEE", new AsyncEventCallback(async metadata => { var atlas = AtlasPlugin.Instance; var character = await EventSystem.Request <AtlasCharacter>("characters:fetchbyseed", metadata.Find <string>(0)); if (character == null) { return(null); } var user = await EventSystem.Request <AtlasUser>("user:fetch", character.Owner); if (user != null) { user.Send("job:employee:kicked", character.Seed); } else { character.Metadata.Employment = Employment.Unemployed; character.Metadata.EmploymentRole = 0; await character.Save(); } return(null); })); Atlas.AttachNuiHandler("EMPLOYEE_UPDATE", new AsyncEventCallback(async metadata => { var atlas = AtlasPlugin.Instance; var character = await EventSystem.Request <AtlasCharacter>("characters:fetchbyseed", metadata.Find <string>(0)); if (character == null) { return(null); } var user = await EventSystem.Request <AtlasUser>("user:fetch", character.Owner); if (user != null) { user.Send("job:employment:update", character.Seed, metadata.Find <int>(1)); } else { character.Metadata.EmploymentRole = metadata.Find <int>(1); await character.Save(); } return(null); })); Atlas.AttachNuiHandler("EMPLOYEE_HIRE", new AsyncEventCallback(async metadata => { var atlas = AtlasPlugin.Instance; var character = await EventSystem.Request <AtlasCharacter>("characters:fetchbyssn", metadata.Find <string>(0)); if (character == null) { return(null); } var user = await EventSystem.Request <AtlasUser>("user:fetch", character.Owner); if (user != null) { user.Send("job:employee:hire", character.Seed, metadata.Find <string>(1), metadata.Find <string>(2)); } else { Enum.TryParse <Employment>(metadata.Find <string>(1), out var employment); character.Metadata.Employment = employment; character.Metadata.EmploymentRole = 0; await character.Save(); } return(null); })); }
public override void Begin() { foreach (var position in Positions) { new BlipInfo() { Name = "Bankomat / Bank", Sprite = 431, Color = 11, Scale = 0.7f, Position = position }.Commit(); } Atlas.AttachNuiHandler("CLOSE_ATM", new EventCallback(metadata => { API.SetNuiFocus(false, false); return(null); })); Atlas.AttachNuiHandler("DEPOSIT_ATM", new EventCallback(metadata => { var amount = 0L; try { amount = long.Parse(metadata.Find <string>(0)); } catch (Exception ex) { Logger.Info($"{ex}"); // Silenced } var character = Cache.Character; if (amount > 0) { if (character.Cash >= amount) { character.Cash -= amount; character.BankAccount.Balance += amount; character.BankAccount.History.Add(new BankTransaction { Type = BankTransactionType.Deposit, Amount = amount, Date = DateTime.Now, Information = "Bankomat" }); } else { Cache.Player.ShowNotification($"Du har inte {amount} SEK på dig!"); } } API.SetNuiFocus(false, false); IsAtmOpened = false; return(this); })); Atlas.AttachNuiHandler("WITHDRAW_ATM", new EventCallback(metadata => { var amount = 0L; try { amount = long.Parse(metadata.Find <string>(0)); } catch (Exception) { // Silenced } var character = Cache.Character; if (amount > 0) { if (character.BankAccount.Balance >= amount) { character.Cash += amount; character.BankAccount.Balance -= amount; character.BankAccount.History.Add(new BankTransaction { Type = BankTransactionType.Withdraw, Amount = amount, Date = DateTime.Now, Information = "Bankomat" }); } else { Cache.Player.ShowNotification($"Du har inte {amount} SEK på ditt konto!"); } } API.SetNuiFocus(false, false); IsAtmOpened = false; return(this); })); }
public override void Begin() { Atlas.AttachNuiHandler("CLOSE_BILL", new EventCallback(metadata => { API.SetNuiFocus(false, false); return(null); })); Atlas.AttachNuiHandler("PAY_BILL", new AsyncEventCallback(async metadata => { var player = Cache.Player; var character = player.Character; var seed = metadata.Find <string>(0); var bills = await EventSystem.Request <List <Bill> >("billing:fetch", Cache.Character.Seed); var bill = bills.FirstOrDefault(self => self.Seed == seed); API.SetNuiFocus(false, false); if (bill == null) { Logger.Info($"[Billing] Could not pay bill due to it already being removed. ({seed})"); return(null); } if (character.BankAccount.Balance >= bill.Amount) { character.BankAccount.Balance -= bill.Amount; var job = JobManager.GetModule().Registered .FirstOrDefault(self => self.Label == bill.Sender.Business); var profile = job?.GetProfile <JobBusinessProfile>(); if (profile != null) { profile.Business.Balance += bill.Amount; profile.Commit(); } player.ShowNotification($"Du betalade faktura #{bill.BillNumber}"); EventSystem.GetModule().Send("PAY_BILL", seed); } else { player.ShowNotification($"Du har inte råd att betala denna faktura. ({bill.Amount} SEK)"); } return(null); })); Atlas.AttachNuiHandler("DESTROY_BILL", new EventCallback(metadata => { API.SetNuiFocus(false, false); EventSystem.GetModule().Send("DESTROY_BILL", metadata.Find <string>(0)); return(null); })); Atlas.AttachNuiHandler("SUBMIT_BILL", new AsyncEventCallback(async metadata => { var player = Cache.Player; var bill = JsonConvert.DeserializeObject <Bill>(metadata.Find <string>(0)); bill.IsCreated = true; bill.IsActive = true; API.SetNuiFocus(false, false); if (bill.Receiver.Type == BillReceiverType.Individual) { var character = await EventSystem.Request <AtlasCharacter>("characters:fetch", bill.Receiver.Name); if (character == null) { player.ShowNotification($"Kunde inte hitta någon vid namn {bill.Receiver.Name}."); return(null); } var user = await EventSystem.Request <AtlasUser>("user:fetch", character.Owner); user?.Send("billing:receive", bill); } else { var job = JobManager.GetModule().Registered.FirstOrDefault(self => self.Label.ToLower().Trim() == bill.Receiver.Name.ToLower().Trim()); if (job == null) { player.ShowNotification($"Kunde inte hitta ett företag vid namn {bill.Receiver.Name}."); return(null); } player.ShowNotification("Denna funktion är för tillfället inaktiverad."); return(null); } EventSystem.GetModule().Send("billing:create", bill); Cache.Player.ShowNotification( $"{bill.Sender.Business}: Skickade en faktura till {bill.Receiver.Name}. (Att betala: {bill.Amount} SEK)"); return(null); })); EventSystem.GetModule().Attach("billing:receive", new EventCallback(metadata => { var bill = metadata.Find <Bill>(0); if (bill.Receiver.Name == Cache.Character.Fullname) { Cache.Player.ShowNotification( $"{bill.Sender.Business}: Du fick en faktura av {bill.Receiver.Name}. (Att betala: {bill.Amount} SEK)"); } return(null); })); }