Ejemplo n.º 1
0
        private void DropPlayerWeapon(Player player)
        {
            if (player.Client.currentWeapon != 0)
            {
                string weaponName = NameToHash.Weapons.Keys.First(k => NameToHash.Weapons[k] == player.Client.currentWeapon);
                Weapon weap       = player.Weapons.Single(w => w.Model.GetHashCode() == player.Client.currentWeapon.GetHashCode());

                Vector3 pos = Player.GetPositionInFrontOfPlayer(player.Client, 1f, -0.5f);
                Vector3 rot = new Vector3(90, 0, 0);

                WeaponLogRepository.AddNew(new WeaponLog(weap.CurrentOwnerId, weap.Id, weap.Type, -1));

                weap.DroppedAt        = Server.Date;
                weap.DroppedPos       = pos;
                weap.DroppedRot       = rot;
                weap.DroppedDimension = player.Client.dimension;
                weap.CurrentOwnerId   = -1;
                weap.DroppedObj       = API.createObject(NameToHash.WeaponObjects[weaponName], pos, rot, weap.DroppedDimension);
                weap.ApplyPhysics();

                Weapon.DroppedWeapons.Add(weap);
                API.removePlayerWeapon(player.Client, (WeaponHash)weap.Model);
                player.Weapons.Remove(weap);

                WeaponRepository.UpdateAsync(weap);
            }
            else
            {
                API.SendErrorNotification(player.Client, "You can only drop the weapon you are holding.");
            }
        }
Ejemplo n.º 2
0
        public async static Task <Weapon> CreateArmouryWeapon(Player player, string itemName)
        {
            Weapon wep = null;

            wep = new Weapon()
            {
                Model          = (WeaponHash)GetWeaponModelFromItemName(itemName),
                Ammo           = GetWeaponAmmoFromItemName(itemName),
                Type           = WeaponType.Faction,
                CurrentOwnerId = player.Id,
                CreatedBy      = player.Id
            };

            API.shared.givePlayerWeapon(player.Client, (WeaponHash)wep.Model, wep.Ammo, true, false);
            player.Weapons.Add(wep);


            WeaponLogRepository.AddNew(new WeaponLog(0, await WeaponRepository.AddNew(wep), wep.Type, player.Id));

            if (DoesItemNameNeedSigningOut(itemName) && wep != null)
            {
                CreateSignOutSheet(wep, player);
            }
            return(wep);
        }
Ejemplo n.º 3
0
        public void PickUpItem(Client user, bool forcePickup = false)
        {
            Player player = Player.PlayerData[user];

            foreach (Weapon w in Weapon.DroppedWeapons)
            {
                if (w.CurrentOwnerId != -1)
                {
                    continue;
                }
                if (!(w.DroppedPos.DistanceTo(user.position) < 1.5f))
                {
                    continue;
                }
                API.deleteEntity(w.DroppedObj);
                if (player.Weapons.Any(we => we.Model == w.Model))
                {
                    if (!forcePickup)
                    {
                        API.ShowPopupPrompt(user, "playerPickupWeaponExists", "Existing weapon in inventory",
                                            "By picking up this weapon, the ammunition in the weapon will be added to your current weapon but this weapon will be destroyed.");
                        return;
                    }
                    else
                    {
                        int index = player.Weapons.IndexOf(player.Weapons.First(we => we.Model == w.Model));
                        player.Weapons[index].Ammo += w.Ammo;
                        WeaponRepository.UpdateAsync(player.Weapons[index]);
                        WeaponRepository.RemoveAsync(w);
                    }
                }
                else
                {
                    w.CurrentOwnerId = player.Id;
                    player.Weapons.Add(w);
                    WeaponRepository.UpdateAsync(w);
                }
                WeaponLogRepository.AddNew(new WeaponLog(-1, w.Id, w.Type, player.Id));

                API.givePlayerWeapon(user, w.Model, w.Ammo, true, true);
                API.setPlayerWeaponAmmo(user, w.Model, w.Ammo);
                Weapon.DroppedWeapons.Remove(w);
                return;
            }
        }