Exemple #1
0
        public void MyVehiclesSellCar(Player sender, params object[] arguments)
        {
            Character   character = sender.GetCharacter();
            GameVehicle scVeh     =
                VehicleManager.Vehicles.Single(
                    x => x.Id == Convert.ToInt32(arguments[0]) && x.OwnerId == character.Id);
            var tid    = (string)arguments[1];
            var target = PlayerManager.ParseClient(tid);

            if (target == null)
            {
                NAPI.Chat.SendChatMessageToPlayer(sender, "That player isn't online or doesn't exist.");
                return;
            }
            var targetChar    = target.GetCharacter();
            var targetAccount = target.GetAccount();

            var price = 0;

            if (!int.TryParse((string)arguments[2], out price))
            {
                NAPI.Chat.SendChatMessageToPlayer(sender, "Invalid price entered.");
                return;
            }
            if (price < 0)
            {
                NAPI.Chat.SendChatMessageToPlayer(sender, "Price cannot be negative.");
                return;
            }

            if (targetChar.OwnedVehicles.Count >= VehicleManager.GetMaxOwnedVehicles(targetChar.Player))
            {
                NAPI.Chat.SendChatMessageToPlayer(sender, "This player cannot own any more vehicles.");
                return;
            }

            NAPI.Chat.SendChatMessageToPlayer(sender,
                                              $"Are you sure you would like to sell the ~r~{returnCorrDisplayName(scVeh.VehModel)}~w~ for ~r~${price}~w~ to the player ~r~{targetChar.rp_name()}~w~?");
            NAPI.Chat.SendChatMessageToPlayer(sender, "Use /confirmsellvehicle to sell.");
            NAPI.Data.SetEntityData(sender, "sellcar_selling", new dynamic[] { scVeh, targetChar, price });
        }
Exemple #2
0
        private void API_onClientEventTrigger(Client sender, string eventName, params object[] arguments)
        {
            Character character = sender.GetCharacter();

            switch (eventName)
            {
            case "myvehicles_locatecar":
                vehicle_manager.Vehicle lcVeh =
                    VehicleManager.Vehicles.Single(
                        x => x.NetHandle.Value == Convert.ToInt32(arguments[0]) && x.OwnerId == character.Id);
                Vector3 loc = API.GetEntityPosition(lcVeh.NetHandle);
                API.TriggerClientEvent(sender, "myvehicles_setCheckpointToCar", loc.X, loc.Y, loc.Z);
                API.SendChatMessageToPlayer(sender, "A checkpoint has been set to the vehicle.");
                break;

            case "myvehicles_abandoncar":
                vehicle_manager.Vehicle acVeh =
                    VehicleManager.Vehicles.Single(
                        x => x.Id == Convert.ToInt32(arguments[0]) && x.OwnerId == character.Id);
                VehicleManager.despawn_vehicle(acVeh);
                VehicleManager.delete_vehicle(acVeh);
                acVeh.Delete();
                API.SendChatMessageToPlayer(sender,
                                            $"You have sucessfully abandoned your ~r~{VehicleOwnership.returnCorrDisplayName(acVeh.VehModel)}~w~");
                break;

            case "myvehicles_sellcar":
                vehicle_manager.Vehicle scVeh =
                    VehicleManager.Vehicles.Single(
                        x => x.Id == Convert.ToInt32(arguments[0]) && x.OwnerId == character.Id);
                var tid    = (string)arguments[1];
                var target = PlayerManager.ParseClient(tid);
                if (target == null)
                {
                    API.SendChatMessageToPlayer(sender, "That player isn't online or doesn't exist.");
                    return;
                }
                var targetChar    = target.GetCharacter();
                var targetAccount = target.GetAccount();

                var price = 0;
                if (!int.TryParse((string)arguments[2], out price))
                {
                    API.SendChatMessageToPlayer(sender, "Invalid price entered.");
                    return;
                }
                if (price < 0)
                {
                    API.SendChatMessageToPlayer(sender, "Price cannot be negative.");
                    return;
                }

                if (targetChar.OwnedVehicles.Count >= VehicleManager.GetMaxOwnedVehicles(targetChar.Client))
                {
                    API.SendChatMessageToPlayer(sender, "This player cannot own any more vehicles.");
                    return;
                }

                API.SendChatMessageToPlayer(sender,
                                            $"Are you sure you would like to sell the ~r~{VehicleOwnership.returnCorrDisplayName(scVeh.VehModel)}~w~ for ~r~${price}~w~ to the player ~r~{targetChar.rp_name()}~w~?");
                API.SendChatMessageToPlayer(sender, "Use /confirmsellvehicle to sell.");
                API.SetEntityData(sender, "sellcar_selling", new dynamic[] { scVeh, targetChar, price });
                break;

            case "groupvehicles_locatecar":
                vehicle_manager.Vehicle gVeh =
                    VehicleManager.Vehicles.Single(
                        x => x.NetHandle.Value == Convert.ToInt32(arguments[0]) && x.GroupId == character.GroupId);
                Vector3 location = API.GetEntityPosition(gVeh.NetHandle);
                API.TriggerClientEvent(sender, "myvehicles_setCheckpointToCar", location.X, location.Y, location.Z);
                API.SendChatMessageToPlayer(sender, "A checkpoint has been set to the vehicle.");
                break;
            }
        }
Exemple #3
0
        public void confirmbuyvehicle_cmd(Client player)
        {
            Character character = player.GetCharacter();
            Account   account   = player.GetAccount();
            var       data      = API.GetEntityData(player, "sellcar_buying");

            if (data != null)
            {
                Character buyingFrom = data[0];
                Vehicle   veh        = data[1];
                int       price      = data[2];
                //Make sure near him.
                var buyingPos = buyingFrom.Client.position;
                if (player.position.DistanceTo(buyingPos) <= 5f)
                {
                    //make sure still have slots.
                    if (character.OwnedVehicles.Count < VehicleManager.GetMaxOwnedVehicles(character.Client))
                    {
                        //make sure have money.
                        if (Money.GetCharacterMoney(character) >= price)
                        {
                            //Do actual process.
                            InventoryManager.GiveInventoryItem(buyingFrom, new Money(), price);
                            InventoryManager.DeleteInventoryItem(character, typeof(Money), price);
                            veh.OwnerId   = character.Id;
                            veh.OwnerName = character.CharacterName;
                            veh.Save();

                            //DONE, now spawn if hes vip.
                            if (!veh.IsSpawned)
                            {
                                //He won't be able to buy it anyways if he wasn't VIP... so I THINK he can now have it spawned, right ? :/
                                if (VehicleManager.spawn_vehicle(veh) != 1)
                                {
                                    API.ConsoleOutput(
                                        $"There was an error spawning vehicle #{veh.Id} of {character.CharacterName}.");
                                }
                            }

                            //Tell.
                            API.SendChatMessageToPlayer(player, "You have sucessfully bought the car.");
                            API.SendChatMessageToPlayer(buyingFrom.Client, "You have successfully sold the car.");
                            API.SetEntityData(player, "sellcar_buying", null);
                        }
                        else
                        {
                            API.SendChatMessageToPlayer(player, "You don't have enough money.");
                            API.SendChatMessageToPlayer(buyingFrom.Client, "The buyer doesn't have enough money.");
                            API.SetEntityData(player, "sellcar_buying", null);
                        }
                    }
                    else
                    {
                        API.SendChatMessageToPlayer(player, "You can't own anymore vehicles.");
                        API.SendChatMessageToPlayer(buyingFrom.Client, "The buyer can't own anymore vehicles.");
                        API.SetEntityData(player, "sellcar_buying", null);
                    }
                }
                else
                {
                    API.SendChatMessageToPlayer(player, "You must be near the buyer.");
                    API.SendChatMessageToPlayer(buyingFrom.Client, "The buyer must be near you.");
                    API.SetEntityData(player, "sellcar_buying", null);
                }
            }
            else
            {
                API.SendChatMessageToPlayer(player, "You aren't buying any car.");
            }
        }