2022-07-20 17:50:01 +08:00
|
|
|
|
using GTA;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
using GTA.Native;
|
2022-07-20 17:50:01 +08:00
|
|
|
|
using System;
|
2022-08-22 21:59:01 +08:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Threading;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
2022-05-22 15:55:26 +08:00
|
|
|
|
namespace RageCoop.Client
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
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
|
|
|
|
{
|
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-08-22 21:59:01 +08:00
|
|
|
|
ChangeTraffic(true);
|
|
|
|
|
};
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
while (true)
|
2021-08-18 11:47:59 +02:00
|
|
|
|
{
|
2022-08-22 21:59:01 +08:00
|
|
|
|
Thread.Sleep(5000);
|
|
|
|
|
Main.QueueAction(() => { ChangeTraffic(_trafficEnabled); });
|
2021-08-18 11:47:59 +02:00
|
|
|
|
}
|
2022-08-22 21:59:01 +08:00
|
|
|
|
});
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
2022-08-22 21:59:01 +08:00
|
|
|
|
static bool _trafficEnabled;
|
2022-03-28 15:08:30 +02:00
|
|
|
|
private void OnTick(object sender, EventArgs e)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
2022-08-11 14:59:09 +02:00
|
|
|
|
if (Game.IsLoading || !Networking.IsOnServer)
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-27 14:33:33 +08:00
|
|
|
|
Game.DisableControlThisFrame(Control.FrontendPause);
|
2022-08-13 16:59:09 +08:00
|
|
|
|
|
2022-05-27 14:33:33 +08:00
|
|
|
|
if (Main.Settings.DisableAlternatePause)
|
|
|
|
|
{
|
|
|
|
|
Game.DisableControlThisFrame(Control.FrontendPauseAlternate);
|
2022-05-25 11:32:34 +08: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
|
2022-08-23 17:43:24 +08:00
|
|
|
|
|
|
|
|
|
if (Main.Settings.ShowEntityOwnerName)
|
|
|
|
|
{
|
|
|
|
|
unsafe
|
|
|
|
|
{
|
|
|
|
|
int handle;
|
|
|
|
|
if (Function.Call<bool>(Hash.GET_ENTITY_PLAYER_IS_FREE_AIMING_AT, 0, &handle))
|
|
|
|
|
{
|
|
|
|
|
var entity = Entity.FromHandle(handle);
|
|
|
|
|
if (entity != null)
|
|
|
|
|
{
|
|
|
|
|
var owner = "invalid";
|
|
|
|
|
if (entity.EntityType == EntityType.Vehicle)
|
|
|
|
|
{
|
|
|
|
|
owner = (entity as Vehicle).GetSyncEntity()?.Owner?.Username ?? "unknown";
|
|
|
|
|
}
|
|
|
|
|
if (entity.EntityType == EntityType.Ped)
|
|
|
|
|
{
|
|
|
|
|
owner = (entity as Ped).GetSyncEntity()?.Owner?.Username ?? "unknown";
|
|
|
|
|
}
|
|
|
|
|
GTA.UI.Screen.ShowHelpTextThisFrame("Entity owner: " + owner);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-24 18:47:59 +08:00
|
|
|
|
if (!_trafficEnabled)
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
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-08-14 10:35:59 +08:00
|
|
|
|
public static void Traffic(bool enable)
|
2022-08-22 21:59:01 +08:00
|
|
|
|
{
|
|
|
|
|
ChangeTraffic(enable);
|
|
|
|
|
_trafficEnabled = enable;
|
|
|
|
|
}
|
|
|
|
|
private static void ChangeTraffic(bool enable)
|
2021-08-18 11:47:59 +02:00
|
|
|
|
{
|
|
|
|
|
if (enable)
|
|
|
|
|
{
|
2022-08-22 10:01:09 +08:00
|
|
|
|
// Function.Call(Hash.REMOVE_SCENARIO_BLOCKING_AREAS);
|
2021-08-18 11:47:59 +02:00
|
|
|
|
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);
|
2022-08-22 10:01:09 +08:00
|
|
|
|
Function.Call(Hash.SET_PED_POPULATION_BUDGET, 3); // 0 - 3
|
|
|
|
|
Function.Call(Hash.SET_VEHICLE_POPULATION_BUDGET, 3); // 0 - 3
|
2021-08-18 11:47:59 +02:00
|
|
|
|
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);
|
|
|
|
|
}
|
2022-08-24 18:47:59 +08:00
|
|
|
|
else if(Networking.IsOnServer)
|
2021-08-18 11:47:59 +02:00
|
|
|
|
{
|
2022-08-22 10:01:09 +08:00
|
|
|
|
// Function.Call(Hash.ADD_SCENARIO_BLOCKING_AREA, -10000.0f, -10000.0f, -1000.0f, 10000.0f, 10000.0f, 1000.0f, 0, 1, 1, 1);
|
2021-08-18 11:47:59 +02:00
|
|
|
|
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);
|
2022-08-22 10:01:09 +08:00
|
|
|
|
Function.Call(Hash.SET_PED_POPULATION_BUDGET, 0);
|
|
|
|
|
Function.Call(Hash.SET_VEHICLE_POPULATION_BUDGET, 0);
|
2021-08-18 11:47:59 +02:00
|
|
|
|
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);
|
|
|
|
|
|
2022-08-22 21:59:01 +08:00
|
|
|
|
if (Networking.IsOnServer)
|
2021-08-18 11:47:59 +02:00
|
|
|
|
{
|
2022-08-22 21:59:01 +08:00
|
|
|
|
|
|
|
|
|
foreach (Ped ped in World.GetAllPeds())
|
2022-05-22 15:55:26 +08:00
|
|
|
|
{
|
2022-08-22 21:59:01 +08:00
|
|
|
|
SyncedPed c = EntityPool.GetPedByHandle(ped.Handle);
|
|
|
|
|
if ((c == null) || (c.IsLocal && (ped.Handle != Game.Player.Character.Handle) && ped.PopulationType != EntityPopulationType.Mission))
|
|
|
|
|
{
|
|
|
|
|
if (ped.Handle == Game.Player.Character.Handle) { continue; }
|
|
|
|
|
|
|
|
|
|
// Main.Logger.Trace($"Removing ped {ped.Handle}. Reason:RemoveTraffic");
|
|
|
|
|
ped.CurrentVehicle?.Delete();
|
|
|
|
|
ped.Kill();
|
|
|
|
|
ped.Delete();
|
|
|
|
|
}
|
2021-08-18 11:47:59 +02:00
|
|
|
|
|
2022-05-22 15:55:26 +08:00
|
|
|
|
}
|
2022-07-20 17:50:01 +08:00
|
|
|
|
|
2022-08-22 21:59:01 +08:00
|
|
|
|
foreach (Vehicle veh in World.GetAllVehicles())
|
|
|
|
|
{
|
|
|
|
|
SyncedVehicle v = veh.GetSyncEntity();
|
|
|
|
|
if (v.MainVehicle == Game.Player.LastVehicle)
|
|
|
|
|
{
|
|
|
|
|
// Don't delete player's vehicle
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if ((v == null) || (v.IsLocal && veh.PopulationType != EntityPopulationType.Mission))
|
|
|
|
|
{
|
|
|
|
|
// Main.Logger.Debug($"Removing Vehicle {veh.Handle}. Reason:ClearTraffic");
|
2022-07-20 17:50:01 +08:00
|
|
|
|
|
2022-08-22 21:59:01 +08:00
|
|
|
|
veh.Delete();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2021-08-18 11:47:59 +02:00
|
|
|
|
{
|
2022-08-22 21:59:01 +08:00
|
|
|
|
foreach (Ped ped in World.GetAllPeds())
|
2022-06-02 13:11:01 +08:00
|
|
|
|
{
|
2022-08-22 21:59:01 +08:00
|
|
|
|
if ((ped != Game.Player.Character) && (ped.PopulationType != EntityPopulationType.Mission))
|
|
|
|
|
{
|
|
|
|
|
// Main.Logger.Trace($"Removing ped {ped.Handle}. Reason:RemoveTraffic");
|
|
|
|
|
ped.CurrentVehicle?.Delete();
|
|
|
|
|
ped.Kill();
|
|
|
|
|
ped.Delete();
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-02 13:11:01 +08:00
|
|
|
|
}
|
2022-08-22 21:59:01 +08:00
|
|
|
|
var last = Game.Player.Character.LastVehicle;
|
|
|
|
|
var current = Game.Player.Character.CurrentVehicle;
|
|
|
|
|
foreach (Vehicle veh in World.GetAllVehicles())
|
2022-05-22 15:55:26 +08:00
|
|
|
|
{
|
2022-08-22 21:59:01 +08:00
|
|
|
|
if (veh.PopulationType != EntityPopulationType.Mission && veh != last && veh!=current)
|
|
|
|
|
{
|
|
|
|
|
// Main.Logger.Debug($"Removing Vehicle {veh.Handle}. Reason:ClearTraffic");
|
2022-05-22 15:55:26 +08:00
|
|
|
|
|
2022-08-22 21:59:01 +08:00
|
|
|
|
veh.Delete();
|
|
|
|
|
}
|
2022-05-22 15:55:26 +08:00
|
|
|
|
}
|
2021-08-18 11:47:59 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|