2021-07-07 13:36:25 +02:00
|
|
|
|
using System;
|
2021-08-18 11:47:59 +02:00
|
|
|
|
using System.Linq;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
|
|
|
|
using GTA;
|
|
|
|
|
using GTA.Native;
|
|
|
|
|
|
|
|
|
|
namespace CoopClient
|
|
|
|
|
{
|
2021-12-03 20:30:00 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Don't use it!
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class WorldThread : Script
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2022-04-10 14:34:55 +02:00
|
|
|
|
private static bool _lastDisableTraffic = false;
|
2021-08-18 11:47:59 +02:00
|
|
|
|
|
2021-12-03 20:30:00 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Don't use it!
|
|
|
|
|
/// </summary>
|
2021-07-07 13:36:25 +02:00
|
|
|
|
public WorldThread()
|
|
|
|
|
{
|
|
|
|
|
Tick += OnTick;
|
2021-08-18 11:47:59 +02:00
|
|
|
|
Aborted += (sender, e) =>
|
|
|
|
|
{
|
2022-04-10 14:34:55 +02:00
|
|
|
|
if (_lastDisableTraffic)
|
2021-08-18 11:47:59 +02:00
|
|
|
|
{
|
|
|
|
|
Traffic(true);
|
|
|
|
|
}
|
|
|
|
|
};
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-28 15:08:30 +02:00
|
|
|
|
private void OnTick(object sender, EventArgs e)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
|
|
|
|
if (Game.IsLoading)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-19 05:42:30 +02:00
|
|
|
|
Game.DisableControlThisFrame(Control.FrontendPause);
|
2022-03-28 22:34:59 +02:00
|
|
|
|
|
2022-04-18 21:54:34 +02:00
|
|
|
|
// Sets a value that determines how aggressive the ocean waves will be.
|
|
|
|
|
// Values of 2.0 or more make for very aggressive waves like you see during a thunderstorm.
|
|
|
|
|
Function.Call(Hash.SET_DEEP_OCEAN_SCALER, 0.0f); // Works only ~200 meters around the player
|
2021-08-06 12:31:25 +02:00
|
|
|
|
|
|
|
|
|
Function.Call(Hash.SET_CAN_ATTACK_FRIENDLY, Game.Player.Character.Handle, true, false);
|
2021-08-18 11:47:59 +02:00
|
|
|
|
|
2021-08-22 13:59:15 +02:00
|
|
|
|
if (Main.DisableTraffic)
|
2021-08-18 11:47:59 +02:00
|
|
|
|
{
|
2022-04-10 14:34:55 +02:00
|
|
|
|
if (!_lastDisableTraffic)
|
2021-08-18 11:47:59 +02:00
|
|
|
|
{
|
|
|
|
|
Traffic(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Function.Call(Hash.SET_VEHICLE_POPULATION_BUDGET, 0);
|
|
|
|
|
Function.Call(Hash.SET_PED_POPULATION_BUDGET, 0);
|
|
|
|
|
Function.Call(Hash.SET_VEHICLE_DENSITY_MULTIPLIER_THIS_FRAME, 0f);
|
|
|
|
|
Function.Call(Hash.SET_RANDOM_VEHICLE_DENSITY_MULTIPLIER_THIS_FRAME, 0f);
|
|
|
|
|
Function.Call(Hash.SET_PARKED_VEHICLE_DENSITY_MULTIPLIER_THIS_FRAME, 0f);
|
2022-04-18 21:54:34 +02:00
|
|
|
|
Function.Call(Hash.SUPPRESS_SHOCKING_EVENTS_NEXT_FRAME);
|
|
|
|
|
Function.Call(Hash.SUPPRESS_AGITATION_EVENTS_NEXT_FRAME);
|
2021-08-18 11:47:59 +02:00
|
|
|
|
}
|
2022-04-10 14:34:55 +02:00
|
|
|
|
else if (_lastDisableTraffic)
|
2021-08-18 11:47:59 +02:00
|
|
|
|
{
|
|
|
|
|
Traffic(true);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-10 14:34:55 +02:00
|
|
|
|
_lastDisableTraffic = Main.DisableTraffic;
|
2021-08-18 11:47:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-28 15:08:30 +02:00
|
|
|
|
private void Traffic(bool enable)
|
2021-08-18 11:47:59 +02:00
|
|
|
|
{
|
|
|
|
|
if (enable)
|
|
|
|
|
{
|
|
|
|
|
Function.Call(Hash.REMOVE_SCENARIO_BLOCKING_AREAS);
|
|
|
|
|
Function.Call(Hash.SET_CREATE_RANDOM_COPS, true);
|
|
|
|
|
Function.Call(Hash.SET_RANDOM_TRAINS, true);
|
|
|
|
|
Function.Call(Hash.SET_RANDOM_BOATS, true);
|
|
|
|
|
Function.Call(Hash.SET_GARBAGE_TRUCKS, true);
|
|
|
|
|
Function.Call(Hash.SET_PED_POPULATION_BUDGET, 3); // 0 - 3
|
|
|
|
|
Function.Call(Hash.SET_VEHICLE_POPULATION_BUDGET, 3); // 0 - 3
|
|
|
|
|
Function.Call(Hash.SET_ALL_VEHICLE_GENERATORS_ACTIVE);
|
|
|
|
|
Function.Call(Hash.SET_ALL_LOW_PRIORITY_VEHICLE_GENERATORS_ACTIVE, true);
|
|
|
|
|
Function.Call(Hash.SET_NUMBER_OF_PARKED_VEHICLES, -1);
|
2022-04-18 21:54:34 +02:00
|
|
|
|
Function.Call(Hash.SET_DISTANT_CARS_ENABLED, true);
|
2021-08-18 11:47:59 +02:00
|
|
|
|
Function.Call(Hash.DISABLE_VEHICLE_DISTANTLIGHTS, false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Function.Call(Hash.ADD_SCENARIO_BLOCKING_AREA, -10000.0f, -10000.0f, -1000.0f, 10000.0f, 10000.0f, 1000.0f, 0, 1, 1, 1);
|
|
|
|
|
Function.Call(Hash.SET_CREATE_RANDOM_COPS, false);
|
|
|
|
|
Function.Call(Hash.SET_RANDOM_TRAINS, false);
|
|
|
|
|
Function.Call(Hash.SET_RANDOM_BOATS, false);
|
|
|
|
|
Function.Call(Hash.SET_GARBAGE_TRUCKS, false);
|
|
|
|
|
Function.Call(Hash.DELETE_ALL_TRAINS);
|
|
|
|
|
Function.Call(Hash.SET_PED_POPULATION_BUDGET, 0);
|
|
|
|
|
Function.Call(Hash.SET_VEHICLE_POPULATION_BUDGET, 0);
|
|
|
|
|
Function.Call(Hash.SET_ALL_LOW_PRIORITY_VEHICLE_GENERATORS_ACTIVE, false);
|
|
|
|
|
Function.Call(Hash.SET_FAR_DRAW_VEHICLES, false);
|
|
|
|
|
Function.Call(Hash.SET_NUMBER_OF_PARKED_VEHICLES, 0);
|
2022-04-18 21:54:34 +02:00
|
|
|
|
Function.Call(Hash.SET_DISTANT_CARS_ENABLED, false);
|
2021-08-18 11:47:59 +02:00
|
|
|
|
Function.Call(Hash.DISABLE_VEHICLE_DISTANTLIGHTS, true);
|
|
|
|
|
|
2021-12-13 20:25:31 +01:00
|
|
|
|
foreach (Ped ped in World.GetAllPeds().Where(p => p.RelationshipGroup != "SYNCPED" && p.Handle != Game.Player.Character?.Handle))
|
2021-08-18 11:47:59 +02:00
|
|
|
|
{
|
|
|
|
|
ped.CurrentVehicle?.Delete();
|
|
|
|
|
ped.Kill();
|
|
|
|
|
ped.Delete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (Vehicle veh in World.GetAllVehicles().Where(v => v.IsSeatFree(VehicleSeat.Driver) && v.PassengerCount == 0))
|
|
|
|
|
{
|
|
|
|
|
veh.Delete();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|