-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from oldnapalm/main
Add zombies resource
- Loading branch information
Showing
9 changed files
with
384 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Zombies resource for RageCoop-V |
172 changes: 172 additions & 0 deletions
172
Resources/RageCoop/RageCoop.Resources.Zombies/RageCoop.Resources.Zombies.Client/Main.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
using GTA; | ||
using RageCoop.Client.Scripting; | ||
using System.Collections.Generic; | ||
using GTA.Native; | ||
using GTA.Math; | ||
|
||
namespace RageCoop.Resources.Zombies | ||
{ | ||
public class Main : ClientScript | ||
{ | ||
private int _level; | ||
private int _kills; | ||
|
||
private readonly List<Ped> _zombies = new List<Ped>(); | ||
private readonly List<Vehicle> _zombieVehicles = new List<Vehicle>(); | ||
|
||
private RelationshipGroup _zombieGroup; | ||
|
||
public override void OnStart() | ||
{ | ||
API.Events.OnTick += OnTick; | ||
|
||
API.RegisterCustomEventHandler(Events.Start, Start); | ||
|
||
API.QueueAction(() => { | ||
_zombieGroup = World.AddRelationshipGroup("ZOMBIES_MOD"); | ||
}); | ||
} | ||
|
||
public override void OnStop() | ||
{ | ||
API.Events.OnTick -= OnTick; | ||
|
||
API.QueueAction(() => | ||
{ | ||
foreach (var ped in _zombies) | ||
{ | ||
ped.MarkAsNoLongerNeeded(); | ||
ped.Delete(); | ||
} | ||
foreach (var veh in _zombieVehicles) | ||
{ | ||
veh.MarkAsNoLongerNeeded(); | ||
veh.Delete(); | ||
} | ||
_zombies.Clear(); | ||
_zombieVehicles.Clear(); | ||
}); | ||
} | ||
|
||
private void Start(CustomEventReceivedArgs obj) | ||
{ | ||
_kills = (int)obj.Args[0]; | ||
_level = (int)obj.Args[1]; | ||
} | ||
|
||
private void OnTick() | ||
{ | ||
Ped player = Game.Player.Character; | ||
|
||
foreach (var ped in World.GetNearbyPeds(player, 400)) | ||
{ | ||
if (ped.PopulationType != EntityPopulationType.RandomAmbient && ped.PopulationType != EntityPopulationType.RandomScenario && !_zombies.Contains(ped)) | ||
continue; | ||
|
||
if (ped.IsInVehicle()) | ||
{ | ||
ped.CurrentVehicle.EngineHealth = 0; | ||
_zombieVehicles.Add(ped.CurrentVehicle); | ||
} | ||
|
||
if (ped.IsAlive && ped.IsHuman) | ||
{ | ||
if (ped.RelationshipGroup != _zombieGroup) | ||
Zombify(ped); | ||
else if (ped.Position.DistanceTo(player.Position) < 1 && !player.IsGettingUp && !player.IsRagdoll) | ||
{ | ||
Function.Call(Hash.APPLY_DAMAGE_TO_PED, player, 15); | ||
Function.Call(Hash.SET_PED_TO_RAGDOLL, player, 1, 9000, 9000, 1, 1, 1); | ||
Function.Call(Hash.SET_PED_TO_RAGDOLL, ped, 1, 100, 100, 1, 1, 1); | ||
ped.ApplyForceRelative(new Vector3(0, 1, 2)); | ||
player.ApplyForceRelative(new Vector3(0, -2, -10)); | ||
} | ||
} | ||
|
||
if (ped.IsDead && !ped.IsOnScreen) | ||
{ | ||
ped.MarkAsNoLongerNeeded(); | ||
ped.Delete(); | ||
} | ||
} | ||
|
||
foreach (var ped in _zombies.ToArray()) | ||
{ | ||
if (!ped.Exists()) | ||
{ | ||
_zombies.Remove(ped); | ||
continue; | ||
} | ||
|
||
if (ped.IsDead) | ||
{ | ||
if (ped.Killer == player) | ||
{ | ||
_kills++; | ||
if (_kills >= _level * 10) | ||
{ | ||
_level++; | ||
API.SendCustomEvent(Events.LevelUp, _kills, _level); | ||
} | ||
} | ||
_zombies.Remove(ped); | ||
} | ||
|
||
if (ped.Position.DistanceTo(player.Position) > 400) | ||
{ | ||
ped.MarkAsNoLongerNeeded(); | ||
ped.Delete(); | ||
} | ||
} | ||
|
||
foreach (var veh in _zombieVehicles.ToArray()) | ||
{ | ||
if (!veh.Exists()) | ||
{ | ||
_zombieVehicles.Remove(veh); | ||
continue; | ||
} | ||
|
||
if (veh.Position.DistanceTo(player.Position) > 400) | ||
{ | ||
veh.MarkAsNoLongerNeeded(); | ||
veh.Delete(); | ||
} | ||
} | ||
|
||
if (_zombies.Count < 20) | ||
{ | ||
var ped = World.CreateRandomPed(player.Position.Around(100)); | ||
if (ped != null) | ||
_zombies.Add(ped); | ||
} | ||
} | ||
|
||
private void Zombify(Ped ped) | ||
{ | ||
if (!Function.Call<bool>(Hash.HAS_CLIP_SET_LOADED, "move_m@drunk@verydrunk")) | ||
{ | ||
Function.Call(Hash.REQUEST_CLIP_SET, "move_m@drunk@verydrunk"); | ||
return; | ||
} | ||
Function.Call(Hash.SET_PED_MOVEMENT_CLIPSET, ped.Handle, "move_m@drunk@verydrunk", 1); | ||
Function.Call(Hash.APPLY_PED_DAMAGE_PACK, ped, "BigHitByVehicle", 0, 9); | ||
Function.Call(Hash.APPLY_PED_DAMAGE_PACK, ped, "SCR_Dumpster", 0, 9); | ||
Function.Call(Hash.APPLY_PED_DAMAGE_PACK, ped, "SCR_Torture", 0, 9); | ||
Function.Call(Hash.STOP_PED_SPEAKING, ped.Handle, true); | ||
Function.Call(Hash.DISABLE_PED_PAIN_AUDIO, ped.Handle, true); | ||
Function.Call(Hash.SET_BLOCKING_OF_NON_TEMPORARY_EVENTS, ped, 1); | ||
Function.Call(Hash.SET_PED_FLEE_ATTRIBUTES, ped, 0, 0); | ||
Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, ped, 46, 1); | ||
|
||
ped.Task.GoTo(Game.Player.Character); | ||
ped.AlwaysKeepTask = true; | ||
ped.IsEnemy = true; | ||
ped.Health = 3000; | ||
ped.RelationshipGroup = _zombieGroup; | ||
|
||
if (!_zombies.Contains(ped)) | ||
_zombies.Add(ped); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ources.Zombies/RageCoop.Resources.Zombies.Client/RageCoop.Resources.Zombies.Client.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net48</TargetFramework> | ||
<OutDir>..\..\..\..\..\RageCoop-V\bin\Debug\Server\Resources\Client\RageCoop.Resources.Zombies.Client</OutDir> | ||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks> | ||
|
||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\RageCoop.Resources.Zombies.Shared\RageCoop.Resources.Zombies.Shared.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="RageCoop.Client"> | ||
<HintPath>..\..\..\..\RageCoop.Client.dll</HintPath> | ||
</Reference> | ||
<Reference Include="RageCoop.Core"> | ||
<HintPath>..\..\..\..\RageCoop.Core.dll</HintPath> | ||
</Reference> | ||
<Reference Include="ScriptHookVDotNet3"> | ||
<HintPath>..\..\..\..\ScriptHookVDotNet3.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Windows.Forms" /> | ||
</ItemGroup> | ||
|
||
</Project> |
10 changes: 10 additions & 0 deletions
10
Resources/RageCoop/RageCoop.Resources.Zombies/RageCoop.Resources.Zombies.Shared/Events.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using RageCoop.Core.Scripting; | ||
|
||
namespace RageCoop.Resources.Zombies | ||
{ | ||
public static class Events | ||
{ | ||
public static int Start = CustomEvents.Hash("RageCoop.Resources.Zombies.Start"); | ||
public static int LevelUp = CustomEvents.Hash("RageCoop.Resources.Zombies.LevelUp"); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...ources.Zombies/RageCoop.Resources.Zombies.Shared/RageCoop.Resources.Zombies.Shared.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="RageCoop.Core"> | ||
<HintPath>..\..\..\..\RageCoop.Core.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
|
||
</Project> |
37 changes: 37 additions & 0 deletions
37
Resources/RageCoop/RageCoop.Resources.Zombies/RageCoop.Resources.Zombies.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Blend for Visual Studio Version 17 | ||
VisualStudioVersion = 17.0.31912.275 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{1D65A98F-3FCA-48E8-AF07-6016D96E3B10}") = "RageCoop.Resources.Zombies", "RageCoop.Resources.Zombies\RageCoop.Resources.Zombies.csproj", "{68A438B4-67AE-47B5-94B6-3AF855492437}" | ||
EndProject | ||
Project("{1D65A98F-3FCA-48E8-AF07-6016D96E3B10}") = "RageCoop.Resources.Zombies.Client", "RageCoop.Resources.Zombies.Client\RageCoop.Resources.Zombies.Client.csproj", "{CF340EFE-96A5-4883-926C-D5B7EE2448A2}" | ||
EndProject | ||
Project("{1D65A98F-3FCA-48E8-AF07-6016D96E3B10}") = "RageCoop.Resources.Zombies.Shared", "RageCoop.Resources.Zombies.Shared\RageCoop.Resources.Zombies.Shared.csproj", "{D1B73BD3-CA51-43F4-BE15-B0C3F6F29B7D}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{68A438B4-67AE-47B5-94B6-3AF855492437}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{68A438B4-67AE-47B5-94B6-3AF855492437}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{68A438B4-67AE-47B5-94B6-3AF855492437}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{68A438B4-67AE-47B5-94B6-3AF855492437}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{CF340EFE-96A5-4883-926C-D5B7EE2448A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{CF340EFE-96A5-4883-926C-D5B7EE2448A2}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{CF340EFE-96A5-4883-926C-D5B7EE2448A2}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{CF340EFE-96A5-4883-926C-D5B7EE2448A2}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{D1B73BD3-CA51-43F4-BE15-B0C3F6F29B7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{D1B73BD3-CA51-43F4-BE15-B0C3F6F29B7D}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{D1B73BD3-CA51-43F4-BE15-B0C3F6F29B7D}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{D1B73BD3-CA51-43F4-BE15-B0C3F6F29B7D}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {297AADAB-5771-47E2-A939-B0793C4EF1CA} | ||
EndGlobalSection | ||
EndGlobal |
81 changes: 81 additions & 0 deletions
81
Resources/RageCoop/RageCoop.Resources.Zombies/RageCoop.Resources.Zombies/Main.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using RageCoop.Server; | ||
using RageCoop.Server.Scripting; | ||
using LiteDB; | ||
|
||
namespace RageCoop.Resources.Zombies | ||
{ | ||
public class Main : ServerScript | ||
{ | ||
private static LiteDatabase DB; | ||
private static ILiteCollection<Record> Records; | ||
|
||
public override void OnStart() | ||
{ | ||
API.Events.OnPlayerReady += (s, c) => | ||
{ | ||
int kills = 0; | ||
int level = 1; | ||
var player = Records.Query().Where(x => x.Player == c.Username.ToLower()).FirstOrDefault(); | ||
if (player != null) | ||
{ | ||
kills = player.Kills; | ||
level = player.Level; | ||
} | ||
c.SendCustomEvent(Events.Start, kills, level); | ||
}; | ||
API.Events.OnPlayerDisconnected += (s, c) => | ||
{ | ||
}; | ||
API.Events.OnPlayerUpdate += OnPlayerUpdate; | ||
|
||
API.RegisterCommands(this); | ||
API.RegisterCustomEventHandler(Events.LevelUp, LevelUp); | ||
|
||
DB = new LiteDatabase(@$"Filename={Path.Combine(CurrentResource.DataFolder, "Records.db")}; Connection=Shared;"); | ||
Records = DB.GetCollection<Record>(); | ||
|
||
CurrentResource.Logger.Info("Zombies resource started"); | ||
} | ||
|
||
public override void OnStop() | ||
{ | ||
DB.Dispose(); | ||
|
||
CurrentResource.Logger.Info($"Zombies resource stopped"); | ||
} | ||
|
||
private void OnPlayerUpdate(object s, Client c) | ||
{ | ||
} | ||
|
||
public void LevelUp(CustomEventReceivedArgs obj) | ||
{ | ||
var kills = (int)obj.Args[0]; | ||
var level = (int)obj.Args[1]; | ||
API.SendChatMessage($"{obj.Client.Username} killed {kills} zombies, advanced to level {level}"); | ||
|
||
var player = Records.Query().Where(x => x.Player == obj.Client.Username.ToLower()).FirstOrDefault(); | ||
if (player != null) | ||
{ | ||
player.Kills = kills; | ||
player.Level = level; | ||
Records.Update(player); | ||
} | ||
else | ||
Records.Insert(new Record() | ||
{ | ||
Player = obj.Client.Username.ToLower(), | ||
Kills = kills, | ||
Level = level | ||
}); | ||
} | ||
} | ||
|
||
public class Record | ||
{ | ||
public int Id { get; set; } | ||
public string Player { get; set; } | ||
public int Kills { get; set; } | ||
public int Level { get; set; } | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...p/RageCoop.Resources.Zombies/RageCoop.Resources.Zombies/RageCoop.Resources.Zombies.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<OutDir>..\..\..\..\..\RageCoop-V\bin\Debug\Server\Resources\Server\RageCoop.Resources.Zombies</OutDir> | ||
<ProduceReferenceAssembly>False</ProduceReferenceAssembly> | ||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\RageCoop.Resources.Zombies.Shared\RageCoop.Resources.Zombies.Shared.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="$(ProjectDir)Maps\**" CopyToOutputDirectory="PreserveNewest" /> | ||
<None Include="$(ProjectDir)RuntimeLibs\**" CopyToOutputDirectory="PreserveNewest" /> | ||
|
||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="LiteDB" Version="5.0.17" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Reference Include="RageCoop.Core"> | ||
<HintPath>..\..\..\..\RageCoop.Core.dll</HintPath> | ||
</Reference> | ||
<Reference Include="RageCoop.Server"> | ||
<HintPath>..\..\..\..\RageCoop.Server.dll</HintPath> | ||
</Reference> | ||
<Reference Include="ScriptHookVDotNet"> | ||
<HintPath>..\..\..\..\ScriptHookVDotNet.dll</HintPath> | ||
</Reference> | ||
<Reference Include="ScriptHookVDotNet3"> | ||
<HintPath>..\..\..\..\ScriptHookVDotNet3.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
</Project> |
7 changes: 7 additions & 0 deletions
7
Resources/RageCoop/RageCoop.Resources.Zombies/ResourceManifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"Name": "RageCoop.Resources.Zombies", | ||
"Description": "Zombies resource for RAGECOOP-V", | ||
"ClientResources": ["RageCoop.Resources.Zombies.Client/RageCoop.Resources.Zombies.Client.csproj"], | ||
"ServerResources": ["RageCoop.Resources.Zombies/RageCoop.Resources.Zombies.csproj"], | ||
"Version": "0.1" | ||
} |