void HandleAmbient() { foreach (Ped ped in crowd) { if (ped.IsOnFoot && !ped.IsInCombat && Function.Call<int>(Hash.GET_SEQUENCE_PROGRESS, ped) == -1) { //UI.Notify("Scenario applied, " +ped.Handle.ToString()); Vector3 faceto = GetStartingLine(); TaskSequence dd = new TaskSequence(); Function.Call(GTA.Native.Hash.TASK_TURN_PED_TO_FACE_COORD, 0, faceto.X, faceto.Y, faceto.Z, 2000); Function.Call(GTA.Native.Hash.TASK_START_SCENARIO_IN_PLACE, 0, GetRandomAmbientScenario(), -1, false); dd.Close(); ped.Task.PerformSequence(dd); dd.Dispose(); } } foreach (Ped ped in waitingdrivers) { Function.Call(Hash.SET_SCENARIO_PEDS_TO_BE_RETURNED_BY_NEXT_COMMAND, true); if (ped.IsOnFoot && !ped.IsInCombat && Function.Call<int>(Hash.GET_SEQUENCE_PROGRESS, ped) == -1 && Function.Call<bool>(Hash.IS_PED_USING_ANY_SCENARIO, countdownped) == false) { Vector3 faceto = GetWaitingZone(); TaskSequence dd = new TaskSequence(); Function.Call(GTA.Native.Hash.TASK_TURN_PED_TO_FACE_COORD, 0, faceto.X, faceto.Y, faceto.Z, 2000); Function.Call(GTA.Native.Hash.TASK_START_SCENARIO_IN_PLACE, 0, GetRandomAmbientDriverScenario(), 0, false); dd.Close(); ped.Task.PerformSequence(dd); dd.Dispose(); } } }
void HandleDragRace() { FixStuckDrivers(); switch (DragPhase) { case "MeetNotStarted": { SpawnCountDownPed(); SpawnCrowd(); SpawnDriversFromFile(); SpawnParkedVehicles(); DragPhase = "MeetJustStarted"; NotifiedMeets.Clear(); HandleAmbient(); finish = World.CreateProp("prop_offroad_barrel01", GetFinishLine()+ new Vector3(0, 0,3), new Vector3(0, 0, GetRaceHeading()), false, true); finish.IsPersistent = true; Function.Call(GTA.Native.Hash._0x0DC7CABAB1E9B67E, finish, true); //Load Collision return; } case "MeetJustStarted": { foreach (Vehicle veh in ambientvehicles) { if (veh.DisplayName == "MOONBEAM2" || veh.DisplayName == "FACTION2") { SetRadioLoud(veh); } } //AddNewCarsToMeet(); //Doesn't work properly for now if (drivers.Count == 2) { CountDownGuyIsInPos(); DragPhase = "RacersGoingToStartPos"; leftdriver = drivers[0]; } else { GetNextDriverPair(); } return; } case "RacersGoingToStartPos": { if (AreDriversInStartingLine() == true) { if (CountDownGuyIsInPos() == true) { DragSetupPatience = 0; DragPhase = "RaceCountDown"; if (CanWeUse(countdownped)) { Vector3 faceto = GetStartingLine(); TaskSequence dd = new TaskSequence(); Function.Call(GTA.Native.Hash.TASK_SWAP_WEAPON, 0, true); Function.Call(GTA.Native.Hash.TASK_TURN_PED_TO_FACE_COORD, 0, faceto.X, faceto.Y, faceto.Z, 2000); dd.Close(); countdownped.Task.PerformSequence(dd); dd.Dispose(); } } } else { if (IsPlayerNearStartingLine() || countdownped.IsOnScreen) { DragSetupPatience++; if (DragSetupPatience > 15) { DragSetupPatience = 0; foreach (Ped driver in drivers) { Function.Call(GTA.Native.Hash.SET_VEHICLE_FIXED, GetLastVehicle(driver)); Function.Call(GTA.Native.Hash.SET_VEHICLE_DEFORMATION_FIXED, GetLastVehicle(driver)); if (driver.Handle == drivers[0].Handle) { if (!GetLastVehicle(driver).IsInRangeOf(GetStartingPoint("Left"), 3f)) { GetLastVehicle(driver).Position = GetSequenceToStartingPos("Left")[0]; } } else { if (!GetLastVehicle(driver).IsInRangeOf(GetStartingPoint("Right"), 3f)) { GetLastVehicle(driver).Position = GetSequenceToStartingPos("Right")[0]; } } GetLastVehicle(driver).Heading = GetRaceHeading(); driver.Task.EnterVehicle(GetLastVehicle(driver), VehicleSeat.Driver, -1); } } } else { foreach (Ped driver in drivers) { Function.Call(GTA.Native.Hash.SET_VEHICLE_FIXED, GetLastVehicle(driver)); Function.Call(GTA.Native.Hash.SET_VEHICLE_DEFORMATION_FIXED, GetLastVehicle(driver)); driver.Task.ClearAll(); if (driver.CurrentVehicle == null) { driver.SetIntoVehicle(GetLastVehicle(driver), VehicleSeat.Driver); } if (driver.Handle == drivers[0].Handle) { if (!GetLastVehicle(driver).IsInRangeOf(GetStartingPoint("Left"), 3f)) { GetLastVehicle(driver).Position = GetStartingPoint("Left"); } } else { if (!GetLastVehicle(driver).IsInRangeOf(GetStartingPoint("Right"), 3f)) { GetLastVehicle(driver).Position = GetStartingPoint("Right"); } } GetLastVehicle(driver).Heading = GetRaceHeading(); driver.Task.EnterVehicle(GetLastVehicle(driver), VehicleSeat.Driver, -1); } } } return; } case "RaceCountDown": { IsBarrelWhereItShould(); if (AreDriversInStartingLine() == true && !Game.Player.Character.IsInRangeOf(GetStartingLine(), GetStartingLineRadius() / 2f)) { if (CanWeUse(countdownped)) { Vector3 aim = countdownped.Position + countdownped.ForwardVector + countdownped.UpVector * 2; Vector3 faceto = GetFinishLine(); TaskSequence dd = new TaskSequence(); Function.Call(GTA.Native.Hash.TASK_SHOOT_AT_COORD, 0, aim.X, aim.Y, aim.Z, 500, GetHash("FIRING_PATTERN_BURST_FIRE_PISTOL")); Function.Call(GTA.Native.Hash.TASK_TURN_PED_TO_FACE_COORD, 0, faceto.X, faceto.Y, faceto.Z, 2000); dd.Close(); countdownped.Task.PerformSequence(dd); dd.Dispose(); } string side; foreach (Ped driver in drivers) { if (GetLastVehicle(driver).Heading - GetRaceHeading() > 20f) { GetLastVehicle(driver).Heading = GetRaceHeading(); } if (unpredictable_races) { if (RandomInt(0,2)==3) { Function.Call(Hash._SET_VEHICLE_ENGINE_POWER_MULTIPLIER, GetLastVehicle(driver), RandomFloat(0, 1)); UI.Notify(RandomFloat(0, 1).ToString()); } else { Function.Call(Hash._SET_VEHICLE_ENGINE_POWER_MULTIPLIER, GetLastVehicle(driver), RandomInt(1, 10)); } } float speed = 80f; if (driver == drivers[0]) { side = "Left"; } else { side = "Right"; } TaskSequence RaceSequence = new TaskSequence(); foreach (Vector3 pos in GetSequenceToEnd(side)) { if (unpredictable_races) { Function.Call(Hash.TASK_PAUSE, 0, RandomInt(0, 800)); } Function.Call(Hash.TASK_VEHICLE_DRIVE_TO_COORD_LONGRANGE, 0, GetLastVehicle(driver), pos.X, pos.Y, pos.Z, speed, 16777236, 5f); speed = 10; } RaceSequence.Close(); driver.Task.PerformSequence(RaceSequence); RaceSequence.Dispose(); } DragPhase = "RaceInProgress"; RaceInProgress = true; } return; } case "RaceInProgress": { if (HaveDriversFinished()) { Function.Call(Hash._SET_VEHICLE_ENGINE_POWER_MULTIPLIER, GetLastVehicle(drivers[0]), 0f); Function.Call(Hash._SET_VEHICLE_ENGINE_POWER_MULTIPLIER, GetLastVehicle(drivers[1]), 0f); if (IsPlayerNearFinishgLine() || IsPlayerNearStartingLine()) { UI.Notify("~g~The " + GetLastVehicle(winner).FriendlyName + " won!"); } DriveRacersToTheWaitingArea(); DragPhase = "RaceFinished"; RaceInProgress = false; Vector3 faceto = GetStartingLine(); TaskSequence countdownguysequence = new TaskSequence(); Function.Call(GTA.Native.Hash.TASK_TURN_PED_TO_FACE_COORD, 0, faceto.X, faceto.Y, faceto.Z, 2000); Function.Call(GTA.Native.Hash.TASK_RELOAD_WEAPON, 0, true); countdownguysequence.Close(); countdownped.Task.PerformSequence(countdownguysequence); countdownguysequence.Dispose(); if (CanWeUse(betondriver)) { if (winner.Handle == betondriver.Handle) { UI.Notify("~g~You won the bet!"); Game.Player.Money = Game.Player.Money + 200; PedsCongratulatePlayer(); } else { UI.Notify("~r~You lost the bet."); Game.Player.Money = Game.Player.Money - 200; } betondriver = null; } GetNextDriverPair(); AreDriversInStartingLine(); } return; } case "RaceFinished": { winner = null; DragPhase = "MeetJustStarted"; return; } } }
void DriveThisManToItsStartingPos(Ped driver) { string side; if (driver.Handle == drivers[0].Handle) { side = "Left"; } else { side = "Right"; } Vector3 waitingcenter = GetStartingLine(); TaskSequence RaceSequence = new TaskSequence(); Function.Call(GTA.Native.Hash.TASK_ENTER_VEHICLE, 0, GetLastVehicle(driver), -1, -1, 2f, 1, false); /* if (Function.Call<Vector3>(GTA.Native.Hash.GET_OFFSET_FROM_ENTITY_GIVEN_WORLD_COORDS, GetLastVehicle(driver), waitingcenter.X, waitingcenter.Y, waitingcenter.Z).Y < 0) { RaycastResult back = RaycastDrive(GetLastVehicle(driver).Position + (GetLastVehicle(driver).ForwardVector * -3), GetLastVehicle(driver).Position + (GetLastVehicle(driver).ForwardVector * -20)); Vector3 pos = GetLastVehicle(driver).Position + (GetLastVehicle(driver).ForwardVector * -10); if (back.DitHitAnything) { pos = back.HitCoords; } Function.Call(Hash.TASK_VEHICLE_DRIVE_TO_COORD_LONGRANGE, 0, GetLastVehicle(driver), pos.X, pos.Y, pos.Z, 4f, 16778240, 2f); } */ foreach (Vector3 pos in GetSequenceToStartingPos(side)) { Function.Call(Hash.TASK_VEHICLE_DRIVE_TO_COORD_LONGRANGE, 0, GetLastVehicle(driver), pos.X, pos.Y, pos.Z, 4f, 4194357, 3f); } Vector3 startpoint = GetStartingPoint(side); Function.Call(GTA.Native.Hash.TASK_VEHICLE_PARK, 0, GetLastVehicle(driver), startpoint.X, startpoint.Y, startpoint.Z, GetRaceHeading(), 1, 10f, true); RaceSequence.Close(); driver.Task.PerformSequence(RaceSequence); RaceSequence.Dispose(); }
void DriveThisPedToTheMeetingArea(Ped ped) { if (CanWeUse(ped) && CanWeUse(GetLastVehicle(ped))) { AddToWaitingList(ped); Vector3 random = GetWaitingZone().Around(GetWaitingZoneRadius() * (RandomInt(3, 8) / 10.0f)); Vector3 waitingzone = GetWaitingZone().Around(GetWaitingZoneRadius() * (RandomInt(4,10) / 10.0f)); int how= 262199; if (ped.IsInRangeOf(GetWaitingZone(), 40f)) { how = 4194365; } TaskSequence RaceSequence = new TaskSequence(); Function.Call(Hash.TASK_VEHICLE_DRIVE_TO_COORD, 0, GetLastVehicle(ped), waitingzone.X, waitingzone.Y, waitingzone.Z, 10f, true, GetLastVehicle(ped).GetHashCode(), how, 5f, 0f); Function.Call(Hash.TASK_LEAVE_VEHICLE, 0, GetLastVehicle(ped), 0); Function.Call(Hash.TASK_FOLLOW_NAV_MESH_TO_COORD, 0, random.X, random.Y, random.Z, 1.0f, -1, 0.0f, 0, 0.0f); RaceSequence.Close(); ped.Task.PerformSequence(RaceSequence); RaceSequence.Dispose(); } }
void DriveRacersToTheWaitingArea() { string side; foreach (Ped driver in drivers) { Vector3 random = GetWaitingZone().Around(GetWaitingZoneRadius() * (RandomInt(3,8) / 10.0f)); Vector3 nearwaitingzone = GetWaitingZone().Around(GetWaitingZoneRadius() * (RandomInt(4, 10) / 10.0f)); Vector3 waitingzone = GetWaitingZone(); AddToWaitingList(driver); if (driver == drivers[0]) { side = "Left"; } else { side = "Right"; } TaskSequence RaceSequence = new TaskSequence(); foreach (Vector3 pos in GetSequenceToWaitingZone(side)) { Function.Call(Hash.TASK_VEHICLE_DRIVE_TO_COORD_LONGRANGE, 0, GetLastVehicle(driver), pos.X, pos.Y, pos.Z, 10f, 4194365, 4f); } Function.Call(Hash.TASK_VEHICLE_DRIVE_TO_COORD_LONGRANGE, 0, GetLastVehicle(driver), nearwaitingzone.X, nearwaitingzone.Y, nearwaitingzone.Z, 3f, 4194365,5f); Function.Call(Hash.TASK_LEAVE_VEHICLE, 0, GetLastVehicle(driver), 0); Function.Call(Hash.TASK_FOLLOW_NAV_MESH_TO_COORD, 0, random.X, random.Y, random.Z, 1.0f, -1, 0.0f, 0, 0.0f); RaceSequence.Close(); driver.Task.PerformSequence(RaceSequence); RaceSequence.Dispose(); } drivers.Clear(); }
bool CountDownGuyIsInPos() { if (countdownped.IsInRangeOf(GetCountDownGuyPos(), 2f)) { return true; } else { if (IsPlayerNearStartingLine()) { Vector3 pos = GetCountDownGuyPos(); Vector3 faceto = GetStartingLine(); TaskSequence RaceSequence = new TaskSequence(); Function.Call(Hash.TASK_FOLLOW_NAV_MESH_TO_COORD, 0, pos.X, pos.Y, pos.Z, 1.0f, -1, 0.0f, 0, 0.0f); Function.Call(GTA.Native.Hash.TASK_TURN_PED_TO_FACE_COORD, 0, faceto.X, faceto.Y, faceto.Z, 2000); RaceSequence.Close(); countdownped.Task.PerformSequence(RaceSequence); RaceSequence.Dispose(); } else { countdownped.Position = GetCountDownGuyPos(); } return false; } }
void CleanMeet() { foreach (Ped driver in drivers) { GetLastVehicle(driver).IsPersistent=false; driver.IsPersistent = false; Vector3 pos = driver.Position.Around(900f); TaskSequence RaceSequence = new TaskSequence(); Function.Call(Hash.TASK_VEHICLE_DRIVE_TO_COORD_LONGRANGE, 0, GetLastVehicle(driver), pos.X, pos.Y, pos.Z, 300f, 262196, 2f); RaceSequence.Close(); driver.Task.PerformSequence(RaceSequence); RaceSequence.Dispose(); } foreach (Ped driver in waitingdrivers) { GetLastVehicle(driver).IsPersistent = false; driver.IsPersistent = false; Vector3 pos = driver.Position.Around(900f); TaskSequence RaceSequence = new TaskSequence(); Function.Call(Hash.TASK_VEHICLE_DRIVE_TO_COORD_LONGRANGE, 0, GetLastVehicle(driver), pos.X, pos.Y, pos.Z, 300f, 262196, 2f); RaceSequence.Close(); driver.Task.PerformSequence(RaceSequence); RaceSequence.Dispose(); } foreach (Ped driver in crowd) { driver.MarkAsNoLongerNeeded(); if (CanWeUse(GetLastVehicle(driver))) { Vector3 pos = driver.Position.Around(900f); TaskSequence RaceSequence = new TaskSequence(); Function.Call(Hash.TASK_VEHICLE_DRIVE_TO_COORD_LONGRANGE, 0, GetLastVehicle(driver), pos.X, pos.Y, pos.Z, 300f, 262196, 2f); RaceSequence.Close(); driver.Task.PerformSequence(RaceSequence); RaceSequence.Dispose(); } else { TaskSequence RaceSequence = new TaskSequence(); Function.Call(Hash.TASK_REACT_AND_FLEE_PED, 0, Game.Player.Character); RaceSequence.Close(); driver.Task.PerformSequence(RaceSequence); RaceSequence.Dispose(); } } crowd.Clear(); drivers.Clear(); waitingdrivers.Clear(); if (CanWeUse(countdownped)) { countdownped.MarkAsNoLongerNeeded(); TaskSequence RaceSequence = new TaskSequence(); Function.Call(Hash.TASK_REACT_AND_FLEE_PED, 0, Game.Player.Character); RaceSequence.Close(); countdownped.Task.PerformSequence(RaceSequence); RaceSequence.Dispose(); } foreach (Vehicle veh in ambientvehicles) { veh.MarkAsNoLongerNeeded(); } finish.MarkAsNoLongerNeeded(); }
void UnlockDriver(Ped ped) { ped.Task.ClearAll(); TaskSequence dd = new TaskSequence(); Function.Call(GTA.Native.Hash.TASK_ENTER_VEHICLE, ped, GetLastVehicle(ped), -1, -1, 2f, 3, false); dd.Close(); ped.Task.PerformSequence(dd); dd.Dispose(); GetLastVehicle(ped).FreezePosition = false; Function.Call(GTA.Native.Hash.SET_VEHICLE_BURNOUT, GetLastVehicle(ped), false); }
void HandleDriverShowOff() { UI.Notify("Driver showoff initiated"); foreach (Ped ped in drivers) { if (ped.IsInRangeOf(GetStartingLine(), GetStartingLineRadius())) { if (IsIdle(ped)) { if (IsInBurnout(ped)) { UI.Notify("Driver showoff UNLOCK"); UnlockDriver(ped); } else { Vector3 pos = ped.Position + ped.ForwardVector * 30; Function.Call(GTA.Native.Hash.SET_VEHICLE_BURNOUT, GetLastVehicle(ped), true); TaskSequence dd2 = new TaskSequence(); Function.Call(Hash.TASK_VEHICLE_DRIVE_TO_COORD, 0, GetLastVehicle(ped), pos.X, pos.Y, pos.Z, 100f, true, GetLastVehicle(ped).GetHashCode(), 16777216, 5f, 7f); dd2.Close(); ped.Task.PerformSequence(dd2); dd2.Dispose(); /* TaskSequence dd = new TaskSequence(); Function.Call(Hash.TASK_PAUSE, 0, 2000); dd.Close(); ped.Task.PerformSequence(dd); dd.Dispose(); */ } } } } }