Ejemplo n.º 1
0
        public async Task PlayerSearchTakeItem(ClassicPlayer player, int givenTargetCharId, string itemName, string itemLocation, int itemAmount)
        {
            try
            {
                if (player == null || !player.Exists || givenTargetCharId <= 0 || itemName == "" || itemAmount <= 0 || itemLocation == "")
                {
                    return;
                }
                int charId = player.CharacterId;
                if (charId <= 0)
                {
                    return;
                }
                if (player.HasPlayerHandcuffs() || player.HasPlayerRopeCuffs())
                {
                    HUDHandler.SendNotification(player, 3, 5000, "Wie willst du das mit Handschellen/Fesseln machen?"); return;
                }
                var targetPlayer = Alt.Server.GetPlayers().ToList().FirstOrDefault(x => x.GetCharacterMetaId() == (ulong)givenTargetCharId);
                int targetCharId = (int)targetPlayer.GetCharacterMetaId();
                if (targetCharId != givenTargetCharId)
                {
                    return;
                }
                if (targetPlayer == null || !targetPlayer.Exists)
                {
                    return;
                }
                if (!player.Position.IsInRange(targetPlayer.Position, 3f))
                {
                    HUDHandler.SendNotification(player, 3, 5000, "Fehler: Du bist zuweit vom Spieler entfernt."); return;
                }
                if (!targetPlayer.HasPlayerHandcuffs() && !targetPlayer.HasPlayerRopeCuffs())
                {
                    HUDHandler.SendNotification(player, 3, 5000, "Der Spieler ist nicht gefesselt."); return;
                }
                if (!ServerItems.IsItemDroppable(itemName) || !ServerItems.IsItemGiveable(itemName))
                {
                    HUDHandler.SendNotification(player, 3, 5000, "Fehler: Diesen Gegenstand kannst du nicht entfernen."); return;
                }
                if (!CharactersInventory.ExistCharacterItem(targetCharId, itemName, itemLocation))
                {
                    HUDHandler.SendNotification(player, 4, 5000, "Fehler: Dieser Gegenstand existiert nicht mehr."); return;
                }
                if (CharactersInventory.IsItemActive(targetPlayer, itemName))
                {
                    HUDHandler.SendNotification(player, 3, 5000, "Ausgerüstete Gegenstände können nicht entwendet werden."); return;
                }
                if (CharactersInventory.GetCharacterItemAmount(targetCharId, itemName, itemLocation) < itemAmount)
                {
                    HUDHandler.SendNotification(player, 3, 5000, "Fehler: Soviele Gegenstände hat der Spieler davon nicht."); return;
                }
                float itemWeight     = ServerItems.GetItemWeight(itemName) * itemAmount;
                float invWeight      = CharactersInventory.GetCharacterItemWeight(charId, "inventory");
                float backpackWeight = CharactersInventory.GetCharacterItemWeight(charId, "backpack");
                if (invWeight + itemWeight > 15f && backpackWeight + itemWeight > Characters.GetCharacterBackpackSize(Characters.GetCharacterBackpack(charId)))
                {
                    HUDHandler.SendNotification(player, 3, 5000, $"Du hast nicht genug Platz in deinen Taschen."); return;
                }
                CharactersInventory.RemoveCharacterItemAmount(targetCharId, itemName, itemAmount, itemLocation);
                if (invWeight + itemWeight <= 15f || itemName == "Bargeld" || itemWeight == 0f)
                {
                    HUDHandler.SendNotification(player, 2, 5000, $"Du hast der Person {itemName} ({itemAmount}x) entwendet. (Lagerort: Inventar).");
                    HUDHandler.SendNotification(targetPlayer, 2, 5000, $"Dir wurde der Gegenstand {itemName} ({itemAmount}x) aus dem Inventar entwendet.");
                    CharactersInventory.AddCharacterItem(charId, itemName, itemAmount, "inventory");
                    return;
                }

                if (Characters.GetCharacterBackpack(charId) != "None" && backpackWeight + itemWeight <= Characters.GetCharacterBackpackSize(Characters.GetCharacterBackpack(charId)))
                {
                    HUDHandler.SendNotification(player, 2, 5000, $"Du hast der Person {itemName} ({itemAmount}x) entwendet. (Lagerort: Rucksack/Tasche).");
                    HUDHandler.SendNotification(targetPlayer, 2, 5000, $"Dir wurde der Gegenstand {itemName} ({itemAmount}x) aus dem Rucksack entwendet.");
                    CharactersInventory.AddCharacterItem(charId, itemName, itemAmount, "backpack");
                    return;
                }
            }
            catch (Exception e)
            {
                Alt.Log($"{e}");
            }
        }
Ejemplo n.º 2
0
        public async Task GiveItem(ClassicPlayer player, string itemname, int itemAmount, string fromContainer, int targetPlayerId)
        {
            try
            {
                if (player == null || !player.Exists || itemname == "" || itemAmount <= 0 || fromContainer == "" || targetPlayerId == 0)
                {
                    return;
                }
                player.EmitLocked("Client:Inventory:closeCEF");
                if (player.HasPlayerHandcuffs() || player.HasPlayerRopeCuffs())
                {
                    HUDHandler.SendNotification(player, 3, 5000, "Wie willst du das mit Handschellen/Fesseln machen?"); return;
                }
                if (!ServerItems.IsItemGiveable(itemname))
                {
                    HUDHandler.SendNotification(player, 4, 5000, $"Diesen Gegenstand kannst du nicht weggeben ({itemname})."); return;
                }
                int charId = player.CharacterId;
                if (charId <= 0 || !CharactersInventory.ExistCharacterItem(charId, itemname, fromContainer))
                {
                    return;
                }
                if (CharactersInventory.GetCharacterItemAmount(charId, itemname, fromContainer) < itemAmount)
                {
                    HUDHandler.SendNotification(player, 4, 5000, $"Die angegebene Anzahl ist nicht vorhanden ({itemname})."); return;
                }
                if (CharactersInventory.IsItemActive(player, itemname))
                {
                    HUDHandler.SendNotification(player, 4, 5000, $"Ausgerüstete Gegenstände können nicht abgegeben werden."); return;
                }
                float itemWeight     = ServerItems.GetItemWeight(itemname) * itemAmount;
                float invWeight      = CharactersInventory.GetCharacterItemWeight(targetPlayerId, "inventory");
                float backpackWeight = CharactersInventory.GetCharacterItemWeight(targetPlayerId, "backpack");
                var   targetPlayer   = Alt.Server.GetPlayers().ToList().FirstOrDefault(x => x.GetCharacterMetaId() == (ulong)targetPlayerId);
                if (targetPlayer == null)
                {
                    return;
                }
                if (!player.Position.IsInRange(targetPlayer.Position, 5f))
                {
                    HUDHandler.SendNotification(player, 4, 5000, "Fehler: Die Person ist zu weit entfernt."); return;
                }
                if (invWeight + itemWeight > 15f && backpackWeight + itemWeight > Characters.GetCharacterBackpackSize(Characters.GetCharacterBackpack(targetPlayerId)))
                {
                    HUDHandler.SendNotification(player, 3, 5000, $"Der Spieler hat nicht genug Platz in seinen Taschen."); return;
                }
                if (invWeight + itemWeight <= 15f)
                {
                    HUDHandler.SendNotification(targetPlayer, 1, 5000, $"Eine Person hat dir den Gegenstand {itemname} ({itemAmount}x) gegeben.");
                    HUDHandler.SendNotification(player, 2, 5000, $"Du hast einem Spieler den Gegenstand {itemname} ({itemAmount}x) gegeben.");
                    CharactersInventory.AddCharacterItem(targetPlayerId, itemname, itemAmount, "inventory");
                    CharactersInventory.RemoveCharacterItemAmount(charId, itemname, itemAmount, fromContainer);
                    InventoryAnimation(player, "give", 0);
                    return;
                }

                if (Characters.GetCharacterBackpack(targetPlayerId) != "None" && backpackWeight + itemWeight <= Characters.GetCharacterBackpackSize(Characters.GetCharacterBackpack(targetPlayerId)))
                {
                    HUDHandler.SendNotification(targetPlayer, 1, 5000, $"Eine Person hat dir den Gegenstand {itemname} ({itemAmount}x) gegeben.");
                    HUDHandler.SendNotification(player, 2, 5000, $"Du hast einem Spieler den Gegenstand {itemname} ({itemAmount}x) gegeben.");
                    CharactersInventory.AddCharacterItem(targetPlayerId, itemname, itemAmount, "backpack");
                    CharactersInventory.RemoveCharacterItemAmount(charId, itemname, itemAmount, fromContainer);
                    InventoryAnimation(player, "give", 0);
                    return;
                }
            }
            catch (Exception e)
            {
                Alt.Log($"{e}");
            }
        }