diff --git a/CorruptSnail/CorruptSnail.csproj b/CorruptSnail/CorruptSnail.csproj index 7d4154b..68d0a31 100644 --- a/CorruptSnail/CorruptSnail.csproj +++ b/CorruptSnail/CorruptSnail.csproj @@ -46,6 +46,7 @@ + @@ -60,7 +61,6 @@ - diff --git a/CorruptSnail/Spawners/Ambient/FlyingByPlaneSpawner.cs b/CorruptSnail/Spawners/Ambient/FlyingByPlaneSpawner.cs index 819e354..412c16e 100644 --- a/CorruptSnail/Spawners/Ambient/FlyingByPlaneSpawner.cs +++ b/CorruptSnail/Spawners/Ambient/FlyingByPlaneSpawner.cs @@ -53,12 +53,12 @@ private async void SpawnRandomFlyingByPlane() if (!Utils.IsPosShitSpawn(Players, spawnPos, SpawnerHost.SPAWN_DESPAWN_DISTANCE)) { - Vehicle plane = await World.CreateVehicle(PLANE_LIST[Utils.GetRandomInt(PLANE_LIST.Length)], spawnPos, + Vehicle plane = await EntityUtil.CreateVehicle(PLANE_LIST[Utils.GetRandomInt(PLANE_LIST.Length)], spawnPos, Utils.GetRandomInt(360)); plane.IsInvincible = true; plane.IsEngineRunning = true; - Ped pilot = await World.CreatePed(PedHash.Pilot01SMM, spawnPos); + Ped pilot = await EntityUtil.CreatePed(PedHash.Pilot01SMM, PedType.PED_TYPE_MISSION, spawnPos); pilot.IsInvincible = true; pilot.SetIntoVehicle(plane, VehicleSeat.Driver); pilot.AlwaysKeepTask = true; diff --git a/CorruptSnail/Spawners/Despawner.cs b/CorruptSnail/Spawners/Despawner.cs index e1e11ac..1072c0c 100644 --- a/CorruptSnail/Spawners/Despawner.cs +++ b/CorruptSnail/Spawners/Despawner.cs @@ -15,15 +15,15 @@ private async Task OnTick() { await Delay(SpawnerHost.SPAWN_TICK_RATE); - foreach (Prop prop in EntityEnum.GetProps()) + foreach (Prop prop in World.GetAllProps()) if (prop.HasDecor(SpawnerHost.SPAWN_DESPAWN_DECOR)) prop.MarkAsNoLongerNeeded(); - foreach (Ped ped in EntityEnum.GetPeds()) + foreach (Ped ped in World.GetAllPeds()) if (ped.HasDecor(SpawnerHost.SPAWN_DESPAWN_DECOR)) ped.MarkAsNoLongerNeeded(); - foreach (Vehicle veh in EntityEnum.GetVehicles()) + foreach (Vehicle veh in World.GetAllVehicles()) if (veh.HasDecor(SpawnerHost.SPAWN_DESPAWN_DECOR)) veh.MarkAsNoLongerNeeded(); } diff --git a/CorruptSnail/Spawners/Events/ArmyHeliSquadSpawner.cs b/CorruptSnail/Spawners/Events/ArmyHeliSquadSpawner.cs index fbfe65d..05b0024 100644 --- a/CorruptSnail/Spawners/Events/ArmyHeliSquadSpawner.cs +++ b/CorruptSnail/Spawners/Events/ArmyHeliSquadSpawner.cs @@ -66,12 +66,12 @@ private async void SpawnRandomArmyHeli() if (!Utils.IsPosShitSpawn(Players, spawnPos, SpawnerHost.SPAWN_DESPAWN_DISTANCE)) { - Vehicle heli = await World.CreateVehicle(HELI_LIST[Utils.GetRandomInt(HELI_LIST.Length)], spawnPos, + Vehicle heli = await EntityUtil.CreateVehicle(HELI_LIST[Utils.GetRandomInt(HELI_LIST.Length)], spawnPos, Utils.GetRandomInt(360)); heli.IsInvincible = true; heli.IsEngineRunning = true; - Ped pilot = await World.CreatePed(PedHash.Blackops01SMY, spawnPos); + Ped pilot = await EntityUtil.CreatePed(PedHash.Blackops01SMY, PedType.PED_TYPE_MISSION, spawnPos); pilot.IsInvincible = true; pilot.RelationshipGroup = ArmyHeliSquadGroup; pilot.SetIntoVehicle(heli, VehicleSeat.Driver); @@ -105,7 +105,7 @@ private async void SpawnRandomArmyHeli() private void HandleArmyHeliSquads() { - foreach (Ped ped in EntityEnum.GetPeds()) + foreach (Ped ped in World.GetAllPeds()) if (ped.HasDecor(ARMYHELI_DECOR)) ped.RelationshipGroup.SetRelationshipBetweenGroups(Game.PlayerPed.RelationshipGroup, Relationship.Like, true); } diff --git a/CorruptSnail/Spawners/Events/RebelSquadSpawner.cs b/CorruptSnail/Spawners/Events/RebelSquadSpawner.cs index 8556d7f..edd6a23 100644 --- a/CorruptSnail/Spawners/Events/RebelSquadSpawner.cs +++ b/CorruptSnail/Spawners/Events/RebelSquadSpawner.cs @@ -69,7 +69,7 @@ private async void SpawnRandomRebelSquad() Ped[] rebels = new Ped[rebelAmount]; for (int i = 0; i < rebelAmount; i++) { - Ped rebel = await World.CreatePed(PedHash.Hillbilly01AMM, spawnPos); + Ped rebel = await EntityUtil.CreatePed(PedHash.Hillbilly01AMM, PedType.PED_TYPE_MISSION, spawnPos); API.SetPedCombatRange(rebel.Handle, 2); API.SetPedHearingRange(rebel.Handle, float.MaxValue); rebel.RelationshipGroup = RebelSquadGroup; @@ -89,7 +89,7 @@ private async void SpawnRandomRebelSquad() private void HandleRebelSquads() { - foreach (Ped ped in EntityEnum.GetPeds()) + foreach (Ped ped in World.GetAllPeds()) if (ped.HasDecor(REBELSQUAD_DECOR)) ped.RelationshipGroup.SetRelationshipBetweenGroups(Game.PlayerPed.RelationshipGroup, Relationship.Hate, true); } diff --git a/CorruptSnail/Spawners/ObjectSpawner.cs b/CorruptSnail/Spawners/ObjectSpawner.cs index 36675ff..0bccf8d 100644 --- a/CorruptSnail/Spawners/ObjectSpawner.cs +++ b/CorruptSnail/Spawners/ObjectSpawner.cs @@ -44,8 +44,7 @@ private async void SpawnRandomObstacle() if (!Utils.IsPosShitSpawn(Players, spawnPos, SpawnerHost.SPAWN_MIN_DISTANCE)) { - Prop obstacle = await World - .CreateProp(API.GetHashKey(OBSTACLE_LIST[Utils.GetRandomInt(OBSTACLE_LIST.Length)]), spawnPos, false, true); + Prop obstacle = await EntityUtil.CreateProp(API.GetHashKey(OBSTACLE_LIST[Utils.GetRandomInt(OBSTACLE_LIST.Length)]), spawnPos, false, true); obstacle.IsPositionFrozen = true; obstacles.Add(obstacle); diff --git a/CorruptSnail/Spawners/VehicleSpawner.cs b/CorruptSnail/Spawners/VehicleSpawner.cs index b2e4043..6bb2636 100644 --- a/CorruptSnail/Spawners/VehicleSpawner.cs +++ b/CorruptSnail/Spawners/VehicleSpawner.cs @@ -37,8 +37,7 @@ private async void SpawnRandomVeh() if (!Utils.IsPosShitSpawn(Players, spawnPos, SpawnerHost.SPAWN_MIN_DISTANCE)) { - Vehicle veh = await World - .CreateVehicle(VEH_LIST[Utils.GetRandomInt(VEH_LIST.Length)], spawnPos); + Vehicle veh = await EntityUtil.CreateVehicle(VEH_LIST[Utils.GetRandomInt(VEH_LIST.Length)], spawnPos); veh.Health = Utils.GetRandomInt(1000); veh.EngineHealth = Utils.GetRandomInt(1000); veh.PetrolTankHealth = Utils.GetRandomInt(1000); diff --git a/CorruptSnail/Spawners/ZombieSpawner.cs b/CorruptSnail/Spawners/ZombieSpawner.cs index 5742b4e..28bf37a 100644 --- a/CorruptSnail/Spawners/ZombieSpawner.cs +++ b/CorruptSnail/Spawners/ZombieSpawner.cs @@ -1,7 +1,6 @@ using CitizenFX.Core; using CitizenFX.Core.Native; using CorruptSnail.Util; -using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -51,7 +50,7 @@ private async void SpawnRandomZombie() if (!Utils.IsPosShitSpawn(Players, spawnPos, SpawnerHost.SPAWN_MIN_DISTANCE)) { - Ped zombie = await World.CreatePed(PedHash.Zombie01, spawnPos); + Ped zombie = await EntityUtil.CreatePed(PedHash.Zombie01, PedType.PED_TYPE_MISSION, spawnPos); int zombieHandle = zombie.Handle; API.SetPedCombatRange(zombieHandle, 2); API.SetPedHearingRange(zombieHandle, float.MaxValue); @@ -80,7 +79,7 @@ private async void SpawnRandomZombie() private void HandleZombies() { - foreach (Ped ped in EntityEnum.GetPeds()) + foreach (Ped ped in World.GetAllPeds()) { if (ped.HasDecor(ZOMBIE_DECOR)) { diff --git a/CorruptSnail/Util/EntityEnum.cs b/CorruptSnail/Util/EntityEnum.cs deleted file mode 100644 index d2e8fe1..0000000 --- a/CorruptSnail/Util/EntityEnum.cs +++ /dev/null @@ -1,93 +0,0 @@ -using CitizenFX.Core; -using CitizenFX.Core.Native; -using System.Collections.Generic; - -namespace CorruptSnail.Util -{ - class EntityEnum - { - public static List GetProps() - { - List props = new List(); - int entHandle = 0; - - int handle = API.FindFirstObject(ref entHandle); - Prop prop = (Prop) Entity.FromHandle(entHandle); - if (prop != null) - props.Add(prop); - - while (API.FindNextObject(handle, ref entHandle)) - { - prop = (Prop) Entity.FromHandle(entHandle); - if (prop != null) - props.Add(prop); - } - - API.EndFindObject(handle); - return props; - } - - public static List GetPeds() - { - List peds = new List(); - int entHandle = 0; - - int handle = API.FindFirstPed(ref entHandle); - Ped ped = (Ped) Entity.FromHandle(entHandle); - if (ped != null) - peds.Add(ped); - - while (API.FindNextPed(handle, ref entHandle)) - { - ped = (Ped) Entity.FromHandle(entHandle); - if (ped != null) - peds.Add(ped); - } - - API.EndFindPed(handle); - return peds; - } - - public static List GetVehicles() - { - List vehs = new List(); - int entHandle = 0; - - int handle = API.FindFirstVehicle(ref entHandle); - Vehicle veh = (Vehicle) Entity.FromHandle(entHandle); - if (veh != null) - vehs.Add(veh); - - while (API.FindNextVehicle(handle, ref entHandle)) - { - veh = (Vehicle) Entity.FromHandle(entHandle); - if (veh != null) - vehs.Add(veh); - } - - API.EndFindVehicle(handle); - return vehs; - } - - public static List GetPickups() - { - List pickups = new List(); - int entHandle = 0; - - int handle = API.FindFirstPickup(ref entHandle); - Pickup pickup = new Pickup(entHandle); - if (pickup != null && pickup.Exists()) - pickups.Add(pickup); - - while (API.FindNextPickup(handle, ref entHandle)) - { - pickup = new Pickup(entHandle); - if (pickup != null && pickup.Exists()) - pickups.Add(pickup); - } - - API.EndFindPickup(handle); - return pickups; - } - } -} diff --git a/CorruptSnail/Util/EntityUtil.cs b/CorruptSnail/Util/EntityUtil.cs new file mode 100644 index 0000000..7b44b99 --- /dev/null +++ b/CorruptSnail/Util/EntityUtil.cs @@ -0,0 +1,105 @@ +using CitizenFX.Core; +using CitizenFX.Core.Native; +using System.Threading.Tasks; + +namespace CorruptSnail.Util +{ + public enum PedType + { + PED_TYPE_PLAYER_0, + PED_TYPE_PLAYER_1, + PED_TYPE_NETWORK_PLAYER, + PED_TYPE_PLAYER_2, + PED_TYPE_CIVMALE, + PED_TYPE_CIVFEMALE, + PED_TYPE_COP, + PED_TYPE_GANG_ALBANIAN, + PED_TYPE_GANG_BIKER_1, + PED_TYPE_GANG_BIKER_2, + PED_TYPE_GANG_ITALIAN, + PED_TYPE_GANG_RUSSIAN, + PED_TYPE_GANG_RUSSIAN_2, + PED_TYPE_GANG_IRISH, + PED_TYPE_GANG_JAMAICAN, + PED_TYPE_GANG_AFRICAN_AMERICAN, + PED_TYPE_GANG_KOREAN, + PED_TYPE_GANG_CHINESE_JAPANESE, + PED_TYPE_GANG_PUERTO_RICAN, + PED_TYPE_DEALER, + PED_TYPE_MEDIC, + PED_TYPE_FIREMAN, + PED_TYPE_CRIMINAL, + PED_TYPE_BUM, + PED_TYPE_PROSTITUTE, + PED_TYPE_SPECIAL, + PED_TYPE_MISSION, + PED_TYPE_SWAT, + PED_TYPE_ANIMAL, + PED_TYPE_ARMY + } + + public static class EntityUtil + { + public static async Task CreatePed(Model model, PedType pedType, Vector3 pos, float heading = 0f, bool networked = true) + { + if (API.IsModelAPed((uint)model.Hash)) + { + model.Request(); + while (!model.IsLoaded) + await BaseScript.Delay(1); + Ped ped = new Ped(API.CreatePed((int)pedType, (uint)model.Hash, pos.X, pos.Y, pos.Z, heading, networked, false)); + model.MarkAsNoLongerNeeded(); + return ped; + } + return null; + } + + public static async Task CreateVehicle(Model model, Vector3 pos, float heading = 0f, bool networked = true) + { + if (API.IsModelAVehicle((uint)model.Hash)) + { + model.Request(); + while (!model.IsLoaded) + await BaseScript.Delay(1); + Vehicle vehicle = new Vehicle(API.CreateVehicle((uint)model.Hash, pos.X, pos.Y, pos.Z, heading, networked, false)); + model.MarkAsNoLongerNeeded(); + return vehicle; + } + return null; + } + + public static async Task CreateProp(Model model, Vector3 pos, bool dynamic, bool placeOnGround = false, bool networked = true) + { + if (API.IsModelValid((uint)model.Hash)) + { + model.Request(); + while (!model.IsLoaded) + await BaseScript.Delay(1); + if (placeOnGround) + pos.Z = World.GetGroundHeight(pos); + Prop prop = new Prop(API.CreateObjectNoOffset((uint)model.Hash, pos.X, pos.Y, pos.Z, networked, false, dynamic)); + model.MarkAsNoLongerNeeded(); + return prop; + } + return null; + } + + public static void _StartScenario(this Ped ped, string scenario) + { + API.TaskStartScenarioInPlace(ped.Handle, scenario, 0, true); + } + } + + public static class VehicleUtil + { + public static bool _IsBroken(this Vehicle vehicle) + { + return vehicle.IsDead || vehicle.EngineHealth == 0f || vehicle.PetrolTankHealth == 0f; + } + + public static string _GetLabel(this Vehicle vehicle) + { + return API.GetLabelText(API.GetDisplayNameFromVehicleModel((uint)vehicle.Model.Hash)); + } + } +}