Skip to content

Commit e104e02

Browse files
authored
Merge pull request #3 from oldnapalm/main
Add zombies resource
2 parents 5988c40 + c433e35 commit e104e02

File tree

9 files changed

+384
-0
lines changed

9 files changed

+384
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Zombies resource for RageCoop-V
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
using GTA;
2+
using RageCoop.Client.Scripting;
3+
using System.Collections.Generic;
4+
using GTA.Native;
5+
using GTA.Math;
6+
7+
namespace RageCoop.Resources.Zombies
8+
{
9+
public class Main : ClientScript
10+
{
11+
private int _level;
12+
private int _kills;
13+
14+
private readonly List<Ped> _zombies = new List<Ped>();
15+
private readonly List<Vehicle> _zombieVehicles = new List<Vehicle>();
16+
17+
private RelationshipGroup _zombieGroup;
18+
19+
public override void OnStart()
20+
{
21+
API.Events.OnTick += OnTick;
22+
23+
API.RegisterCustomEventHandler(Events.Start, Start);
24+
25+
API.QueueAction(() => {
26+
_zombieGroup = World.AddRelationshipGroup("ZOMBIES_MOD");
27+
});
28+
}
29+
30+
public override void OnStop()
31+
{
32+
API.Events.OnTick -= OnTick;
33+
34+
API.QueueAction(() =>
35+
{
36+
foreach (var ped in _zombies)
37+
{
38+
ped.MarkAsNoLongerNeeded();
39+
ped.Delete();
40+
}
41+
foreach (var veh in _zombieVehicles)
42+
{
43+
veh.MarkAsNoLongerNeeded();
44+
veh.Delete();
45+
}
46+
_zombies.Clear();
47+
_zombieVehicles.Clear();
48+
});
49+
}
50+
51+
private void Start(CustomEventReceivedArgs obj)
52+
{
53+
_kills = (int)obj.Args[0];
54+
_level = (int)obj.Args[1];
55+
}
56+
57+
private void OnTick()
58+
{
59+
Ped player = Game.Player.Character;
60+
61+
foreach (var ped in World.GetNearbyPeds(player, 400))
62+
{
63+
if (ped.PopulationType != EntityPopulationType.RandomAmbient && ped.PopulationType != EntityPopulationType.RandomScenario && !_zombies.Contains(ped))
64+
continue;
65+
66+
if (ped.IsInVehicle())
67+
{
68+
ped.CurrentVehicle.EngineHealth = 0;
69+
_zombieVehicles.Add(ped.CurrentVehicle);
70+
}
71+
72+
if (ped.IsAlive && ped.IsHuman)
73+
{
74+
if (ped.RelationshipGroup != _zombieGroup)
75+
Zombify(ped);
76+
else if (ped.Position.DistanceTo(player.Position) < 1 && !player.IsGettingUp && !player.IsRagdoll)
77+
{
78+
Function.Call(Hash.APPLY_DAMAGE_TO_PED, player, 15);
79+
Function.Call(Hash.SET_PED_TO_RAGDOLL, player, 1, 9000, 9000, 1, 1, 1);
80+
Function.Call(Hash.SET_PED_TO_RAGDOLL, ped, 1, 100, 100, 1, 1, 1);
81+
ped.ApplyForceRelative(new Vector3(0, 1, 2));
82+
player.ApplyForceRelative(new Vector3(0, -2, -10));
83+
}
84+
}
85+
86+
if (ped.IsDead && !ped.IsOnScreen)
87+
{
88+
ped.MarkAsNoLongerNeeded();
89+
ped.Delete();
90+
}
91+
}
92+
93+
foreach (var ped in _zombies.ToArray())
94+
{
95+
if (!ped.Exists())
96+
{
97+
_zombies.Remove(ped);
98+
continue;
99+
}
100+
101+
if (ped.IsDead)
102+
{
103+
if (ped.Killer == player)
104+
{
105+
_kills++;
106+
if (_kills >= _level * 10)
107+
{
108+
_level++;
109+
API.SendCustomEvent(Events.LevelUp, _kills, _level);
110+
}
111+
}
112+
_zombies.Remove(ped);
113+
}
114+
115+
if (ped.Position.DistanceTo(player.Position) > 400)
116+
{
117+
ped.MarkAsNoLongerNeeded();
118+
ped.Delete();
119+
}
120+
}
121+
122+
foreach (var veh in _zombieVehicles.ToArray())
123+
{
124+
if (!veh.Exists())
125+
{
126+
_zombieVehicles.Remove(veh);
127+
continue;
128+
}
129+
130+
if (veh.Position.DistanceTo(player.Position) > 400)
131+
{
132+
veh.MarkAsNoLongerNeeded();
133+
veh.Delete();
134+
}
135+
}
136+
137+
if (_zombies.Count < 20)
138+
{
139+
var ped = World.CreateRandomPed(player.Position.Around(100));
140+
if (ped != null)
141+
_zombies.Add(ped);
142+
}
143+
}
144+
145+
private void Zombify(Ped ped)
146+
{
147+
if (!Function.Call<bool>(Hash.HAS_CLIP_SET_LOADED, "move_m@drunk@verydrunk"))
148+
{
149+
Function.Call(Hash.REQUEST_CLIP_SET, "move_m@drunk@verydrunk");
150+
return;
151+
}
152+
Function.Call(Hash.SET_PED_MOVEMENT_CLIPSET, ped.Handle, "move_m@drunk@verydrunk", 1);
153+
Function.Call(Hash.APPLY_PED_DAMAGE_PACK, ped, "BigHitByVehicle", 0, 9);
154+
Function.Call(Hash.APPLY_PED_DAMAGE_PACK, ped, "SCR_Dumpster", 0, 9);
155+
Function.Call(Hash.APPLY_PED_DAMAGE_PACK, ped, "SCR_Torture", 0, 9);
156+
Function.Call(Hash.STOP_PED_SPEAKING, ped.Handle, true);
157+
Function.Call(Hash.DISABLE_PED_PAIN_AUDIO, ped.Handle, true);
158+
Function.Call(Hash.SET_BLOCKING_OF_NON_TEMPORARY_EVENTS, ped, 1);
159+
Function.Call(Hash.SET_PED_FLEE_ATTRIBUTES, ped, 0, 0);
160+
Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, ped, 46, 1);
161+
162+
ped.Task.GoTo(Game.Player.Character);
163+
ped.AlwaysKeepTask = true;
164+
ped.IsEnemy = true;
165+
ped.Health = 3000;
166+
ped.RelationshipGroup = _zombieGroup;
167+
168+
if (!_zombies.Contains(ped))
169+
_zombies.Add(ped);
170+
}
171+
}
172+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net48</TargetFramework>
5+
<OutDir>..\..\..\..\..\RageCoop-V\bin\Debug\Server\Resources\Client\RageCoop.Resources.Zombies.Client</OutDir>
6+
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
7+
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\RageCoop.Resources.Zombies.Shared\RageCoop.Resources.Zombies.Shared.csproj" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<Reference Include="RageCoop.Client">
16+
<HintPath>..\..\..\..\RageCoop.Client.dll</HintPath>
17+
</Reference>
18+
<Reference Include="RageCoop.Core">
19+
<HintPath>..\..\..\..\RageCoop.Core.dll</HintPath>
20+
</Reference>
21+
<Reference Include="ScriptHookVDotNet3">
22+
<HintPath>..\..\..\..\ScriptHookVDotNet3.dll</HintPath>
23+
</Reference>
24+
<Reference Include="System.Windows.Forms" />
25+
</ItemGroup>
26+
27+
</Project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using RageCoop.Core.Scripting;
2+
3+
namespace RageCoop.Resources.Zombies
4+
{
5+
public static class Events
6+
{
7+
public static int Start = CustomEvents.Hash("RageCoop.Resources.Zombies.Start");
8+
public static int LevelUp = CustomEvents.Hash("RageCoop.Resources.Zombies.LevelUp");
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<Reference Include="RageCoop.Core">
9+
<HintPath>..\..\..\..\RageCoop.Core.dll</HintPath>
10+
</Reference>
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Blend for Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31912.275
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{1D65A98F-3FCA-48E8-AF07-6016D96E3B10}") = "RageCoop.Resources.Zombies", "RageCoop.Resources.Zombies\RageCoop.Resources.Zombies.csproj", "{68A438B4-67AE-47B5-94B6-3AF855492437}"
7+
EndProject
8+
Project("{1D65A98F-3FCA-48E8-AF07-6016D96E3B10}") = "RageCoop.Resources.Zombies.Client", "RageCoop.Resources.Zombies.Client\RageCoop.Resources.Zombies.Client.csproj", "{CF340EFE-96A5-4883-926C-D5B7EE2448A2}"
9+
EndProject
10+
Project("{1D65A98F-3FCA-48E8-AF07-6016D96E3B10}") = "RageCoop.Resources.Zombies.Shared", "RageCoop.Resources.Zombies.Shared\RageCoop.Resources.Zombies.Shared.csproj", "{D1B73BD3-CA51-43F4-BE15-B0C3F6F29B7D}"
11+
EndProject
12+
Global
13+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
14+
Debug|Any CPU = Debug|Any CPU
15+
Release|Any CPU = Release|Any CPU
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{68A438B4-67AE-47B5-94B6-3AF855492437}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{68A438B4-67AE-47B5-94B6-3AF855492437}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{68A438B4-67AE-47B5-94B6-3AF855492437}.Release|Any CPU.ActiveCfg = Release|Any CPU
21+
{68A438B4-67AE-47B5-94B6-3AF855492437}.Release|Any CPU.Build.0 = Release|Any CPU
22+
{CF340EFE-96A5-4883-926C-D5B7EE2448A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23+
{CF340EFE-96A5-4883-926C-D5B7EE2448A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
24+
{CF340EFE-96A5-4883-926C-D5B7EE2448A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
25+
{CF340EFE-96A5-4883-926C-D5B7EE2448A2}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{D1B73BD3-CA51-43F4-BE15-B0C3F6F29B7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{D1B73BD3-CA51-43F4-BE15-B0C3F6F29B7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{D1B73BD3-CA51-43F4-BE15-B0C3F6F29B7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{D1B73BD3-CA51-43F4-BE15-B0C3F6F29B7D}.Release|Any CPU.Build.0 = Release|Any CPU
30+
EndGlobalSection
31+
GlobalSection(SolutionProperties) = preSolution
32+
HideSolutionNode = FALSE
33+
EndGlobalSection
34+
GlobalSection(ExtensibilityGlobals) = postSolution
35+
SolutionGuid = {297AADAB-5771-47E2-A939-B0793C4EF1CA}
36+
EndGlobalSection
37+
EndGlobal
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using RageCoop.Server;
2+
using RageCoop.Server.Scripting;
3+
using LiteDB;
4+
5+
namespace RageCoop.Resources.Zombies
6+
{
7+
public class Main : ServerScript
8+
{
9+
private static LiteDatabase DB;
10+
private static ILiteCollection<Record> Records;
11+
12+
public override void OnStart()
13+
{
14+
API.Events.OnPlayerReady += (s, c) =>
15+
{
16+
int kills = 0;
17+
int level = 1;
18+
var player = Records.Query().Where(x => x.Player == c.Username.ToLower()).FirstOrDefault();
19+
if (player != null)
20+
{
21+
kills = player.Kills;
22+
level = player.Level;
23+
}
24+
c.SendCustomEvent(Events.Start, kills, level);
25+
};
26+
API.Events.OnPlayerDisconnected += (s, c) =>
27+
{
28+
};
29+
API.Events.OnPlayerUpdate += OnPlayerUpdate;
30+
31+
API.RegisterCommands(this);
32+
API.RegisterCustomEventHandler(Events.LevelUp, LevelUp);
33+
34+
DB = new LiteDatabase(@$"Filename={Path.Combine(CurrentResource.DataFolder, "Records.db")}; Connection=Shared;");
35+
Records = DB.GetCollection<Record>();
36+
37+
CurrentResource.Logger.Info("Zombies resource started");
38+
}
39+
40+
public override void OnStop()
41+
{
42+
DB.Dispose();
43+
44+
CurrentResource.Logger.Info($"Zombies resource stopped");
45+
}
46+
47+
private void OnPlayerUpdate(object s, Client c)
48+
{
49+
}
50+
51+
public void LevelUp(CustomEventReceivedArgs obj)
52+
{
53+
var kills = (int)obj.Args[0];
54+
var level = (int)obj.Args[1];
55+
API.SendChatMessage($"{obj.Client.Username} killed {kills} zombies, advanced to level {level}");
56+
57+
var player = Records.Query().Where(x => x.Player == obj.Client.Username.ToLower()).FirstOrDefault();
58+
if (player != null)
59+
{
60+
player.Kills = kills;
61+
player.Level = level;
62+
Records.Update(player);
63+
}
64+
else
65+
Records.Insert(new Record()
66+
{
67+
Player = obj.Client.Username.ToLower(),
68+
Kills = kills,
69+
Level = level
70+
});
71+
}
72+
}
73+
74+
public class Record
75+
{
76+
public int Id { get; set; }
77+
public string Player { get; set; }
78+
public int Kills { get; set; }
79+
public int Level { get; set; }
80+
}
81+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<OutDir>..\..\..\..\..\RageCoop-V\bin\Debug\Server\Resources\Server\RageCoop.Resources.Zombies</OutDir>
7+
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
8+
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="..\RageCoop.Resources.Zombies.Shared\RageCoop.Resources.Zombies.Shared.csproj" />
13+
</ItemGroup>
14+
<ItemGroup>
15+
<None Include="$(ProjectDir)Maps\**" CopyToOutputDirectory="PreserveNewest" />
16+
<None Include="$(ProjectDir)RuntimeLibs\**" CopyToOutputDirectory="PreserveNewest" />
17+
18+
</ItemGroup>
19+
<ItemGroup>
20+
<PackageReference Include="LiteDB" Version="5.0.17" />
21+
</ItemGroup>
22+
<ItemGroup>
23+
<Reference Include="RageCoop.Core">
24+
<HintPath>..\..\..\..\RageCoop.Core.dll</HintPath>
25+
</Reference>
26+
<Reference Include="RageCoop.Server">
27+
<HintPath>..\..\..\..\RageCoop.Server.dll</HintPath>
28+
</Reference>
29+
<Reference Include="ScriptHookVDotNet">
30+
<HintPath>..\..\..\..\ScriptHookVDotNet.dll</HintPath>
31+
</Reference>
32+
<Reference Include="ScriptHookVDotNet3">
33+
<HintPath>..\..\..\..\ScriptHookVDotNet3.dll</HintPath>
34+
</Reference>
35+
</ItemGroup>
36+
</Project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"Name": "RageCoop.Resources.Zombies",
3+
"Description": "Zombies resource for RAGECOOP-V",
4+
"ClientResources": ["RageCoop.Resources.Zombies.Client/RageCoop.Resources.Zombies.Client.csproj"],
5+
"ServerResources": ["RageCoop.Resources.Zombies/RageCoop.Resources.Zombies.csproj"],
6+
"Version": "0.1"
7+
}

0 commit comments

Comments
 (0)