Example #1
0
        public static bool DoesPlayerHaveVehicleAccess(Player player, GameVehicle vehicle)
        {
            Account   account   = player.GetAccount();
            Character character = player.GetCharacter();

            if (vehicle == null)
            {
                return(false);
            }

            if (account.AdminLevel >= 3 && account.AdminDuty)
            {
                return(true);
            }
            if (character.Id == vehicle.OwnerId)
            {
                return(true);
            }
            if (vehicle.GroupId == character.GroupId && character.GroupId != 0)
            {
                return(true);
            }
            if (character.JobOne == vehicle.Job && character.JobOne != Job.None)
            {
                return(true);
            }
            if (DmvManager._testVehicles.Any(x => x[2] == vehicle))
            {
                return(true);
            }

            return(false);
        }
Example #2
0
        public static int spawn_vehicle(GameVehicle veh, Vector3 pos)
        {
            var returnCode = veh.Spawn(pos);

            if (returnCode == 1)
            {
                API.Shared.SetEntityData(veh.Entity, "Vehicle", veh);
            }

            API.Shared.SetVehicleEngineStatus(veh.Entity, false);
            if (veh.OwnerId != 0)
            {
                API.Shared.SetVehicleLocked(veh.Entity, true);
            }

            if (veh.Group.CommandType == Group.CommandTypeLspd)
            {
                API.Shared.SetVehicleEnginePowerMultiplier(veh.Entity, 4);
            }

            //Install modifications.
            ModdingManager.ApplyVehicleMods(veh);

            //Set wheel type. TODO: ERROR
            //API.SetVehicleWheelType(veh.Entity, VehicleInfo.Get(veh.VehModel).wheelType);
            return(returnCode);
        }
Example #3
0
 public static int respawn_vehicle(GameVehicle veh, Vector3 pos)
 {
     if (API.Shared.HasEntityData(veh.Entity, "Vehicle"))
     {
         despawn_vehicle(veh);
     }
     return(spawn_vehicle(veh, pos));
 }
Example #4
0
 public void FuelGetVehicleFuel(Player sender, params object[] arguments)
 {
     if (NAPI.Player.IsPlayerInAnyVehicle(sender) && NAPI.Player.GetPlayerVehicleSeat(sender) == -1)
     {
         GameVehicle veh = NAPI.Data.GetEntityData(NAPI.Player.GetPlayerVehicle(sender), "Vehicle");
         NAPI.ClientEvent.TriggerClientEvent(sender, "fuel_updatevalue", veh.Fuel);
     }
 }
Example #5
0
        public static int respawn_vehicle(GameVehicle veh)
        {
            if (veh == null)
            {
                return(-1);
            }

            return(respawn_vehicle(veh, veh.SpawnPos));
        }
Example #6
0
        public static void engine_cmd(Player player)
        {
            Character   character     = player.GetCharacter();
            var         vehicleHandle = API.Shared.GetPlayerVehicle(player);
            GameVehicle vehicle       = API.Shared.GetEntityData(vehicleHandle, "Vehicle");

            if (vehicle == null)
            {
                return;
            }

            if (API.Shared.GetPlayerVehicleSeat(player) != -1)
            {
                player.SendChatMessage("You must be the driver of a vehicle to do this.");
                return;
            }

            var engineState = API.Shared.GetVehicleEngineStatus(vehicleHandle);
            var vehAccess   = DoesPlayerHaveVehicleAccess(player, vehicle);

            if (!engineState)
            {
                if (vehicle.Fuel <= 0)
                {
                    API.Shared.SendChatMessageToPlayer(player, "The vehicle has no fuel.");
                    return;
                }
            }

            if (API.Shared.GetVehicleClass(vehicle.VehModel) == 13) // Cycles
            {
                API.Shared.SendChatMessageToPlayer(player, "The vehicle has no engine.");
                return;
            }

            if (vehAccess)
            {
                if (engineState)
                {
                    API.Shared.SetVehicleEngineStatus(vehicleHandle, false);
                    ChatManager.RoleplayMessage(character, "turns off the vehicle engine.", ChatManager.RoleplayMe);
                    OnVehicleEngineToggle?.Invoke(player, vehicleHandle, false);
                }
                else
                {
                    API.Shared.SetVehicleEngineStatus(vehicleHandle, true);
                    ChatManager.RoleplayMessage(character, "turns on the vehicle engine.", ChatManager.RoleplayMe);
                    OnVehicleEngineToggle?.Invoke(player, vehicleHandle, true);
                }
            }
            else
            {
                API.Shared.SendChatMessageToPlayer(player, "You don't have access to this vehicle.");
            }
        }
Example #7
0
        public void GroupVehiclesLocateCar(Player sender, params object[] arguments)
        {
            Character   character = sender.GetCharacter();
            GameVehicle gVeh      =
                VehicleManager.Vehicles.Single(
                    x => x.Entity.Value == Convert.ToInt32(arguments[0]) && x.GroupId == character.GroupId);
            Vector3 location = NAPI.Entity.GetEntityPosition(gVeh.Entity);

            NAPI.ClientEvent.TriggerClientEvent(sender, "myvehicles_setCheckpointToCar", location.X, location.Y, location.Z);
            NAPI.Chat.SendChatMessageToPlayer(sender, "A checkpoint has been set to the vehicle.");
        }
Example #8
0
        public static int despawn_vehicle(GameVehicle veh)
        {
            var returnCode = veh.Despawn();

            if (returnCode == 1)
            {
                API.Shared.ResetEntityData(veh.Entity, "Vehicle");
            }

            return(returnCode);
        }
Example #9
0
        public void MyVehiclesLocateCar(Client sender, params object[] arguments)
        {
            Character   character = sender.GetCharacter();
            GameVehicle lcVeh     =
                VehicleManager.Vehicles.Single(
                    x => x.NetHandle.Value == Convert.ToInt32(arguments[0]) && x.OwnerId == character.Id);
            Vector3 loc = NAPI.Entity.GetEntityPosition(lcVeh.NetHandle);

            NAPI.ClientEvent.TriggerClientEvent(sender, "myvehicles_setCheckpointToCar", loc.X, loc.Y, loc.Z);
            NAPI.Chat.SendChatMessageToPlayer(sender, "A checkpoint has been set to the vehicle.");
        }
Example #10
0
 public void OnPlayerExitVehicle(Player player, Vehicle vehicle)
 {
     if (NAPI.Data.HasEntityData(player, "FUELING_VEHICLE"))
     {
         var vehEntity = NAPI.Data.GetEntityData(player, "FUELING_VEHICLE");
         NAPI.Chat.SendChatMessageToPlayer(player, "Refuel ended.");
         GameVehicle veh = NAPI.Data.GetEntityData(vehEntity, "Vehicle");
         veh.FuelingTimer?.Dispose();
         player.TriggerEvent("freezePlayer", false);
         veh.Save();
     }
 }
Example #11
0
        public void MyVehiclesAbandonCar(Player sender, params object[] arguments)
        {
            Character   character = sender.GetCharacter();
            GameVehicle 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();
            NAPI.Chat.SendChatMessageToPlayer(sender,
                                              $"You have sucessfully abandoned your ~r~{returnCorrDisplayName(acVeh.VehModel)}~w~");
        }
Example #12
0
        public void PickupWood(Client player)
        {
            var character = player.GetCharacter();

            if (character.JobOne.Type != JobManager.JobTypes.Lumberjack)
            {
                NAPI.Notification.SendNotificationToPlayer(player, "You must be a lumberjack.");
                return;
            }

            if (NAPI.Player.IsPlayerInAnyVehicle(player) && API.GetEntityModel(NAPI.Player.GetPlayerVehicle(player)) == (int)VehicleHash.Flatbed)
            {
                GameVehicle vehicle = NAPI.Data.GetEntityData(NAPI.Player.GetPlayerVehicle(player), "Vehicle");
                if (vehicle.Job.Type != JobManager.JobTypes.Lumberjack)
                {
                    NAPI.Chat.SendChatMessageToPlayer(player, "This is not a Lumberjack vehicle.");
                    return;
                }

                if (NAPI.Data.HasEntityData(vehicle.NetHandle, "TREE_OBJ"))
                {
                    NAPI.Chat.SendChatMessageToPlayer(player, "This vehicle is already holding some logs.");
                    return;
                }

                var tree = Tree.Trees.FirstOrDefault(x => x.TreeObj?.Position?.DistanceTo(player.Position) <= 10.0f && x.Stage == Tree.Stages.Waiting);
                if (tree == null || tree?.Stage != Tree.Stages.Waiting)
                {
                    NAPI.Chat.SendChatMessageToPlayer(player, "You aren't near a tree.");
                    return;
                }

                tree.Stage = Tree.Stages.Moving;
                tree.UpdateTreeText();
                API.AttachEntityToEntity(tree.TreeObj, NAPI.Player.GetPlayerVehicle(player), "bodyshell", new Vector3(0, -1.5, 0.3), new Vector3(0, 0, 0));

                ChatManager.RoleplayMessage(player, "picks up the woods into the truck.", ChatManager.RoleplayMe);

                NAPI.ClientEvent.TriggerClientEvent(player, "update_beacon", character.JobOne.MiscOne.Location);


                NAPI.Data.SetEntityData(vehicle.NetHandle, "TREE_OBJ", tree);
                NAPI.Data.SetEntityData(vehicle.NetHandle, "TREE_DRIVER", character.Id);
                NAPI.Chat.SendChatMessageToPlayer(player, "Go to the HQ to sell your wood.");
            }
            else
            {
                NAPI.Chat.SendChatMessageToPlayer(player, "You have to be in a truck to pickup the wood.");
            }
        }
Example #13
0
        public void SellWoodCmd(Client player)
        {
            var character = player.GetCharacter();

            if (character.JobOne.Type != JobManager.JobTypes.Lumberjack)
            {
                NAPI.Notification.SendNotificationToPlayer(player, "You must be a lumberjack.");
                return;
            }

            if (character.JobZoneType != 2 || JobManager.GetJobById(character.JobZone).Type != JobManager.JobTypes.Lumberjack)
            {
                NAPI.Chat.SendChatMessageToPlayer(player, Color.White, "You are not near the sell wood point!");
                return;
            }

            if (NAPI.Player.IsPlayerInAnyVehicle(player) && API.GetEntityModel(NAPI.Player.GetPlayerVehicle(player)) ==
                (int)VehicleHash.Flatbed)
            {
                Tree tree = NAPI.Data.GetEntityData(NAPI.Player.GetPlayerVehicle(player), "TREE_OBJ");
                if (tree == null)
                {
                    NAPI.Chat.SendChatMessageToPlayer(player, "You dont have any wood on your vehicle.");
                    return;
                }

                tree.Stage = Tree.Stages.Hidden;
                tree.UpdateAllTree();
                tree.RespawnTimer          = new Timer(1.8e+6);
                tree.RespawnTimer.Elapsed += tree.RespawnTimer_Elapsed;
                tree.RespawnTimer.Start();

                GameVehicle vehicle = NAPI.Data.GetEntityData(NAPI.Player.GetPlayerVehicle(player), "Vehicle");
                NAPI.Data.ResetEntityData(NAPI.Player.GetPlayerVehicle(player), "TREE_OBJ");
                Task.Delay(1000).ContinueWith(t => API.WarpPlayerOutOfVehicle(player)); // CONV NOTE: delay fixme
                VehicleManager.respawn_vehicle(vehicle);
                NAPI.Data.ResetEntityData(NAPI.Player.GetPlayerVehicle(player), "TREE_DRIVER");
                NAPI.ClientEvent.TriggerClientEvent(player, "update_beacon", new Vector3());

                InventoryManager.GiveInventoryItem(player.GetCharacter(), new Money(), 350, true);
                NAPI.Chat.SendChatMessageToPlayer(player, "* You have sucessfully sold your wood for ~g~$350");
                LogManager.Log(LogManager.LogTypes.Stats, $"[Job] {character.CharacterName}[{player.GetAccount().AccountName}] has earned $200 from selling wood.");

                SettingsManager.Settings.WoodSupplies += 50;
            }
        }
Example #14
0
        public void RespawnTaxi(Character character, GameVehicle veh)
        {
            if (API.IsPlayerConnected(character.Client))
            {
                NAPI.Chat.SendChatMessageToPlayer(character.Client, Color.Yellow, "[TAXI] You were out of your taxi for too long and have taken off-duty. The taxi has been respawned.");

                if (OnDutyDrivers.Contains(character))
                {
                    character.TaxiDuty = false;
                }
                SendMessageToOnDutyDrivers(character.rp_name() + " has gone off of taxi duty.");
            }

            NAPI.Vehicle.SetVehicleEngineStatus(veh.NetHandle, false);
            veh.CustomRespawnTimer.Stop();
            VehicleManager.respawn_vehicle(veh);
        }
Example #15
0
        public static bool DoesPlayerHaveVehicleParkLockAccess(Player player, GameVehicle vehicle)
        {
            Account   account   = player.GetAccount();
            Character character = player.GetCharacter();

            if (account.AdminLevel >= 3 && account.AdminDuty)
            {
                return(true);
            }
            if (character.Id == vehicle.OwnerId)
            {
                return(true);
            }
            if (vehicle.GroupId == character.GroupId && character.GroupId != 0)
            {
                return(true);
            }
            return(false);
        }
Example #16
0
        public void OnPlayerEnterVehicle(Client player, Vehicle vehicle, sbyte seat)
        {
            if (vehicle.GetVehicle() == null)
            {
                return;
            }

            if (API.GetEntityModel(vehicle) == (int)VehicleHash.Flatbed && player.GetCharacter().JobOne.Type == JobManager.JobTypes.Lumberjack)
            {
                GameVehicle veh = NAPI.Data.GetEntityData(vehicle, "Vehicle");
                if (veh.Job?.Type != JobManager.JobTypes.Lumberjack)
                {
                    return;
                }

                Tree tree = NAPI.Data.GetEntityData(vehicle, "TREE_OBJ");
                if (tree == null)
                {
                    return;
                }

                if (NAPI.Data.HasEntityData(vehicle, "TREE_DRIVER"))
                {
                    int id = NAPI.Data.GetEntityData(vehicle, "TREE_DRIVER");
                    if (id != player.GetCharacter().Id)
                    {
                        //API.Delay(1000, true, () => API.WarpPlayerOutOfVehicle(player));
                        Task.Delay(1000).ContinueWith(t => API.WarpPlayerOutOfVehicle(player)); // CONV NOTE: delay fixme
                        NAPI.Chat.SendChatMessageToPlayer(player, "This is not yours.");
                        return;
                    }
                }

                if (NAPI.Data.HasEntityData(vehicle, "Tree_Cancel_Timer"))
                {
                    System.Threading.Timer timer = NAPI.Data.GetEntityData(vehicle, "Tree_Cancel_Timer");
                    timer.Dispose();
                    NAPI.Data.ResetEntityData(vehicle, "Tree_Cancel_Timer");
                    NAPI.Chat.SendChatMessageToPlayer(player, "You've got back into your vehicle.");
                }
            }
        }
Example #17
0
        public static GameVehicle CreateVehicle(VehicleHash model, Vector3 pos, Vector3 rot, string license, int ownerid, int vehtype, int color1 = 0, int color2 = 0, int dimension = 0)
        {
            var veh = new GameVehicle
            {
                VehModel = model,
                SpawnPos = pos,
                SpawnRot = rot,
                VehMods  = new Dictionary <string, string>()
                {
                    [ModdingManager.PrimaryColorId.ToString()] = color1.ToString(), [ModdingManager.SecondryColorId.ToString()] = color2.ToString()
                },
                SpawnDimension = dimension,
                LicensePlate   = license,
                OwnerId        = ownerid,
                VehType        = vehtype
            };

            Vehicles.Add(veh);
            return(veh);
        }
Example #18
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 });
        }
Example #19
0
        public void confirmsellvehicle_cmd(Player player)
        {
            Character character = player.GetCharacter();
            var       data      = NAPI.Data.GetEntityData(player, "sellcar_selling");

            if (data != null)
            {
                GameVehicle veh    = data[0];
                Character   target = data[1];
                int         price  = data[2];
                NAPI.Data.SetEntityData(target.Player, "sellcar_buying", new dynamic[] { character, veh, price });
                NAPI.Data.SetEntityData(player, "sellcar_selling", null);
                NAPI.Chat.SendChatMessageToPlayer(target.Player,
                                                  $"~r~{character.rp_name()}~w~ has offered to sell you a ~r~{returnCorrDisplayName(veh.VehModel)}~w~ for ~r~${price}~w~.");
                NAPI.Chat.SendChatMessageToPlayer(target.Player, "Use /confirmbuyvehicle to buy it.");
                NAPI.Chat.SendChatMessageToPlayer(player, "Request sent.");
            }
            else
            {
                NAPI.Chat.SendChatMessageToPlayer(player, "You aren't selling any car.");
            }
        }
Example #20
0
        public void OnPlayerExitVehicle(Client player, Vehicle vehicle)
        {
            if (API.GetEntityModel(vehicle) == (int)VehicleHash.Flatbed && player.GetCharacter().JobOne.Type == JobManager.JobTypes.Lumberjack)
            {
                GameVehicle veh = NAPI.Data.GetEntityData(vehicle, "Vehicle");
                if (veh.Job.Type != JobManager.JobTypes.Lumberjack)
                {
                    return;
                }

                Tree tree = NAPI.Data.GetEntityData(vehicle, "TREE_OBJ");
                if (tree == null)
                {
                    return;
                }

                NAPI.Data.SetEntityData(vehicle, "Tree_Cancel_Timer", new System.Threading.Timer(state =>
                {
                    GameVehicle vehN = NAPI.Data.GetEntityData(vehicle, "Vehicle");
                    Tree ttree       = NAPI.Data.GetEntityData(vehicle, "TREE_OBJ");
                    if (ttree == null)
                    {
                        return;
                    }
                    ttree.Stage = Tree.Stages.Cutting;
                    ttree.UpdateAllTree();

                    NAPI.Data.ResetEntityData(vehicle, "TREE_OBJ");
                    vehN.Respawn();
                    NAPI.Data.ResetEntityData(vehicle, "Tree_Cancel_Timer");
                    NAPI.Data.ResetEntityData(vehicle, "TREE_DRIVER");
                    NAPI.Chat.SendChatMessageToPlayer(player, "Wood run cancelled.");
                    NAPI.ClientEvent.TriggerClientEvent(player, "update_beacon", new Vector3());
                }, null, 60000, Timeout.Infinite));
                NAPI.Chat.SendChatMessageToPlayer(player, "You've got 1 minute to get back to your vehicle or the wood will be reset.");
            }
        }
Example #21
0
 public static int spawn_vehicle(GameVehicle veh)
 {
     return(spawn_vehicle(veh, veh.SpawnPos));
 }
Example #22
0
        private void FuelVeh(Player playerEntity, Vehicle vehEntity)
        {
            if (vehEntity.IsNull)
            {
                return;
            }

            GameVehicle veh = NAPI.Data.GetEntityData(vehEntity, "Vehicle");

            if (veh == null)
            {
                return;
            }

            if (playerEntity == null)
            {
                veh.FuelingTimer?.Dispose();
                NAPI.Data.ResetEntityData(vehEntity, "PENDING_FUEL");
                return;
            }

            Character c = playerEntity.GetCharacter();

            if (c == null)
            {
                veh.FuelingTimer?.Dispose();
                NAPI.Data.ResetEntityData(vehEntity, "PENDING_FUEL");
                return;
            }

            if (NAPI.Vehicle.GetVehicleEngineStatus(vehEntity))
            {
                veh.FuelingTimer?.Dispose();
                NAPI.Data.ResetEntityData(vehEntity, "PENDING_FUEL");
                NAPI.Data.ResetEntityData(playerEntity, "FUELING_VEHICLE");
                playerEntity.TriggerEvent("freezePlayer", false);
                NAPI.Chat.SendChatMessageToPlayer(playerEntity, "Refuel has been cancelled cause the engine has turned on.");
                veh.Save();
                return;
            }

            int pendingFuel = NAPI.Data.GetEntityData(vehEntity, "PENDING_FUEL") ?? 0;

            if (pendingFuel <= 0 || veh.RefuelProp.Supplies <= 0)
            {
                NAPI.ClientEvent.TriggerClientEvent(playerEntity, "fuel_updatevalue", veh.Fuel);
                veh.FuelingTimer?.Dispose();
                NAPI.Data.ResetEntityData(vehEntity, "PENDING_FUEL");
                NAPI.Data.ResetEntityData(playerEntity, "FUELING_VEHICLE");
                playerEntity.TriggerEvent("freezePlayer", false);

                if (veh.RefuelProp.Supplies <= 0)
                {
                    NAPI.Chat.SendChatMessageToPlayer(playerEntity, "The gas station ran out of gas.");
                }
                else if (pendingFuel <= 0)
                {
                    NAPI.Chat.SendChatMessageToPlayer(playerEntity, "Refueling finished.");
                }

                veh.Save();
                return;
            }

            if (pendingFuel < 10)
            {
                veh.Fuel    += pendingFuel;
                pendingFuel -= pendingFuel;
                if (c.Group.CommandType != group_manager.Group.CommandTypeLspd)
                {
                    InventoryManager.DeleteInventoryItem <Money>(c, pendingFuel * veh.RefuelProp.ItemPrices["gas"]);
                }
                veh.RefuelProp.Supplies--;
            }
            else
            {
                veh.Fuel    += 10;
                pendingFuel -= 10;
                if (c.Group.CommandType != group_manager.Group.CommandTypeLspd)
                {
                    InventoryManager.DeleteInventoryItem <Money>(c, 10 * veh.RefuelProp.ItemPrices["gas"]);
                }
                veh.RefuelProp.Supplies--;
            }

            NAPI.ClientEvent.TriggerClientEvent(playerEntity, "fuel_updatevalue", veh.Fuel);
            NAPI.Data.SetEntityData(vehEntity, "PENDING_FUEL", pendingFuel);
        }
Example #23
0
        public void OnVehicleMenuTrigger(Player player, params object[] arguments)
        {
            var vehicleHandle = (Entity)arguments[0];
            var option        = (string)arguments[1];

            Character   character = player.GetCharacter();
            GameVehicle vehicle   = API.Shared.GetEntityData(vehicleHandle, "Vehicle");

            var playerSeat = API.Shared.GetPlayerVehicleSeat(player);

            //Check that player vehicle is the same as the menu vehicle...
            if (API.Shared.GetPlayerVehicle(player) != vehicleHandle)
            {
                DebugManager.DebugMessage("[VehicleMenu] " + character.CharacterName + "(" + player.SocialClubName + ", " + player + ") used VehicleMenu option in a different vehicle handle.");
                return;
            }

            var vehAccess  = VehicleManager.DoesPlayerHaveVehicleAccess(player, vehicle);
            var parkAccess = VehicleManager.DoesPlayerHaveVehicleParkLockAccess(player, vehicle);

            if ((option.Equals("park") || option.Equals("lock")) && !parkAccess)
            {
                API.Shared.SendChatMessageToPlayer(player, "~r~ You do not have access to this vehicle.");
                return;
            }

            if ((option.Equals("engine") || option.Equals("park")) && playerSeat != -1)
            {
                API.Shared.SendChatMessageToPlayer(player, "~r~ You can only access these options in the driver seat.");
                return;
            }

            switch (option)
            {
            case "engine":
                if (vehAccess)
                {
                    VehicleManager.engine_cmd(player);
                }
                else
                {
                    VehicleManager.hotwire_cmd(player);
                }
                break;

            case "lock":
                var lockState = API.Shared.GetVehicleLocked(vehicleHandle);

                if (lockState)
                {
                    API.Shared.SetVehicleLocked(vehicleHandle, false);
                    ChatManager.RoleplayMessage(character, "unlocks the doors of the vehicle.", ChatManager.RoleplayMe);
                }
                else
                {
                    API.Shared.SetVehicleLocked(vehicleHandle, true);
                    ChatManager.RoleplayMessage(character, "locks the doors of the vehicle.", ChatManager.RoleplayMe);
                }


                break;

            case "park":

                var pos       = NAPI.Entity.GetEntityPosition(vehicleHandle);
                var rot       = NAPI.Entity.GetEntityRotation(vehicleHandle);
                var dimension = NAPI.Entity.GetEntityDimension(vehicleHandle);

                vehicle.SpawnPos       = pos;
                vehicle.SpawnRot       = rot;
                vehicle.SpawnDimension = (int)dimension;

                vehicle.Save();

                API.Shared.SendChatMessageToPlayer(player, "Car spawn location saved to current location.");
                break;

            case "door":
                var doorIndex = (int)arguments[2];

                var doorName = "";
                switch (doorIndex)
                {
                case 0:
                    doorName = "front left door";
                    break;

                case 1:
                    doorName = "front right door";
                    break;

                case 2:
                    doorName = "back left door";
                    break;

                case 3:
                    doorName = "back right door";
                    break;

                case 4:
                    doorName = "hood";
                    break;

                case 5:
                    doorName = "trunk";
                    break;
                }

                var doorState = API.GetVehicleDoorState(vehicleHandle, doorIndex);

                if (doorState)
                {
                    API.SetVehicleDoorState(vehicleHandle, doorIndex, false);
                    ChatManager.RoleplayMessage(character, "closed the " + doorName + " of the vehicle.", ChatManager.RoleplayMe);
                }
                else
                {
                    API.SetVehicleDoorState(vehicleHandle, doorIndex, true);
                    ChatManager.RoleplayMessage(character, "opened the " + doorName + " of the vehicle.", ChatManager.RoleplayMe);
                }

                break;
            }
        }
Example #24
0
        public void Refuel(Player player, int fuel = 0)
        {
            var prop = PropertyManager.IsAtPropertyInteraction(player);

            if (prop?.Type == PropertyManager.PropertyTypes.GasStation)
            {
                if (NAPI.Player.IsPlayerInAnyVehicle(player) && NAPI.Player.GetPlayerVehicleSeat(player) == -1)
                {
                    var         vehEntity = player.Vehicle;
                    GameVehicle veh       = NAPI.Data.GetEntityData(vehEntity, "Vehicle");

                    if (NAPI.Vehicle.GetVehicleEngineStatus(vehEntity))
                    {
                        NAPI.Chat.SendChatMessageToPlayer(player, "Vehicle engine must be off.");
                        return;
                    }

                    if (player.HasData("FUELING_VEHICLE"))
                    {
                        NAPI.Chat.SendChatMessageToPlayer(player, "You're already refueling a vehicle.");
                        return;
                    }

                    if (fuel == 0)
                    {
                        fuel = 100 - veh.Fuel;
                    }

                    var pendingFuel = fuel;

                    if (pendingFuel > 100 || pendingFuel + veh.Fuel > 100 || pendingFuel < 0)
                    {
                        NAPI.Chat.SendChatMessageToPlayer(player, "Vehicle fuel can't be above 100 or negative.");
                        return;
                    }

                    if (Money.GetCharacterMoney(player.GetCharacter()) < pendingFuel * prop.ItemPrices["gas"] && player.GetCharacter().Group.CommandType != group_manager.Group.CommandTypeLspd)
                    {
                        NAPI.Chat.SendChatMessageToPlayer(player,
                                                          $"You don't have enough money to get ~r~{pendingFuel}~w~ units of fuel.~n~It's worth ~g~${pendingFuel * prop.ItemPrices["gas"]}~w~.");
                        return;
                    }

                    NAPI.Chat.SendChatMessageToPlayer(player,
                                                      $"You will be charged ~g~${pendingFuel * prop.ItemPrices["gas"]}~w~ for ~r~{pendingFuel}~w~ units of fuel.");
                    player.TriggerEvent("freezePlayer", true);
                    NAPI.Data.SetEntityData(vehEntity, "PENDING_FUEL", pendingFuel);
                    veh.RefuelProp = prop;
                    FuelVeh(player, vehEntity);
                    if (NAPI.Data.HasEntityData(vehEntity, "PENDING_FUEL"))
                    {
                        NAPI.Data.SetEntityData(player, "FUELING_VEHICLE", vehEntity);
                        veh.FuelingTimer = new System.Threading.Timer(FuelVehTimer, new object[] { player, vehEntity }, 3000, 3000);
                        return;
                    }
                }
                else
                {
                    NAPI.Chat.SendChatMessageToPlayer(player, "You must be driving a vehicle.");
                }
            }
            else
            {
                NAPI.Chat.SendChatMessageToPlayer(player, "You must be at a gas station.");
            }
        }
Example #25
0
        public void confirmbuyvehicle_cmd(Player player)
        {
            Character character = player.GetCharacter();
            Account   account   = player.GetAccount();
            var       data      = NAPI.Data.GetEntityData(player, "sellcar_buying");

            if (data != null)
            {
                Character   buyingFrom = data[0];
                GameVehicle veh        = data[1];
                int         price      = data[2];
                //Make sure near him.
                var buyingPos = buyingFrom.Player.Position;
                if (player.Position.DistanceTo(buyingPos) <= 5f)
                {
                    //make sure still have slots.
                    if (character.OwnedVehicles.Count < VehicleManager.GetMaxOwnedVehicles(character.Player))
                    {
                        //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)
                                {
                                    NAPI.Util.ConsoleOutput(
                                        $"There was an error spawning vehicle #{veh.Id} of {character.CharacterName}.");
                                }
                            }

                            //Tell.
                            NAPI.Chat.SendChatMessageToPlayer(player, "You have sucessfully bought the car.");
                            NAPI.Chat.SendChatMessageToPlayer(buyingFrom.Player, "You have successfully sold the car.");
                            NAPI.Data.SetEntityData(player, "sellcar_buying", null);
                        }
                        else
                        {
                            NAPI.Chat.SendChatMessageToPlayer(player, "You don't have enough money.");
                            NAPI.Chat.SendChatMessageToPlayer(buyingFrom.Player, "The buyer doesn't have enough money.");
                            NAPI.Data.SetEntityData(player, "sellcar_buying", null);
                        }
                    }
                    else
                    {
                        NAPI.Chat.SendChatMessageToPlayer(player, "You can't own anymore vehicles.");
                        NAPI.Chat.SendChatMessageToPlayer(buyingFrom.Player, "The buyer can't own anymore vehicles.");
                        NAPI.Data.SetEntityData(player, "sellcar_buying", null);
                    }
                }
                else
                {
                    NAPI.Chat.SendChatMessageToPlayer(player, "You must be near the buyer.");
                    NAPI.Chat.SendChatMessageToPlayer(buyingFrom.Player, "The buyer must be near you.");
                    NAPI.Data.SetEntityData(player, "sellcar_buying", null);
                }
            }
            else
            {
                NAPI.Chat.SendChatMessageToPlayer(player, "You aren't buying any car.");
            }
        }
Example #26
0
 public static void delete_vehicle(GameVehicle veh)
 {
     Vehicles.Remove(veh);
 }
Example #27
0
        public static void hotwire_cmd(Player player)
        {
            if (player.IsInVehicle == false)
            {
                API.Shared.SendChatMessageToPlayer(player, "You are not in a vehicle.");
                return;
            }

            Character   character = player.GetCharacter();
            var         veh       = API.Shared.GetPlayerVehicle(player);
            GameVehicle vehicle   = API.Shared.GetEntityData(veh, "Vehicle");

            if (API.Shared.GetVehicleEngineStatus(veh) == true)
            {
                API.Shared.SendChatMessageToPlayer(player, "This vehicle is already started.");
                return;
            }

            if (API.Shared.GetVehicleClass(vehicle.VehModel) == 13) // Cycles
            {
                API.Shared.SendChatMessageToPlayer(player, "The vehicle has no engine.");
                return;
            }

            if (vehicle.Fuel < 1)
            {
                API.Shared.SendChatMessageToPlayer(player, "This vehicle has no fuel.");
                return;
            }

            if (API.Shared.GetVehicleLocked(veh))
            {
                API.Shared.SendChatMessageToPlayer(player, "The vehicle is locked.");
                return;
            }

            if (character.NextHotWire > DateTime.Now)
            {
                API.Shared.SendChatMessageToPlayer(player, $"You have to wait {character.NextHotWire.Subtract(DateTime.Now).Seconds} more second(s) before attempting to hotwire.");
                return;
            }

            ChatManager.RoleplayMessage(character, "attempts to hotwire the vehicle.", ChatManager.RoleplayMe);

            Random ran = new Random();

            var hotwireChance = ran.Next(100);

            if (hotwireChance < 40)
            {
                API.Shared.SetVehicleEngineStatus(veh, true);
                ChatManager.RoleplayMessage(character, "succeeded in hotwiring the vehicle.", ChatManager.RoleplayMe);
            }
            else
            {
                API.Shared.SetPlayerHealth(player, player.Health - 10);
                player.SendChatMessage("You attempted to hotwire the vehicle and got shocked!");
                ChatManager.RoleplayMessage(character, "failed to hotwire the vehicle.", ChatManager.RoleplayMe);
                character.NextHotWire = DateTime.Now.Add(TimeSpan.FromSeconds(10));
            }
        }