Skip to content

Commit

Permalink
Lower tickrate for performance & disable weapon spawning for now & mi…
Browse files Browse the repository at this point in the history
…nor stuffs
  • Loading branch information
pongo1231 committed May 26, 2018
1 parent ff37ecb commit 519c5a0
Show file tree
Hide file tree
Showing 16 changed files with 243 additions and 80 deletions.
18 changes: 18 additions & 0 deletions CorruptSnail/CPlayer/PlayerSpawner.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
63 changes: 63 additions & 0 deletions CorruptSnail/CPlayer/Safezones.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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<float>(veh, VEH_FUEL_DECOR) - veh.Speed * 0.01f;
float newFuelLevel = EntityDecoration.Get<float>(veh, VEH_FUEL_DECOR) - veh.Speed * 0.1f;
if (newFuelLevel < 0f)
newFuelLevel = 0f;
EntityDecoration.Set(veh, VEH_FUEL_DECOR, newFuelLevel);
Expand All @@ -45,8 +48,6 @@ private async Task OnTick()
Screen.DisplayHelpTextThisFrame("Low Fuel Level");
}
}

await Task.FromResult(0);
}
}
}
4 changes: 3 additions & 1 deletion CorruptSnail/CorruptSnail.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CPlayer\PlayerSpawner.cs" />
<Compile Include="CPlayer\Safezones.cs" />
<Compile Include="Spawners\Ambient\AmbientWarNoiseSpawner.cs" />
<Compile Include="Spawners\Ambient\FlyingByPlaneSpawner.cs" />
<Compile Include="Spawners\Events\RebelSquadSpawner.cs" />
Expand All @@ -58,7 +60,7 @@
<Compile Include="Atmosphere.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Util\Utils.cs" />
<Compile Include="VehFuelHandler.cs" />
<Compile Include="CVehicle\VehFuelHandler.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
8 changes: 4 additions & 4 deletions CorruptSnail/Spawners/Ambient/AmbientWarNoiseSpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
10 changes: 5 additions & 5 deletions CorruptSnail/Spawners/Ambient/FlyingByPlaneSpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
14 changes: 7 additions & 7 deletions CorruptSnail/Spawners/Events/ArmyHeliSquadSpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,27 @@ 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();
armyHeliSquad.Gunman1.MarkAsNoLongerNeeded();
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));
Expand All @@ -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);
Expand All @@ -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]);
Expand Down
15 changes: 7 additions & 8 deletions CorruptSnail/Spawners/Events/RebelSquadSpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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];
Expand All @@ -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);

Expand Down
12 changes: 6 additions & 6 deletions CorruptSnail/Spawners/ObjectSpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 519c5a0

Please sign in to comment.