Example #1
0
        private void OnPlayerUpdateStance(UnturnedPlayer player, byte stance)
        {
            if (stance == (byte)6 && Configuration.Instance.AllowCarOwnerShip)
            {
                InteractableVehicle veh = player.Player.movement.getVehicle();
                if (Instance.DatabaseCar.CheckCarExistInDB(veh.instanceID.ToString()))
                {
                    if (Instance.DatabaseCar.CheckCarDestoryed(veh.instanceID.ToString()) != veh.id.ToString())
                    {
                        uint   CheckIDOld = veh.instanceID + 1;
                        string PlayerID   = Instance.DatabaseCar.GetOwnerID((CheckIDOld).ToString());
                        string CarID      = Instance.DatabaseCar.GetCarID((CheckIDOld).ToString());
                        if (PlayerID == player.Id && CarID == veh.id.ToString())
                        {
                            Instance.DatabaseCar.RemovedDestoryedCar(veh.instanceID.ToString());
                            Instance.DatabaseCar.RemovedDestoryedCar(CheckIDOld.ToString());
                            Instance.DatabaseCar.AddOwnership(veh.instanceID.ToString(), player.Id, player.SteamName);
                            return;
                        }
                        else
                        {
                            for (int x = 0; x < 10; x++)
                            {
                                CheckIDOld++;
                                PlayerID = Instance.DatabaseCar.GetOwnerID(CheckIDOld.ToString());
                                CarID    = Instance.DatabaseCar.GetCarID(CheckIDOld.ToString());
                                if (PlayerID == player.Id && CarID == veh.id.ToString())
                                {
                                    Instance.DatabaseCar.RemovedDestoryedCar(veh.instanceID.ToString());
                                    Instance.DatabaseCar.RemovedDestoryedCar(CheckIDOld.ToString());
                                    Instance.DatabaseCar.AddOwnership(veh.instanceID.ToString(), player.Id, player.SteamName);
                                    return;
                                }
                            }
                        }
                        Instance.DatabaseCar.RemovedDestoryedCar(veh.instanceID.ToString());
                        if (!Instance.Configuration.Instance.DriveUnownedCar)
                        {
                            foreach (Passenger p in player.Player.movement.getVehicle().passengers)
                            {
                                if (p.player.playerID.steamID.ToString() == player.Id)
                                {
                                    veh.tryRemovePlayer(out byte seat, player.CSteamID, out Vector3 point, out byte angle);
                                }
                            }
                        }
                        Instance.DatabaseCar.AddCar(veh.instanceID.ToString(), veh.id.ToString(), veh.name);
                        UnturnedChat.Say(player.CSteamID, Instance.Translate("lpx_car_promotebuy", veh.instanceID.ToString()));
                        return;
                    }
                    if (Instance.DatabaseCar.CheckOwner(veh.instanceID.ToString()) == "")
                    {
                        UnturnedChat.Say(player.CSteamID, Instance.Translate("lpx_car_promotebuy", veh.instanceID.ToString()));
                        if (!Instance.Configuration.Instance.DriveUnownedCar)
                        {
                            foreach (Passenger p in player.Player.movement.getVehicle().passengers)
                            {
                                if (p.player.playerID.steamID.ToString() == player.Id)
                                {
                                    veh.tryRemovePlayer(out byte seat, player.CSteamID, out Vector3 point, out byte angle);
                                }
                            }
                        }
                        return;
                    }
                    if (player.Id != Instance.DatabaseCar.CheckOwner(veh.instanceID.ToString()))
                    {
                        string[] PlayersWithKey = Instance.DatabaseCar.GetGivenKeys(veh.instanceID.ToString());
                        for (int x = 0; x < PlayersWithKey.Length; x++)
                        {
                            if (PlayersWithKey[x].Trim() == player.Id)
                            {
                                UnturnedChat.Say(player, Instance.Translate("car_key_used", veh.instanceID.ToString()));
                                return;
                            }
                        }
                        if (Instance.DatabaseCar.CheckLockedStatus(veh.instanceID.ToString()))
                        {
                            foreach (Passenger p in player.Player.movement.getVehicle().passengers)
                            {
                                if (p.player.playerID.steamID.ToString() == player.Id)
                                {
                                    veh.tryRemovePlayer(out byte seat, player.CSteamID, out Vector3 point, out byte angle);
                                }
                            }
                            UnturnedChat.Say(player.CSteamID, Instance.Translate("lpx_car_ownerfalse"));
                            UnturnedChat.Say(player.CSteamID, Instance.Translate("lpx_car_promotebuy", veh.instanceID.ToString()));
                        }
                        else
                        {
                            UnturnedChat.Say(player.CSteamID, Instance.Translate("car_not_locked", Instance.DatabaseCar.GetOwnerName(veh.instanceID.ToString())));
                        }
                    }
                    else
                    {
                        decimal[] lLicensePrice = { 500, 750, /**/ 1000, 1500, 3500, /**/ 1250, 1750, 3750, /**/ 1500, 2000, 4000, 10000, /**/ 90000 };
                        decimal   licensePrice;

                        string strLicense = Instance.DatabaseCar.GetLicence(veh.id.ToString());
                        int    numLicense = Instance.DatabaseCar.ConvertLicenceToInt(strLicense);

                        bool HasLicence = LPXRemastered.Instance.DatabaseCar.CheckLicence(player.Id, strLicense);
                        if (!HasLicence && !player.HasPermission("Licence_" + strLicense))
                        {
                            licensePrice = lLicensePrice.ElementAt(numLicense);

                            decimal balance = Uconomy.Instance.Database.GetBalance(player.Id);
                            if (balance < licensePrice)
                            {
                                UnturnedChat.Say(player, "You need " + licensePrice + " to buy a license");
                                veh.tryRemovePlayer(out _, player.CSteamID, out _, out _);
                                return;
                            }

                            decimal bal = Uconomy.Instance.Database.IncreaseBalance(player.Id, (licensePrice * -1));
                            if (bal >= 0.0m)
                            {
                                UnturnedChat.Say(player, Instance.Translate("new_balance_msg", new object[] { bal, Uconomy.Instance.Configuration.Instance.MoneyName }));
                            }
                        }
                        if (!HasLicence)
                        {
                            LPXRemastered.Instance.DatabaseCar.AddLicenceToPlayer(player.Id, strLicense);
                            UnturnedChat.Say(player, Instance.Translate("lpx_car_licenceOK") + numLicense.ToString());
                        }
                    }
                }
                else
                {
                    if (!Configuration.Instance.DriveUnownedCar)
                    {
                        foreach (Passenger p in player.Player.movement.getVehicle().passengers)
                        {
                            if (p.player.playerID.steamID.ToString() == player.Id)
                            {
                                veh.tryRemovePlayer(out byte seat, player.CSteamID, out Vector3 point, out byte angle);
                            }
                        }
                    }
                    Instance.DatabaseCar.AddCar(veh.instanceID.ToString(), veh.id.ToString(), veh.name);
                    UnturnedChat.Say(player.CSteamID, Instance.Translate("lpx_car_list_all", veh.instanceID.ToString()));
                }
            }
        }