Beispiel #1
0
        public void CMD_AddDealershipVehicle(Client sender, int price)
        {
            if (!sender.isInVehicle)
            {
                API.sendChatMessageToPlayer(sender, $"~r~ERRO: ~s~Você não está em um veículo.");
            }
            else if (price < 1)
            {
                API.sendChatMessageToPlayer(sender, $"~r~ERRO: ~s~Preço inválido.");
            }
            else
            {
                foreach (Dealership dealership in Main.Dealerships)
                {
                    if (dealership.Position.DistanceTo(sender.position) < 40f)
                    {
                        if (dealership.VehicleSpawn.X == 0.0f && dealership.VehicleSpawn.Y == 0.0f)
                        {
                            API.sendChatMessageToPlayer(sender, "~r~ERRO: ~w~Você precisar configurar o spawn desta concessionária primeiro. (/dealershipspawn)");
                            return;
                        }

                        DealershipVehicle new_vehicle = new DealershipVehicle(sender.vehicle.model, sender.vehicle.primaryColor, sender.vehicle.secondaryColor, sender.vehicle.position, sender.vehicle.rotation, price);
                        dealership.Vehicles.Add(new_vehicle);

                        sender.vehicle.delete();
                        sender.position.Z += 0.5f;

                        new_vehicle.Create();
                        dealership.Save();

                        API.sendChatMessageToPlayer(sender, $"~g~SUCESSO: ~s~Você adicionou um {sender.vehicle.displayName} na concessionária: ~g~{dealership.Name}~s~.");
                        return;
                    }
                }

                API.sendChatMessageToPlayer(sender, $"~r~ERRO: ~s~Você não está próximo de uma concessionária.");
            }
        }
Beispiel #2
0
        public void Dealership_ClientEvent(Client player, string event_name, params object[] args)
        {
            switch (event_name)
            {
            case "RequestDealershipBuyMenu":
            {
                if (!player.hasData("DealershipVehicle_ID"))
                {
                    return;
                }

                DealershipVehicle vehicle = player.getData("DealershipVehicle_ID");
                player.triggerEvent("Dealership_PurchaseMenu", API.toJson(new { vehicle.Price }));
                break;
            }

            case "VehiclePurchase":
            {
                if (!player.hasData("DealershipVehicle_ID"))
                {
                    return;
                }

                int color1 = (int)args[0];
                int color2 = (int)args[1];

                Dealership        dealership = player.getData("Dealership_ID");
                DealershipVehicle vehicle    = player.getData("DealershipVehicle_ID");

                if (Player.Data.Character[player].Vehicles.Count >= 3)
                {
                    API.sendChatMessageToPlayer(player, $"~r~ERRO: ~s~Você pode ter apenas 3 veículos.");
                    return;
                }

                else if (vehicle.Price > Player.Data.Character[player].Money)
                {
                    API.sendChatMessageToPlayer(player, $"~r~ERRO: ~s~Você não tem dinheiro suficiente.");
                    return;
                }

                var veh = API.shared.createVehicle(vehicle.Model, new Vector3(dealership.VehicleSpawn.X, dealership.VehicleSpawn.Y, dealership.VehicleSpawn.Z), new Vector3(0.0, 0.0, 0.0), color1, color2);
                veh.engineStatus = false;
                API.shared.setPlayerIntoVehicle(player, veh, -1);

                player.resetData("Dealership_ID");
                player.resetData("DealershipVehicle_ID");
                player.triggerEvent("OnExitDealershipVehicle");

                player.giveMoney(-vehicle.Price);
                player.sendNotification("", $"Você comprou um ~g~{veh.displayName}~s~.");

                CharacterVehicle characterVehicle = new CharacterVehicle
                {
                    Character = Player.Data.Character[player],
                    Vehicle   = veh,
                    Price     = vehicle.Price,
                    Model     = vehicle.Model,
                    Color1    = color1,
                    Color2    = color2,
                    Fuel      = 100,
                    PositionX = veh.position.X,
                    PositionY = veh.position.Y,
                    PositionZ = veh.position.Z,
                    RotationX = 0.0f,
                    RotationY = 0.0f,
                    RotationZ = 0.0f,
                    CreatedAt = DateTime.Now
                };

                Player.Data.Character[player].Vehicles.Add(characterVehicle);
                break;
            }
            }
        }