Exemplo n.º 1
0
        /// <summary>
        /// Spawns a ped PedVariable is the model, bool inVehicle is if to spawn in vehicle and int Vehicle is for the vehicle to use, if so
        /// </summary>
        /// <param name="PedVariable"></param>
        /// <param name="inVehicle"></param>
        /// <param name="Vehicle"></param>
        /// <returns></returns>
        public static async Task <int> SpawnPed(string PedVariable, bool inVehicle, int Vehicle)
        {
            var  PedHash        = (uint)GetHashKey(PedVariable);
            bool successFullPed = await CommonFunctionsLib.ModelLoader(PedHash, PedVariable);

            if (!successFullPed)
            {
                // Ped model is invalid.
                if (DebugLog.DebugMode)
                {
                    //Debug.Write($"AlsekLib: Model invalid, Ped not spawning {PedVariable}!");
                    DebugLog.Log($"AlsekLib: Model invalid, Ped not spawning {PedVariable}!", false, false, DebugLog.LogLevel.error);
                }
                return(0);
            }
            else
            {
                if (DebugLog.DebugMode)
                {
                    //Debug.Write($"AlsekLib: Model valid, Ped will spawn {PedVariable}!");
                    DebugLog.Log($"AlsekLib: Model valid, Ped will spawn {PedVariable}!", false, false, DebugLog.LogLevel.success);
                }
                if (inVehicle && AreAnyVehicleSeatsFree(Vehicle))
                {
                    var SeatFree    = false;
                    var SeatFreeNum = -1;
                    var MaxSeats    = GetVehicleMaxNumberOfPassengers(Vehicle);
                    do
                    {
                        if (!IsVehicleSeatFree(Vehicle, SeatFreeNum))
                        {
                            ++SeatFreeNum;
                            if (DebugLog.DebugMode)
                            {
                                //Debug.Write($"Seatfree:: {SeatFreeNum}");
                                DebugLog.Log($"Seatfree:: {SeatFreeNum}", false, false, DebugLog.LogLevel.info);
                            }
                        }
                        else
                        {
                            SeatFree = true;
                            var NPC = CreatePedInsideVehicle(Vehicle, 1, PedHash, SeatFreeNum, true, true);
                            return(NPC);
                        }
                    } while (!SeatFree && SeatFreeNum < MaxSeats);
                }

                if (inVehicle && AreAnyVehicleSeatsFree(Vehicle) == false)
                {
                    //failed
                    return(0);
                }
                else
                {
                    //Make this area?
                    return(0);
                }
            }
        }
Exemplo n.º 2
0
        //spawnVehicle function, returns a cfx "vehicle". vehicleName = model name of vehicle (example:"adder") pos = vector3 coords for spawn, spawnHeading = float for vehicle heading when spawned.
        #region spawnVehicle
        public static async Task <Vehicle> spawnVehicle(string vehicleName, Vector3 pos, float spawnHeading)
        {
            //makes it return 0 if fails
            Vehicle vehicle = new Vehicle(0);
            //gets the name hash
            var  nameHash    = (uint)GetHashKey(vehicleName);
            uint vehicleHash = nameHash;
            //loads the vehicle model
            bool successFull = await CommonFunctionsLib.ModelLoader(vehicleHash, vehicleName);

            if (!successFull || !IsModelAVehicle(vehicleHash))
            {
                // Vehicle model is invalid.
                if (DebugLog.DebugMode)
                {
                    //Debug.Write($"AlsekLib: Model invalid, Vehicle will not spawn. {vehicleName}!");
                    DebugLog.Log($"AlsekLib: Model invalid, Vehicle will not spawn. {vehicleName}!", false, false, DebugLog.LogLevel.error);
                }
                //returns the 0
                return(vehicle);
            }
            else
            {
                if (DebugLog.DebugMode)
                {
                    //Debug.Write($"AlsekLib: Model valid, Vehicle will spawn {vehicleName}!");
                    DebugLog.Log($"AlsekLib: Model valid, Vehicle will spawn {vehicleName}!", false, false, DebugLog.LogLevel.success);
                }
                //actually creates the vehicle
                vehicle = new Vehicle(CreateVehicle(vehicleHash, pos.X, pos.Y, pos.Z + 1f, spawnHeading, true, false))
                {
                    NeedsToBeHotwired       = false,
                    PreviouslyOwnedByPlayer = true,
                    IsPersistent            = true,
                    IsStolen = false,
                    IsWanted = false
                };
                return(vehicle);
            }
        }