Пример #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.");
            }
        }
Пример #2
0
        public void ThrowWeapon(Client client, int force)
        {
            Player player = Player.PlayerData[client];

            Console.WriteLine(client.name);
            if (client.currentWeapon != WeaponHash.Unarmed)
            {
                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, client.rotation.Z);

                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.ThrowPhysics(client, force, -1);

                Weapon.DroppedWeapons.Add(weap);
                API.removePlayerWeapon(player.Client, weap.Model);
                player.Weapons.Remove(weap);
                WeaponRepository.UpdateAsync(weap);
            }
            else
            {
                API.SendErrorNotification(player.Client, "You can only drop the weapon you are holding.");
            }
        }
Пример #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;
            }
        }