Skip to content

Commit 57b9113

Browse files
committed
Add Gang Wars resource
1 parent f42ff38 commit 57b9113

File tree

9 files changed

+493
-0
lines changed

9 files changed

+493
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Gang Wars resource for RageCoop-V
Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
using GTA.UI;
2+
using GTA;
3+
using RageCoop.Client.Scripting;
4+
using System.Collections.Generic;
5+
using System;
6+
using GTA.Native;
7+
using GTA.Math;
8+
9+
namespace RageCoop.Resources.GangWars
10+
{
11+
public class Main : ClientScript
12+
{
13+
private int _level;
14+
private int _kills;
15+
16+
private readonly List<Enemy> _enemies = new List<Enemy>();
17+
private readonly List<Vehicle> _enemyVehicles = new List<Vehicle>();
18+
19+
private Vehicle _hostVehicle;
20+
21+
private RelationshipGroup _enemyGroup;
22+
23+
private readonly Random _rndGet = new Random();
24+
25+
private readonly WeaponHash[] _weaponList = {
26+
WeaponHash.Pistol,
27+
WeaponHash.CombatPistol,
28+
WeaponHash.APPistol,
29+
WeaponHash.BullpupShotgun,
30+
WeaponHash.SawnOffShotgun,
31+
WeaponHash.MicroSMG,
32+
WeaponHash.SMG,
33+
WeaponHash.AssaultRifle,
34+
WeaponHash.CarbineRifle
35+
};
36+
37+
private readonly Model[] _vehicleList = {
38+
new Model(VehicleHash.Oracle),
39+
new Model(VehicleHash.Buffalo),
40+
new Model(VehicleHash.Exemplar),
41+
new Model(VehicleHash.Sultan),
42+
new Model(VehicleHash.Tailgater)
43+
};
44+
45+
public override void OnStart()
46+
{
47+
API.RegisterCustomEventHandler(Events.Start, Start);
48+
API.RegisterCustomEventHandler(Events.Stop, Stop);
49+
API.Events.OnTick+=OnTick;
50+
51+
API.QueueAction(() => {
52+
_enemyGroup = World.AddRelationshipGroup("GANGS_MOD");
53+
});
54+
}
55+
56+
public override void OnStop()
57+
{
58+
API.QueueAction(() =>
59+
{
60+
StopMissions();
61+
});
62+
}
63+
64+
private void OnTick()
65+
{
66+
Ped player = Game.Player.Character;
67+
68+
for (int i = 0; i < _enemies.Count; i++)
69+
{
70+
if (_enemies[i].ped.IsDead)
71+
{
72+
_kills++;
73+
Game.Player.Money += 20 * _level;
74+
_enemies[i].ped.MarkAsNoLongerNeeded();
75+
_enemies[i].blip.Delete();
76+
_enemies.RemoveAt(i);
77+
if (_enemies.Count == 0)
78+
{
79+
foreach (var item in _enemyVehicles)
80+
item.MarkAsNoLongerNeeded();
81+
_enemyVehicles.Clear();
82+
_level++;
83+
API.SendCustomEvent(Events.MissionAccomplished, _kills, _level);
84+
StartMissions(_kills, _level);
85+
}
86+
}
87+
else
88+
{
89+
if (_enemies[i].ped.IsInVehicle())
90+
{
91+
if ((player.Position - _enemies[i].ped.Position).Length() < 40.0f && !_enemies[i].spooked)
92+
{
93+
_enemies[i].spooked = true;
94+
Function.Call(Hash.SET_DRIVE_TASK_CRUISE_SPEED, _enemies[i].ped.Handle, 60.0f);
95+
}
96+
97+
if ((player.Position - _enemies[i].ped.Position).Length() < 50.0f && _enemies[i].ped.CurrentVehicle.Speed < 1.0f && _enemies[i].spooked && !_enemies[i].fighting)
98+
{
99+
_enemies[i].fighting = true;
100+
TaskSequence tasks = new TaskSequence();
101+
tasks.AddTask.LeaveVehicle();
102+
tasks.AddTask.FightAgainst(player);
103+
tasks.Close();
104+
_enemies[i].ped.Task.PerformSequence(tasks);
105+
}
106+
}
107+
else
108+
{
109+
if ((player.Position - _enemies[i].ped.Position).Length() < 60.0f)
110+
{
111+
if (!_enemies[i].fighting)
112+
{
113+
_enemies[i].fighting = true;
114+
_enemies[i].ped.Task.FightAgainst(player);
115+
}
116+
}
117+
else if (_enemies[i].ped.LastVehicle.IsAlive)
118+
{
119+
_enemies[i].fighting = false;
120+
TaskSequence tasks = new TaskSequence();
121+
tasks.AddTask.EnterVehicle(_enemies[i].ped.LastVehicle, VehicleSeat.Driver);
122+
tasks.AddTask.CruiseWithVehicle(_enemies[i].ped.LastVehicle, 60.0f, DrivingStyle.AvoidTrafficExtremely);
123+
tasks.Close();
124+
_enemies[i].ped.Task.PerformSequence(tasks);
125+
}
126+
}
127+
}
128+
}
129+
}
130+
131+
private void StartMissions(int kills, int level)
132+
{
133+
_kills = kills;
134+
_level = level;
135+
Notification.Show("Eliminate the ~r~enemies~w~.");
136+
Ped player = Game.Player.Character;
137+
138+
for (int i = 1; i <= Math.Ceiling((decimal)_level / 4); i++)
139+
{
140+
Model vehModel = _vehicleList[_rndGet.Next(0, _vehicleList.Length)];
141+
if (vehModel.Request(1000))
142+
{
143+
Vector3 pedSpawnPoint;
144+
if (i == 1)
145+
{
146+
Vector3 playerpos = player.Position;
147+
148+
Vector3 v = new Vector3
149+
{
150+
X = (float)(_rndGet.NextDouble() - 0.5),
151+
Y = (float)(_rndGet.NextDouble() - 0.5),
152+
Z = 0.0f
153+
};
154+
v.Normalize();
155+
playerpos += v * 500.0f;
156+
157+
pedSpawnPoint = World.GetNextPositionOnStreet(playerpos, true);
158+
}
159+
else
160+
{
161+
Vector3 playerpos = _hostVehicle.Position;
162+
163+
Vector3 v = new Vector3
164+
{
165+
X = (float)(_rndGet.NextDouble() - 0.5),
166+
Y = (float)(_rndGet.NextDouble() - 0.5),
167+
Z = 0.0f
168+
};
169+
v.Normalize();
170+
playerpos += v * 200.0f;
171+
172+
pedSpawnPoint = World.GetNextPositionOnStreet(playerpos, true);
173+
}
174+
Vehicle tmpVeh = World.CreateVehicle(vehModel, pedSpawnPoint);
175+
tmpVeh.PlaceOnGround();
176+
tmpVeh.IsPersistent = true;
177+
if (i == 1)
178+
_hostVehicle = tmpVeh;
179+
180+
int maxPasseng;
181+
182+
if (i == Math.Ceiling((decimal)_level / 4))
183+
{
184+
maxPasseng = _level % 4;
185+
if (maxPasseng == 0)
186+
maxPasseng = 4;
187+
}
188+
else
189+
maxPasseng = 4;
190+
191+
for (int d = 0; d < maxPasseng; d++)
192+
{
193+
Ped tmpPed = World.CreateRandomPed(pedSpawnPoint);
194+
var gunid = _level > _weaponList.Length ? _weaponList[_rndGet.Next(0, _weaponList.Length)] : _weaponList[_rndGet.Next(0, _level)];
195+
tmpPed.Weapons.Give(gunid, 999, true, true);
196+
if (d == 0)
197+
{
198+
tmpPed.SetIntoVehicle(tmpVeh, VehicleSeat.Driver);
199+
if (i == 1)
200+
tmpPed.Task.CruiseWithVehicle(tmpPed.CurrentVehicle, 15.0f, DrivingStyle.AvoidTrafficExtremely);
201+
else
202+
Function.Call(Hash.TASK_VEHICLE_FOLLOW, tmpPed.Handle, tmpVeh, _hostVehicle, 15.0f, (int)DrivingStyle.AvoidTrafficExtremely);
203+
}
204+
else
205+
tmpPed.SetIntoVehicle(tmpVeh, VehicleSeat.Any);
206+
207+
tmpPed.IsPersistent = true;
208+
tmpPed.RelationshipGroup = _enemyGroup;
209+
tmpPed.IsEnemy = true;
210+
tmpPed.CanSwitchWeapons = true;
211+
212+
Blip tmpBlip = tmpPed.AddBlip();
213+
tmpBlip.Color = BlipColor.Red;
214+
215+
_enemies.Add(new Enemy(tmpPed, tmpBlip));
216+
}
217+
_enemyVehicles.Add(tmpVeh);
218+
}
219+
else
220+
Notification.Show("Error loading vehicle.");
221+
}
222+
}
223+
224+
private void Start(CustomEventReceivedArgs obj)
225+
{
226+
API.QueueAction(() =>
227+
{
228+
StartMissions((int)obj.Args[0], (int)obj.Args[1]);
229+
});
230+
}
231+
232+
private void StopMissions()
233+
{
234+
foreach (var item in _enemies)
235+
{
236+
item.ped.MarkAsNoLongerNeeded();
237+
item.blip.Delete();
238+
}
239+
foreach (var item in _enemyVehicles)
240+
item.MarkAsNoLongerNeeded();
241+
_enemies.Clear();
242+
_enemyVehicles.Clear();
243+
}
244+
245+
private void Stop(CustomEventReceivedArgs obj)
246+
{
247+
API.QueueAction(() =>
248+
{
249+
StopMissions();
250+
});
251+
}
252+
}
253+
254+
public class Enemy
255+
{
256+
public Ped ped;
257+
public Blip blip;
258+
public bool spooked;
259+
public bool fighting;
260+
261+
public Enemy(Ped ped, Blip blip)
262+
{
263+
this.ped = ped;
264+
this.blip = blip;
265+
spooked = false;
266+
fighting = false;
267+
}
268+
}
269+
}
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.GangWars.Client</OutDir>
6+
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
7+
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\RageCoop.Resources.GangWars.Shared\RageCoop.Resources.GangWars.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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using RageCoop.Core.Scripting;
2+
3+
namespace RageCoop.Resources.GangWars
4+
{
5+
public static class Events
6+
{
7+
public static int Start = CustomEvents.Hash("RageCoop.Resources.GangWars.Start");
8+
public static int Stop = CustomEvents.Hash("RageCoop.Resources.GangWars.Stop");
9+
public static int MissionAccomplished = CustomEvents.Hash("RageCoop.Resources.GangWars.MissionAccomplished");
10+
}
11+
}
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("{3ADD4C21-2DC7-4DE9-B79F-26C7CD94D52E}") = "RageCoop.Resources.GangWars", "RageCoop.Resources.GangWars\RageCoop.Resources.GangWars.csproj", "{94EAF721-8316-4910-A9B1-31FEC907D5B7}"
7+
EndProject
8+
Project("{3ADD4C21-2DC7-4DE9-B79F-26C7CD94D52E}") = "RageCoop.Resources.GangWars.Client", "RageCoop.Resources.GangWars.Client\RageCoop.Resources.GangWars.Client.csproj", "{80616669-889A-40BC-9714-FEFC6CAFD530}"
9+
EndProject
10+
Project("{3ADD4C21-2DC7-4DE9-B79F-26C7CD94D52E}") = "RageCoop.Resources.GangWars.Shared", "RageCoop.Resources.GangWars.Shared\RageCoop.Resources.GangWars.Shared.csproj", "{9948A239-F882-46E5-A4F2-7EFEF64E231B}"
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+
{94EAF721-8316-4910-A9B1-31FEC907D5B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{94EAF721-8316-4910-A9B1-31FEC907D5B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{94EAF721-8316-4910-A9B1-31FEC907D5B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
21+
{94EAF721-8316-4910-A9B1-31FEC907D5B7}.Release|Any CPU.Build.0 = Release|Any CPU
22+
{80616669-889A-40BC-9714-FEFC6CAFD530}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23+
{80616669-889A-40BC-9714-FEFC6CAFD530}.Debug|Any CPU.Build.0 = Debug|Any CPU
24+
{80616669-889A-40BC-9714-FEFC6CAFD530}.Release|Any CPU.ActiveCfg = Release|Any CPU
25+
{80616669-889A-40BC-9714-FEFC6CAFD530}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{9948A239-F882-46E5-A4F2-7EFEF64E231B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{9948A239-F882-46E5-A4F2-7EFEF64E231B}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{9948A239-F882-46E5-A4F2-7EFEF64E231B}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{9948A239-F882-46E5-A4F2-7EFEF64E231B}.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 = {A872276B-8F43-4E3D-9850-C6EE644A4755}
36+
EndGlobalSection
37+
EndGlobal

0 commit comments

Comments
 (0)