|
| 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 | +} |
0 commit comments