diff --git a/CorruptSnail/CPlayer/PlayerSpawner.cs b/CorruptSnail/CPlayer/PlayerSpawner.cs new file mode 100644 index 0000000..5f68848 --- /dev/null +++ b/CorruptSnail/CPlayer/PlayerSpawner.cs @@ -0,0 +1,18 @@ +using CitizenFX.Core; +using System; + +namespace CorruptSnail.CPlayer +{ + class PlayerSpawner : BaseScript + { + public PlayerSpawner() + { + EventHandlers["playerSpawned"] += new Action(SpawnPlayer); + } + + private void SpawnPlayer() + { + Game.PlayerPed.Position = Safezones.SAFEZONES[0].Pos; + } + } +} diff --git a/CorruptSnail/CPlayer/Safezones.cs b/CorruptSnail/CPlayer/Safezones.cs new file mode 100644 index 0000000..b23def7 --- /dev/null +++ b/CorruptSnail/CPlayer/Safezones.cs @@ -0,0 +1,63 @@ +using CitizenFX.Core; +using CitizenFX.Core.Native; +using System.Threading.Tasks; + +namespace CorruptSnail.CPlayer +{ + class Safezones : BaseScript + { + private bool inSafezone = false; + + public class Safezone + { + public Vector3 Pos { get; private set; } + public float Range { get; private set; } + + public Safezone(Vector3 pos, float range) + { + Pos = pos; + Range = range; + } + } + + public static Safezone[] SAFEZONES { get; } = + { + new Safezone(new Vector3(3474, 3681, 34), 250f) + }; + + public Safezones() + { + Tick += OnTick; + } + + private async Task OnTick() + { + await Delay(100); + + if (API.NetworkIsSessionStarted() && !API.GetIsLoadingScreenActive()) + { + Ped playerPed = Game.PlayerPed; + + foreach (Safezone safezone in SAFEZONES) + if (World.GetDistance(playerPed.Position, safezone.Pos) < safezone.Range + && !inSafezone) + { + inSafezone = true; + TriggerEvent("corruptsnail:inZone", true); + TriggerEvent("chatMessage", "", new int[] { 0, 255, 0 }, "\nYou are in a safezone now!\n" + + "Zombies will not spawn and you can spawn stuff in the F6 menu.\n"); + } + else if (World.GetDistance(playerPed.Position, safezone.Pos) > safezone.Range + && inSafezone) + { + inSafezone = false; + TriggerEvent("corruptsnail:inZone", false); + TriggerEvent("chatMessage", "", new int[] { 255, 0, 0 }, "\nYou left the safezone!\n" + + "Zombies will spawn now and you are unable to spawn stuff.\n"); + } + } + + await Task.FromResult(0); + } + } +} diff --git a/CorruptSnail/VehFuelHandler.cs b/CorruptSnail/CVehicle/VehFuelHandler.cs similarity index 85% rename from CorruptSnail/VehFuelHandler.cs rename to CorruptSnail/CVehicle/VehFuelHandler.cs index 410b194..86cae94 100644 --- a/CorruptSnail/VehFuelHandler.cs +++ b/CorruptSnail/CVehicle/VehFuelHandler.cs @@ -3,12 +3,13 @@ using CorruptSnail.Util; using System.Threading.Tasks; -namespace CorruptSnail +namespace CorruptSnail.CVehicle { class VehFuelHandler : BaseScript { public const string VEH_FUEL_DECOR = "_CORRUPTSNAIL_FUEL"; private const float VEH_FUEL_WARNING_THRESHOLD = 1000f; + private const float VEH_FUEL_MAX = 10000f; public VehFuelHandler() { @@ -19,19 +20,21 @@ public VehFuelHandler() private async Task OnTick() { + await Delay(100); + Ped playerPed; Vehicle veh; if ((playerPed = LocalPlayer.Character) != null && (veh = playerPed.CurrentVehicle) != null) { if (!EntityDecoration.HasDecor(veh, VEH_FUEL_DECOR)) { - veh.FuelLevel = Utils.GetRandomInt(10000); + veh.FuelLevel = Utils.GetRandomFloat(VEH_FUEL_MAX); EntityDecoration.Set(veh, VEH_FUEL_DECOR, veh.FuelLevel); } else { if (veh.GetPedOnSeat(VehicleSeat.Driver) == playerPed && !veh.IsInAir) { - float newFuelLevel = EntityDecoration.Get(veh, VEH_FUEL_DECOR) - veh.Speed * 0.01f; + float newFuelLevel = EntityDecoration.Get(veh, VEH_FUEL_DECOR) - veh.Speed * 0.1f; if (newFuelLevel < 0f) newFuelLevel = 0f; EntityDecoration.Set(veh, VEH_FUEL_DECOR, newFuelLevel); @@ -45,8 +48,6 @@ private async Task OnTick() Screen.DisplayHelpTextThisFrame("Low Fuel Level"); } } - - await Task.FromResult(0); } } } diff --git a/CorruptSnail/CorruptSnail.csproj b/CorruptSnail/CorruptSnail.csproj index 360ae82..9f98909 100644 --- a/CorruptSnail/CorruptSnail.csproj +++ b/CorruptSnail/CorruptSnail.csproj @@ -44,6 +44,8 @@ + + @@ -58,7 +60,7 @@ - + \ No newline at end of file diff --git a/CorruptSnail/Spawners/Ambient/AmbientWarNoiseSpawner.cs b/CorruptSnail/Spawners/Ambient/AmbientWarNoiseSpawner.cs index 99b3f0a..9ab25a9 100644 --- a/CorruptSnail/Spawners/Ambient/AmbientWarNoiseSpawner.cs +++ b/CorruptSnail/Spawners/Ambient/AmbientWarNoiseSpawner.cs @@ -14,17 +14,17 @@ public AmbientWarNoiseSpawner() private async Task OnTick() { + await Delay(SpawnerHost.SPAWN_TICK_RATE); + if (SpawnerHost.CanEventTrigger()) SpawnFarExplosion(); - - await Task.FromResult(0); } private void SpawnFarExplosion() { - Vector3 spawnPos = Utils.GetRandomSpawnPosFromPlayer(LocalPlayer, SpawnerHost.SPAWN_DESPAWN_DISTANCE * 10, SpawnerHost.SPAWN_DESPAWN_DISTANCE * 50); + Vector3 spawnPos = Utils.GetRandomSpawnPosFromPlayer(Game.Player, SpawnerHost.SPAWN_DESPAWN_DISTANCE * 10, SpawnerHost.SPAWN_DESPAWN_DISTANCE * 50); - if (!Utils.IsPosInRadiusOfAPlayer(Players, spawnPos, SpawnerHost.SPAWN_DESPAWN_DISTANCE * 5)) + if (!Utils.IsPosShitSpawn(Players, spawnPos, SpawnerHost.SPAWN_DESPAWN_DISTANCE * 5)) { Array explosionTypes = Enum.GetValues(typeof(ExplosionType)); World.AddExplosion(spawnPos, (ExplosionType) explosionTypes.GetValue(Utils.GetRandomInt(explosionTypes.Length)), diff --git a/CorruptSnail/Spawners/Ambient/FlyingByPlaneSpawner.cs b/CorruptSnail/Spawners/Ambient/FlyingByPlaneSpawner.cs index bf4ed42..667275e 100644 --- a/CorruptSnail/Spawners/Ambient/FlyingByPlaneSpawner.cs +++ b/CorruptSnail/Spawners/Ambient/FlyingByPlaneSpawner.cs @@ -33,25 +33,25 @@ public FlyingByPlaneSpawner() private async Task OnTick() { + await Delay(SpawnerHost.SPAWN_TICK_RATE); + if (SpawnerHost.CanEventTrigger() && flyingByPlane == null) SpawnRandomFlyingByPlane(); else if (flyingByPlane != null) - if (!Utils.IsPosInRadiusOfAPlayer(Players, flyingByPlane.Plane.Position, SpawnerHost.SPAWN_DESPAWN_DISTANCE * 3)) + if (!Utils.IsPosShitSpawn(Players, flyingByPlane.Plane.Position, SpawnerHost.SPAWN_DESPAWN_DISTANCE * 3)) { flyingByPlane.Plane.MarkAsNoLongerNeeded(); flyingByPlane.Pilot.MarkAsNoLongerNeeded(); flyingByPlane = null; } - - await Task.FromResult(0); } private async void SpawnRandomFlyingByPlane() { - Vector3 spawnPos = Utils.GetRandomSpawnPosFromPlayer(LocalPlayer, SpawnerHost.SPAWN_DESPAWN_DISTANCE, SpawnerHost.SPAWN_DESPAWN_DISTANCE * 2); + Vector3 spawnPos = Utils.GetRandomSpawnPosFromPlayer(Game.Player, SpawnerHost.SPAWN_DESPAWN_DISTANCE, SpawnerHost.SPAWN_DESPAWN_DISTANCE * 2); spawnPos.Z += Utils.GetRandomInt(PLANE_SPAWNHEIGHT_MIN_OFFSET, PLANE_SPAWNHEIGHT_MAX_OFFSET); - if (!Utils.IsPosInRadiusOfAPlayer(Players, spawnPos, SpawnerHost.SPAWN_DESPAWN_DISTANCE)) + if (!Utils.IsPosShitSpawn(Players, spawnPos, SpawnerHost.SPAWN_DESPAWN_DISTANCE)) { Vehicle plane = await World.CreateVehicle(PLANE_LIST[Utils.GetRandomInt(PLANE_LIST.Length)], spawnPos, Utils.GetRandomInt(360)); diff --git a/CorruptSnail/Spawners/Events/ArmyHeliSquadSpawner.cs b/CorruptSnail/Spawners/Events/ArmyHeliSquadSpawner.cs index 7aa0d8d..7f5ec18 100644 --- a/CorruptSnail/Spawners/Events/ArmyHeliSquadSpawner.cs +++ b/CorruptSnail/Spawners/Events/ArmyHeliSquadSpawner.cs @@ -41,10 +41,12 @@ public ArmyHeliSquadSpawner() private async Task OnTick() { + await Delay(SpawnerHost.SPAWN_TICK_RATE); + if (SpawnerHost.CanEventTrigger() && armyHeliSquad == null) SpawnRandomArmyHeli(); else if (armyHeliSquad != null) - if (!Utils.IsPosInRadiusOfAPlayer(Players, armyHeliSquad.Heli.Position, SpawnerHost.SPAWN_DESPAWN_DISTANCE * 3)) + if (!Utils.IsPosShitSpawn(Players, armyHeliSquad.Heli.Position, SpawnerHost.SPAWN_DESPAWN_DISTANCE * 3)) { armyHeliSquad.Heli.MarkAsNoLongerNeeded(); armyHeliSquad.Pilot.MarkAsNoLongerNeeded(); @@ -52,16 +54,14 @@ private async Task OnTick() armyHeliSquad.Gunman2.MarkAsNoLongerNeeded(); armyHeliSquad = null; } - - await Task.FromResult(0); } private async void SpawnRandomArmyHeli() { - Vector3 spawnPos = Utils.GetRandomSpawnPosFromPlayer(LocalPlayer, SpawnerHost.SPAWN_DESPAWN_DISTANCE, SpawnerHost.SPAWN_DESPAWN_DISTANCE * 2); + Vector3 spawnPos = Utils.GetRandomSpawnPosFromPlayer(Game.Player, SpawnerHost.SPAWN_DESPAWN_DISTANCE, SpawnerHost.SPAWN_DESPAWN_DISTANCE * 2); spawnPos.Z += Utils.GetRandomInt(ARMYHELI_SPAWNHEIGHT_MIN_OFFSET, ARMYHELI_SPAWNHEIGHT_MAX_OFFSET); - if (!Utils.IsPosInRadiusOfAPlayer(Players, spawnPos, SpawnerHost.SPAWN_DESPAWN_DISTANCE)) + if (!Utils.IsPosShitSpawn(Players, spawnPos, SpawnerHost.SPAWN_DESPAWN_DISTANCE)) { Vehicle heli = await World.CreateVehicle(HELI_LIST[Utils.GetRandomInt(HELI_LIST.Length)], spawnPos, Utils.GetRandomInt(360)); @@ -73,7 +73,7 @@ private async void SpawnRandomArmyHeli() pilot.RelationshipGroup = ArmyHeliSquadGroup; pilot.SetIntoVehicle(heli, VehicleSeat.Driver); pilot.AlwaysKeepTask = true; - Vector3 targetPos = LocalPlayer.Character + Vector3 targetPos = Game.PlayerPed .GetOffsetPosition(new Vector3(0f, -SpawnerHost.SPAWN_DESPAWN_DISTANCE * 100f, 0f)); API.TaskHeliMission(pilot.Handle, heli.Handle, 0, 0, targetPos.X, targetPos.Y, targetPos.Z, 4, Utils.GetRandomInt(ARMYHELI_MIN_SPEED, int.MaxValue), 0f, -1f, -1, -1, 0, 0); @@ -92,7 +92,7 @@ private async void SpawnRandomArmyHeli() } gunmans[0].SetIntoVehicle(heli, VehicleSeat.LeftRear); gunmans[1].SetIntoVehicle(heli, VehicleSeat.RightRear); - ArmyHeliSquadGroup.SetRelationshipBetweenGroups(LocalPlayer.Character.RelationshipGroup, Relationship.Respect, true); + ArmyHeliSquadGroup.SetRelationshipBetweenGroups(Game.PlayerPed.RelationshipGroup, Relationship.Respect, true); ArmyHeliSquadGroup.SetRelationshipBetweenGroups(ZombieSpawner.ZombieGroup, Relationship.Hate); armyHeliSquad = new ArmyHeliSquad(heli, pilot, gunmans[0], gunmans[1]); diff --git a/CorruptSnail/Spawners/Events/RebelSquadSpawner.cs b/CorruptSnail/Spawners/Events/RebelSquadSpawner.cs index 5c9de91..36768c5 100644 --- a/CorruptSnail/Spawners/Events/RebelSquadSpawner.cs +++ b/CorruptSnail/Spawners/Events/RebelSquadSpawner.cs @@ -34,6 +34,8 @@ public RebelSquadSpawner() private async Task OnTick() { + await Delay(SpawnerHost.SPAWN_TICK_RATE); + if (SpawnerHost.CanEventTrigger() && rebelSquad == null) SpawnRandomRebelSquad(); else if (rebelSquad != null) @@ -44,7 +46,7 @@ private async Task OnTick() Ped rebel = rebelSquad.Rebels[i]; if (rebel.Exists()) { - if (!Utils.IsPosInRadiusOfAPlayer(Players, rebel.Position, SpawnerHost.SPAWN_DESPAWN_DISTANCE) + if (!Utils.IsPosShitSpawn(Players, rebel.Position, SpawnerHost.SPAWN_DESPAWN_DISTANCE) || rebel.IsDead) rebel.MarkAsNoLongerNeeded(); else @@ -55,16 +57,13 @@ private async Task OnTick() if (allObsolete) rebelSquad = null; } - - await Task.FromResult(0); } private async void SpawnRandomRebelSquad() { - Vector3 spawnPos = Utils.GetRandomSpawnPosFromPlayer(LocalPlayer, SpawnerHost.SPAWN_MIN_DISTANCE, SpawnerHost.SPAWN_DESPAWN_DISTANCE); - spawnPos.Z++; + Vector3 spawnPos = Utils.GetRandomSpawnPosFromPlayer(Game.Player, SpawnerHost.SPAWN_MIN_DISTANCE, SpawnerHost.SPAWN_DESPAWN_DISTANCE); - if (!Utils.IsPosInRadiusOfAPlayer(Players, spawnPos, SpawnerHost.SPAWN_MIN_DISTANCE)) + if (!Utils.IsPosShitSpawn(Players, spawnPos, SpawnerHost.SPAWN_MIN_DISTANCE)) { int rebelAmount = Utils.GetRandomInt(1, REBELSQUAD_MAXMEMBERS); Ped[] rebels = new Ped[rebelAmount]; @@ -84,9 +83,9 @@ private async void SpawnRandomRebelSquad() rebels[i] = rebel; } if (Utils.GetRandomFloat(1f) > REBELSQUAD_FRIENDLY_CHANCE) - RebelSquadGroup.SetRelationshipBetweenGroups(LocalPlayer.Character.RelationshipGroup, Relationship.Hate, true); + RebelSquadGroup.SetRelationshipBetweenGroups(Game.PlayerPed.RelationshipGroup, Relationship.Hate, true); else - RebelSquadGroup.SetRelationshipBetweenGroups(LocalPlayer.Character.RelationshipGroup, Relationship.Respect, true); + RebelSquadGroup.SetRelationshipBetweenGroups(Game.PlayerPed.RelationshipGroup, Relationship.Respect, true); RebelSquadGroup.SetRelationshipBetweenGroups(ZombieSpawner.ZombieGroup, Relationship.Hate, true); RebelSquadGroup.SetRelationshipBetweenGroups(ArmyHeliSquadSpawner.ArmyHeliSquadGroup, Relationship.Hate, true); diff --git a/CorruptSnail/Spawners/ObjectSpawner.cs b/CorruptSnail/Spawners/ObjectSpawner.cs index 0240048..3ba464e 100644 --- a/CorruptSnail/Spawners/ObjectSpawner.cs +++ b/CorruptSnail/Spawners/ObjectSpawner.cs @@ -24,25 +24,25 @@ public ObjectSpawner() private async Task OnTick() { + await Delay(SpawnerHost.SPAWN_TICK_RATE); + if (SpawnerHost.IsHost && obstacles.Count < OBJECT_AMOUNT) SpawnRandomObstacle(); else if (obstacles.Count > 0) foreach (Prop obstacle in obstacles.ToArray()) - if (!Utils.IsPosInRadiusOfAPlayer(Players, obstacle.Position, SpawnerHost.SPAWN_DESPAWN_DISTANCE)) + if (!Utils.IsPosShitSpawn(Players, obstacle.Position, SpawnerHost.SPAWN_DESPAWN_DISTANCE)) { obstacle.Delete(); obstacles.Remove(obstacle); } - - await Task.FromResult(0); } private async void SpawnRandomObstacle() { - Vector3 spawnPos = Utils.GetRandomSpawnPosFromPlayer(LocalPlayer, SpawnerHost.SPAWN_MIN_DISTANCE, SpawnerHost.SPAWN_DESPAWN_DISTANCE); - spawnPos.Z--; + Vector3 spawnPos = Utils.GetRandomSpawnPosFromPlayer(Game.Player, SpawnerHost.SPAWN_MIN_DISTANCE, SpawnerHost.SPAWN_DESPAWN_DISTANCE); + spawnPos.Z -= 3; - if (!Utils.IsPosInRadiusOfAPlayer(Players, spawnPos, SpawnerHost.SPAWN_MIN_DISTANCE)) + 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); diff --git a/CorruptSnail/Spawners/SpawnerHost.cs b/CorruptSnail/Spawners/SpawnerHost.cs index 599be25..c31c2e2 100644 --- a/CorruptSnail/Spawners/SpawnerHost.cs +++ b/CorruptSnail/Spawners/SpawnerHost.cs @@ -1,5 +1,6 @@ using CitizenFX.Core; using CitizenFX.Core.Native; +using CorruptSnail.CPlayer; using CorruptSnail.Util; using System.Threading.Tasks; @@ -7,10 +8,11 @@ namespace CorruptSnail.Spawners { class SpawnerHost : BaseScript { - public const int SPAWN_MIN_DISTANCE = 100; - public const int SPAWN_DESPAWN_DISTANCE = 500; + public const float SPAWN_MIN_DISTANCE = 100f; + public const float SPAWN_DESPAWN_DISTANCE = 350f; public const double SPAWN_EVENT_CHANCE = 0.0005; - private const int SPAWN_HOST_DECIDE_DISTANCE = 500; + public const int SPAWN_TICK_RATE = 100; + private const float SPAWN_HOST_DECIDE_DISTANCE = 500f; public static bool IsHost { get; private set; } @@ -23,25 +25,38 @@ public SpawnerHost() private async Task OnTick() { + await Delay(SPAWN_TICK_RATE); + if (API.NetworkIsSessionStarted() && !API.GetIsLoadingScreenActive()) { - Ped playerPed = LocalPlayer.Character; - int lowestServerId = int.MaxValue; - foreach (Player player in Players) - if (player.Character != null && player.ServerId != LocalPlayer.ServerId - && World.GetDistance(playerPed.Position, player.Character.Position) < SPAWN_HOST_DECIDE_DISTANCE) - if (player.ServerId < lowestServerId) - lowestServerId = player.ServerId; - - bool IsNewHost = LocalPlayer.ServerId < lowestServerId; - if (IsNewHost && !IsHost) + Ped playerPed = Game.PlayerPed; + bool isNewHost = false; + bool isNearSafezone = false; + foreach (Safezones.Safezone safezone in Safezones.SAFEZONES) + if (World.GetDistance(playerPed.Position, safezone.Pos) < safezone.Range) + { + isNearSafezone = true; + break; + } + + if (!isNearSafezone) + { + int lowestServerId = int.MaxValue; + foreach (Player player in Players) + if (player.Character != null && player.ServerId != Game.Player.ServerId + && World.GetDistance(playerPed.Position, player.Character.Position) < SPAWN_HOST_DECIDE_DISTANCE) + if (player.ServerId < lowestServerId) + lowestServerId = player.ServerId; + + isNewHost = Game.Player.ServerId < lowestServerId; + } + + if (isNewHost && !IsHost) Debug.WriteLine("SPAWNER_HOST"); - else if (!IsNewHost && IsHost) + else if (!isNewHost && IsHost) Debug.WriteLine("SPAWNER_SLAVE"); - IsHost = IsNewHost; + IsHost = isNewHost; } - - await Task.FromResult(0); } public static bool CanEventTrigger() diff --git a/CorruptSnail/Spawners/VehicleSpawner.cs b/CorruptSnail/Spawners/VehicleSpawner.cs index 3fd5ed9..81250a6 100644 --- a/CorruptSnail/Spawners/VehicleSpawner.cs +++ b/CorruptSnail/Spawners/VehicleSpawner.cs @@ -7,7 +7,7 @@ namespace CorruptSnail.Spawners class VehicleSpawner : BaseScript { private static VehicleHash[] VEH_LIST { get; } = { VehicleHash.Faggio, VehicleHash.Asterope, VehicleHash.Ingot, - VehicleHash.Asea }; + VehicleHash.Asea, VehicleHash.Sultan, VehicleHash.Technical }; private Vehicle spawnedVeh; @@ -18,24 +18,24 @@ public VehicleSpawner() private async Task OnTick() { + await Delay(SpawnerHost.SPAWN_TICK_RATE); + if (SpawnerHost.CanEventTrigger() && spawnedVeh == null) SpawnRandomVeh(); else if (spawnedVeh != null) - if (!Utils.IsPosInRadiusOfAPlayer(Players, spawnedVeh.Position, SpawnerHost.SPAWN_DESPAWN_DISTANCE) + if (!Utils.IsPosShitSpawn(Players, spawnedVeh.Position, SpawnerHost.SPAWN_DESPAWN_DISTANCE) || spawnedVeh.EngineHealth == 0f) { spawnedVeh.MarkAsNoLongerNeeded(); spawnedVeh = null; } - - await Task.FromResult(0); } private async void SpawnRandomVeh() { - Vector3 spawnPos = Utils.GetRandomSpawnPosFromPlayer(LocalPlayer, SpawnerHost.SPAWN_MIN_DISTANCE, SpawnerHost.SPAWN_DESPAWN_DISTANCE); + Vector3 spawnPos = Utils.GetRandomSpawnPosFromPlayer(Game.Player, SpawnerHost.SPAWN_MIN_DISTANCE, SpawnerHost.SPAWN_DESPAWN_DISTANCE); - if (!Utils.IsPosInRadiusOfAPlayer(Players, spawnPos, SpawnerHost.SPAWN_MIN_DISTANCE)) + if (!Utils.IsPosShitSpawn(Players, spawnPos, SpawnerHost.SPAWN_MIN_DISTANCE)) { Vehicle veh = await World .CreateVehicle(VEH_LIST[Utils.GetRandomInt(VEH_LIST.Length)], spawnPos); diff --git a/CorruptSnail/Spawners/WeaponSpawner.cs b/CorruptSnail/Spawners/WeaponSpawner.cs index 8a700c1..1a4b0ef 100644 --- a/CorruptSnail/Spawners/WeaponSpawner.cs +++ b/CorruptSnail/Spawners/WeaponSpawner.cs @@ -21,35 +21,40 @@ public WeaponSpawner() { weapons = new List(); - Tick += OnTick; + //Tick += OnTick; } private async Task OnTick() { + await Delay(SpawnerHost.SPAWN_TICK_RATE); + if (SpawnerHost.IsHost && weapons.Count < WEAPON_AMOUNT) SpawnRandomWeapon(); else if (weapons.Count > 0) for (int i = weapons.Count - 1; i > 0; i--) { int obj = weapons[i]; - if (!Utils.IsPosInRadiusOfAPlayer(Players, API.GetEntityCoords(obj, false), SpawnerHost.SPAWN_DESPAWN_DISTANCE)) + if (!Utils.IsPosShitSpawn(Players, API.GetEntityCoords(obj, false), SpawnerHost.SPAWN_DESPAWN_DISTANCE)) { API.DeleteObject(ref obj); weapons.Remove(obj); } } - - await Task.FromResult(0); } private void SpawnRandomWeapon() { - Vector3 spawnPos = Utils.GetRandomSpawnPosFromPlayer(LocalPlayer, SpawnerHost.SPAWN_MIN_DISTANCE, SpawnerHost.SPAWN_DESPAWN_DISTANCE); - spawnPos.Z++; + Vector3 spawnPos = Utils.GetRandomSpawnPosFromPlayer(Game.Player, SpawnerHost.SPAWN_MIN_DISTANCE, SpawnerHost.SPAWN_DESPAWN_DISTANCE); - if (!Utils.IsPosInRadiusOfAPlayer(Players, spawnPos, SpawnerHost.SPAWN_MIN_DISTANCE)) + if (!Utils.IsPosShitSpawn(Players, spawnPos, SpawnerHost.SPAWN_MIN_DISTANCE)) { - int obj = API.CreateWeaponObject((uint) WEAPON_LIST[Utils.GetRandomInt(WEAPON_LIST.Length)], Utils.GetRandomInt(WEAPON_MAXAMMO), + uint modelHash = (uint) WEAPON_LIST[Utils.GetRandomInt(WEAPON_LIST.Length)]; + /* while (!API.HasWeaponAssetLoaded(modelHash)) + { + await Delay(1); + API.RequestWeaponAsset(modelHash, 31, 0); + }*/ + int obj = API.CreateWeaponObject(modelHash, Utils.GetRandomInt(WEAPON_MAXAMMO), spawnPos.X, spawnPos.Y, spawnPos.Z, true, Utils.GetRandomFloat(360f), 1); weapons.Add(obj); } diff --git a/CorruptSnail/Spawners/ZombieSpawner.cs b/CorruptSnail/Spawners/ZombieSpawner.cs index f8fbf8f..562f084 100644 --- a/CorruptSnail/Spawners/ZombieSpawner.cs +++ b/CorruptSnail/Spawners/ZombieSpawner.cs @@ -9,7 +9,7 @@ namespace CorruptSnail.Spawners { class ZombieSpawner : BaseScript { - private const int ZOMBIE_AMOUNT = 35; + private const int ZOMBIE_AMOUNT = 30; private const double ZOMBIE_ATTR_CHANCE = 0.5; private const int ZOMBIE_MAX_HEALTH = 500; private const int ZOMBIE_MAX_ARMOR = 500; @@ -28,26 +28,25 @@ public ZombieSpawner() private async Task OnTick() { + await Delay(SpawnerHost.SPAWN_TICK_RATE); + if (SpawnerHost.IsHost && zombies.Count < ZOMBIE_AMOUNT) SpawnRandomZombie(); else if (zombies.Count > 0) foreach (Ped zombie in zombies.ToArray()) - if (!Utils.IsPosInRadiusOfAPlayer(Players, zombie.Position, SpawnerHost.SPAWN_DESPAWN_DISTANCE) + if (!Utils.IsPosShitSpawn(Players, zombie.Position, SpawnerHost.SPAWN_DESPAWN_DISTANCE) || zombie.IsDead) { zombie.MarkAsNoLongerNeeded(); zombies.Remove(zombie); } - - await Task.FromResult(0); } private async void SpawnRandomZombie() { - Vector3 spawnPos = Utils.GetRandomSpawnPosFromPlayer(LocalPlayer, SpawnerHost.SPAWN_MIN_DISTANCE, SpawnerHost.SPAWN_DESPAWN_DISTANCE); - spawnPos.Z++; + Vector3 spawnPos = Utils.GetRandomSpawnPosFromPlayer(Game.Player, SpawnerHost.SPAWN_MIN_DISTANCE, SpawnerHost.SPAWN_DESPAWN_DISTANCE); - if (!Utils.IsPosInRadiusOfAPlayer(Players, spawnPos, SpawnerHost.SPAWN_MIN_DISTANCE)) + if (!Utils.IsPosShitSpawn(Players, spawnPos, SpawnerHost.SPAWN_MIN_DISTANCE)) { Ped zombie = await World.CreatePed(PedHash.Zombie01, spawnPos); int zombieHandle = zombie.Handle; @@ -67,7 +66,7 @@ private async void SpawnRandomZombie() zombie.Health = randHealth; zombie.Armor = Utils.GetRandomInt(ZOMBIE_MAX_ARMOR); zombie.RelationshipGroup = ZombieGroup; - ZombieGroup.SetRelationshipBetweenGroups(LocalPlayer.Character.RelationshipGroup, Relationship.Hate, true); + ZombieGroup.SetRelationshipBetweenGroups(Game.PlayerPed.RelationshipGroup, Relationship.Hate, true); ZombieAttrChances(zombie); zombie.Task.WanderAround(); diff --git a/CorruptSnail/Util/Utils.cs b/CorruptSnail/Util/Utils.cs index 0c2b42b..5bf5f0d 100644 --- a/CorruptSnail/Util/Utils.cs +++ b/CorruptSnail/Util/Utils.cs @@ -1,24 +1,29 @@ using CitizenFX.Core; using CitizenFX.Core.Native; +using CorruptSnail.CPlayer; namespace CorruptSnail.Util { class Utils { - public static Vector3 GetRandomSpawnPosFromPlayer(Player player, int minDist, int maxDist) + public static Vector3 GetRandomSpawnPosFromPlayer(Player player, float minDist, float maxDist) { - Vector3 spawnPos = player.Character.GetOffsetPosition(new Vector3(GetRandomInt(-minDist, minDist), - GetRandomInt(minDist, maxDist), 0f)); + Vector3 spawnPos = player.Character.GetOffsetPosition(new Vector3(GetRandomFloat(-minDist, minDist), + GetRandomFloat(minDist, maxDist), 0f)); spawnPos.Z = World.GetGroundHeight(spawnPos); return spawnPos; } - public static bool IsPosInRadiusOfAPlayer(PlayerList playerList, Vector3 pos, int radius) + public static bool IsPosShitSpawn(PlayerList playerList, Vector3 pos, float radius) { foreach (Player player in playerList) if (player.Character != null && World.GetDistance(player.Character.Position, pos) < radius) return true; + foreach (Safezones.Safezone safezone in Safezones.SAFEZONES) + if (World.GetDistance(pos, safezone.Pos) < safezone.Range) + return true; + return false; } diff --git a/__resource.lua b/__resource.lua index 3e46e92..7124afe 100644 --- a/__resource.lua +++ b/__resource.lua @@ -1,5 +1,8 @@ resource_manifest_version "05cfa83c-a124-4cfa-a768-c24a5811d8f9" -client_script "corruptsnail.net.dll" +client_scripts { + "corruptsnail.net.dll", + "menu.lua" +} server_script "server.lua" \ No newline at end of file diff --git a/menu.lua b/menu.lua new file mode 100644 index 0000000..a2d32df --- /dev/null +++ b/menu.lua @@ -0,0 +1,53 @@ +local ids = {} + +AddEventHandler("menu:setup", function() + TriggerEvent("menu:registerModuleMenu", "Spawn Menu", function(id) + table.insert(ids, id) + + TriggerEvent("menu:addModuleSubMenu", id, "Spawn Vehicle", function(id) + table.insert(ids, id) + TriggerEvent("menu:addModuleItem", id, "Faggio", nil, function(id) table.insert(ids, id) end, function(id) spawnVehicleToPlayer("FAGGIO") end) + TriggerEvent("menu:addModuleItem", id, "Futo", nil, function(id) table.insert(ids, id) end, function(id) spawnVehicleToPlayer("FUTO") end) + TriggerEvent("menu:addModuleItem", id, "Ingot", nil, function(id) table.insert(ids, id) end, function(id) spawnVehicleToPlayer("INGOT") end) + TriggerEvent("menu:addModuleItem", id, "Sultan", nil, function(id) table.insert(ids, id) end, function(id) spawnVehicleToPlayer("SULTAN") end) + TriggerEvent("menu:addModuleItem", id, "Technical", nil, function(id) table.insert(ids, id) end, function(id) spawnVehicleToPlayer("TECHNICAL") end) + end, false) + + TriggerEvent("menu:addModuleSubMenu", id, "Give Weapon", function(id) + table.insert(ids, id) + TriggerEvent("menu:addModuleItem", id, "Give Knife", nil, function(id) table.insert(ids, id) end, function(id) giveWeaponToPlayer("WEAPON_KNIFE") end) + TriggerEvent("menu:addModuleItem", id, "Give Baseball Bat", nil, function(id) table.insert(ids, id) end, function(id) giveWeaponToPlayer("WEAPON_BAT") end) + TriggerEvent("menu:addModuleItem", id, "Give Pistol", nil, function(id) table.insert(ids, id) end, function(id) giveWeaponToPlayer("WEAPON_PISTOL") end) + TriggerEvent("menu:addModuleItem", id, "Give Assault Rifle", nil, function(id) table.insert(ids, id) end, function(id) giveWeaponToPlayer("WEAPON_ASSAULTRIFLE") end) + end, false) + end, false) +end) + +AddEventHandler("corruptsnail:inZone", function(state) + for _, id in ipairs(ids) do + TriggerEvent("menu:setGreyedOut", not state, id) + end +end) + +function giveWeaponToPlayer(weapon) + local playerPed = GetPlayerPed(-1) + GiveWeaponToPed(playerPed, GetHashKey(weapon), 9999, true, true) +end + +function spawnVehicleToPlayer(model) + local x, y, z = table.unpack(GetEntityCoords(GetPlayerPed(-1), true)) + while not HasModelLoaded(model) do + Wait(1) + RequestModel(model) + end + + local veh = CreateVehicle(model, x + 2.5, y + 2.5, z + 1, 0.0, true, true) + SetVehicleAsNoLongerNeeded(veh) + drawNotification("~g~Vehicle spawned!") +end + +function drawNotification(text) + SetNotificationTextEntry("STRING") + AddTextComponentString(text) + DrawNotification(false, false) +end \ No newline at end of file