public async void PlayerInit(Player player) { API.setPlayerNametag(player.Client, player.Username.Roleplay()); API.setPlayerName(player.Client, player.Username.Roleplay()); API.setPlayerHealth(player.Client, (int)player.Health); API.setPlayerArmor(player.Client, (int)player.Armour); API.setEntityDimension(player.Client, player.Dimension); player.IsInInterior = (player.Dimension > 0); if (player.IsInInterior) { player.PropertyIn = PropertyManager.Properties.FirstOrDefault(p => p.Dimension == player.Dimension); } Skin playerSkin = await SkinRepository.GetSkinById(player.Skin); API.setPlayerSkin(player.Client, (PedHash)playerSkin.Model); List <SkinVariations> skinVars = playerSkin.Variations(); player.ChatIndicatorLabel = API.createTextLabel("typing...", player.Client.position, 50, 0.35f, false, player.Dimension); player.ChatIndicatorLabel.color = new Color(0, 0, 0, 0); player.ChatIndicatorLabel.attachTo(player.Client, null, new Vector3(0, 0, 0.9f), new Vector3()); for (int i = 0; i < 12; i++) { API.setPlayerClothes(player.Client, i, skinVars[i].Drawable, skinVars[i].Texture); } player.IsLogged = true; player.MasterAccount.ActiveConnectionLog.PlayerId = player.Id; ConnectionLogRepository.UpdateAsync(player.MasterAccount.ActiveConnectionLog); if (player.FactionId > 0) { player.Faction = Faction.FactionData.Single(f => f.Id == player.FactionId); } player.Weapons = await WeaponRepository.GetAllWeaponsByPlayerIdAsync(player.Id); foreach (Weapon w in player.Weapons) { API.givePlayerWeapon(player.Client, w.Model, w.Ammo, false, false); } player.Inventory = await InventoryRepository.GetInventoryByOwnerIdAsync(player.Id); player.PopulateWeaponSkills(); await player.LoadPlayerVehicles(); foreach (Inventory i in player.Inventory) { if (i.IsPhone()) { Phone p = PhoneRepository.GetPhoneByIMEI(long.Parse(i.Value)); if (p.IsPrimary) { player.PrimaryPhone = p; if (p.PoweredOn) { if (p.BatteryLevel > 3) { p.TurnOn(player.Client); } else { p.TurnOff(player.Client); } } else { p.TurnOff(player.Client); } break; } } } player.InEvent = PlayerEvent.None; player.Client.freeze(false); player.Client.ToggleCursorLock(false); player.Client.transparency = 255; API.sendNativeToAllPlayers(Hash.SET_CURRENT_PED_WEAPON, player.Client, (int)WeaponHash.Unarmed, true); Player.PlayerData.Add(player.Client, player); if (player.LastPosition != new Vector3(0, 0, 0)) { player.Client.position = player.LastPosition; } API.triggerClientEvent(player.Client, "hasLoggedIn", ((char)player.MasterAccount.KeyCursor).ToString(), ((char)player.MasterAccount.KeyInventory).ToString(), ((char)player.MasterAccount.KeyInteract).ToString()); API.triggerClientEvent(player.Client, "executeSkillTimer"); API.triggerClientEvent(player.Client, "loadScoreboard"); API.triggerClientEvent(player.Client, "initInteractionMenu"); API.sendNativeToPlayer(player.Client, Hash.SET_CAM_AFFECTS_AIMING, player.Client, true); //API.sendNativeToPlayer(player.Client, Hash.SET_PED_CAN_BE_SHOT_IN_VEHICLE, player.Client, true); player.Client.invincible = true; for (int i = 0; i < 12; i++) { API.exported.doormanager.refreshDoorState(i); } UpdateNatives(player); PrisonManager.LoadPrisonSentenceForPlayer(player); OnPlayerLoggedIn(player); }
private async void OnClientEventTrigger(Client sender, string eventName, params object[] arguments) { switch (eventName) { case "getInventoryTypeActions": { Inventory inv = InventoryRepository.GetInventoryItemById((int)arguments[0]); if (inv.IsPhone()) { Phone p = PhoneRepository.GetPhoneByIMEI(long.Parse(inv.Value)); API.triggerClientEvent(sender, "displayActionsForItem", inv.Id, p.IsPrimary ? JsonConvert.SerializeObject("GIVE,DROP,UNSET PRIMARY".Split(',')) : JsonConvert.SerializeObject("GIVE,DROP,SET PRIMARY".Split(','))); return; } API.triggerClientEvent(sender, "displayActionsForItem", inv.Id, JsonConvert.SerializeObject(Inventory.GetActionsByType[inv.Type])); } break; case "performActionOnItem": { Inventory inv = InventoryRepository.GetInventoryItemById((int)arguments[0]); switch (arguments[1].ToString()) { case "USE": UsePlayerInventoryItem(sender, (int)arguments[0]); break; case "GIVE": GetPlayerToGiveItem(sender, (int)arguments[0]); break; case "DROP": DropInventoryItem(sender, (int)arguments[0]); break; case "SET PRIMARY": SetPhonePrimary(sender, inv, true); break; case "UNSET PRIMARY": SetPhonePrimary(sender, inv, false); break; case "RELEASE": DestroyInventoryItem(sender, (int)arguments[0]); break; } } break; case "giveItemToPlayer": if ((int)arguments[0] == 1) { GiveInventoryItem(sender, arguments[1].ToString()); } break; case "DisplayPlayerInventory": { Player p = Player.PlayerData[sender]; UpdatePlayerInventory(p); } break; case "OnInventoryItemMoved": { Player p = Player.PlayerData[sender]; Inventory item; try { item = p.Inventory.Single(i => i.Id == (int)arguments[0]); } catch { item = Inventory.DroppedItems.Single(i => i.Id == (int)arguments[0]); Inventory.DroppedItems.Remove(item); API.deleteEntity(item.DroppedObj); if (!Inventory.IsStackable(item)) { item.OwnerId = p.Id; item.OwnerType = InventoryOwnerType.Player; p.Inventory.Add(item); API.SendInfoNotification(p.Client, String.Format("You have picked up a {0}", item.Name)); API.playPlayerAnimation(p.Client, 0, "pickup_object", "pickup_low"); RefreshAfterDropChange(item); } } item.SlotPosition = int.Parse(arguments[1].ToString() + arguments[2].ToString()); InventoryRepository.UpdateAsync(item); } break; case "OnFriskInventoryItemTaken": { Player p = Player.PlayerData[sender]; Inventory item = null; try { item = p.Inventory.Single(i => i.Id == (int)arguments[0]); } catch { item = p.PlayerInteractingWith.Inventory.Single(i => i.Id == (int)arguments[0]); } if (item != null) { int newOwnerId = (int)arguments[1]; Player oldOwner = Player.PlayerData.Values.FirstOrDefault(pl => pl.Id == item.OwnerId); Player newOwner = Player.PlayerData.Values.FirstOrDefault(pl => p.Id == newOwnerId); API.SendCloseMessage(sender, 10.0f, "~#C2A2DA~", p != oldOwner ? string.Format("{0} {1} takes a {2} from {3}.", p.Faction.Ranks[p.FactionRank].Title, API.getPlayerName(sender), item.Name, oldOwner.Username.Roleplay()) : string.Format("{0} {1} places a {2} on {3}.", p.Faction.Ranks[p.FactionRank].Title, API.getPlayerName(sender), item.Name, newOwner.Username.Roleplay())); item.OwnerId = newOwner.Id; item.OwnerType = InventoryOwnerType.Player; item.SlotPosition = int.Parse(arguments[2].ToString() + arguments[3].ToString()); InventoryRepository.UpdateAsync(item); RefreshPlayerInventory(p.PlayerInteractingWith); ShowFriskInventory(p, p.PlayerInteractingWith); } } break; case "OnTrunkInventoryItemTaken": { int oldOwnerId; Player p = Player.PlayerData[sender]; string type = arguments[2].ToString(); Vehicle vTo = null; Player from = null; Vehicle vFrom = null; Player to = null; Inventory item = null; item = InventoryRepository.GetInventoryItemById((int)arguments[0]); Console.WriteLine(arguments[1].ToString()); if (type == "trunk") { vTo = Vehicle.VehicleData.Values.FirstOrDefault( ve => ve.Id == int.Parse(arguments[1].ToString())); from = p; } else { to = Player.PlayerData.Values.FirstOrDefault( pl => pl.Id == int.Parse(arguments[1].ToString())); if (item.OwnerType == InventoryOwnerType.Vehicle) { vFrom = Vehicle.VehicleData.Values.FirstOrDefault(ve => ve.Id == item.OwnerId); } } oldOwnerId = item.OwnerId; item.OwnerType = vTo != null ? InventoryOwnerType.Vehicle : to != null ? InventoryOwnerType.Player : InventoryOwnerType.Dropped; item.OwnerId = vTo != null ? vTo.Id : to != null ? p.Id : -1; item.SlotPosition = int.Parse(arguments[3].ToString() + arguments[4].ToString()); InventoryRepository.UpdateAsync(item); if (oldOwnerId == -1) { Inventory.DroppedItems.Remove(Inventory.DroppedItems.Single(i => i.Id == (int)arguments[0])); API.deleteEntity(item.DroppedObj); API.SendInfoNotification(p.Client, String.Format("You have picked up a {0}", item.Name)); API.playPlayerAnimation(p.Client, 0, "pickup_object", "pickup_low"); RefreshAfterDropChange(item); } p.Inventory = await InventoryRepository.GetInventoryByOwnerIdAsync(p.Id); if (vFrom != null) { vFrom.TrunkItems.Remove(vFrom.TrunkItems.FirstOrDefault(vl => vl.Id == item.Id)); } if (item.OwnerType == InventoryOwnerType.Vehicle) { if (oldOwnerId != item.OwnerId) { vTo.TrunkItems.Add(item); } else { vTo.TrunkItems.FirstOrDefault(vl => vl.Id == item.Id).SlotPosition = item.SlotPosition; } } ShowTrunkInventory(p, p.VehicleInteractingWith); if (p == to) { return; } string fromString = vTo != null ? $"{vTo.DisplayName}" : $"{vFrom.DisplayName}"; API.SendCloseMessage(sender, 10.0f, "~#C2A2DA~", vTo == null ? string.Format("{0} takes a {1} from the {2}.", API.getPlayerName(sender), item.Name, fromString) : string.Format("{0} places a {1} on the {2}.", API.getPlayerName(sender), item.Name, fromString)); break; } case "OnHeaderSlotItemSelected": { Player p = Player.PlayerData[sender]; Inventory item = null; try { item = p.Inventory.FirstOrDefault(i => i.Id == (int)arguments[0]); } catch { Console.WriteLine("{0}: Error occurred when trying to open Header Slot with ID: {1}", Server.Date.ToString(), (int)arguments[0]); return; } if (item != null) { if (item.IsBag()) { } } } break; case "OnInventoryClose": { Player p = Player.PlayerData[sender]; if (p.AccessingBank != -1) { } p.InEvent = PlayerEvent.None; } break; } }