Advertisement
noentiendero

Gang War: gangs vs. cops [dinamic]

Nov 15th, 2015
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.27 KB | None | 0 0
  1. /* GTA V Gang War Mod
  2. * GANG ALLIANCE vs COPS+ARMY
  3. * MODIFIED BY ENFORCERZHUKOV
  4. * This script will spawn peds from gangs (ballas, vagos, families & lost)
  5. * on team B (player's team) and soldiers, cops & NOOSE specops units
  6. * on team A (enemy team). Both teams will fight each other, but team A
  7. * will respect cops & army from the game, so native spawned cops & soldiers
  8. * won't fight with the cops&soldiers spawned by this script.
  9. *
  10. * ORIGINAL CREDITS:
  11. *
  12. * After the play defines during the gametime two spawnpoints,
  13. * there will be spawnd a limited crowd of peds for each team.
  14. * Peds will goto the enemy spawnpoint and atack peds from the enemy team
  15. * The player is in Team B
  16. *
  17. * Use this Mod for getting introdused into scripting mods for GTA V :)
  18. *
  19. * Version 0.2
  20. *
  21. * (C)Tobias Rosini
  22. */
  23. using GTA;
  24. using GTA.Native;
  25. using GTA.Math;
  26.  
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Windows.Forms;
  30.  
  31.  
  32.  
  33. public class GangWar : Script
  34. {
  35. //RelationshipGroup Indizies
  36. int relgrpA = 0;
  37. int relgrpB = 0;
  38.  
  39. //Frequenzy divisor counter
  40. int TickCnt = 0;
  41.  
  42. //Lists for keeping references to our Peds
  43. List<Ped> managedPedsTeamA = new List<Ped>();
  44. List<Ped> managedPedsTeamB = new List<Ped>();
  45.  
  46. //List for noticing wich Ped has to be deleted
  47. List<Ped> LöschIndizies = new List<Ped>();
  48.  
  49. //Points
  50. int PointsTeamA = 0;
  51. int PointsTeamB = 0;
  52.  
  53. public GangWar()
  54. {
  55. //Events from Game
  56. Tick += OnTick;
  57. KeyDown += OnKeyDown;
  58. KeyUp += OnKeyUp;
  59.  
  60. Interval = 10;
  61.  
  62. //Defining Relationships
  63. //originales
  64. //relgrpA = World.AddRelationshipGroup("A");
  65. //relgrpB = World.AddRelationshipGroup("B");
  66.  
  67. relgrpA = World.AddRelationshipGroup("A");
  68. relgrpB = World.AddRelationshipGroup("B");
  69. relgrpA = World.AddRelationshipGroup("cop");
  70. relgrpA = World.AddRelationshipGroup("army");
  71.  
  72. //who hates and like who
  73. //originales
  74. //World.SetRelationshipBetweenGroups(Relationship.Hate, relgrpA, relgrpB);
  75. //World.SetRelationshipBetweenGroups(Relationship.Respect, relgrpA, relgrpA);
  76. //World.SetRelationshipBetweenGroups(Relationship.Respect, relgrpB, relgrpB);
  77. World.SetRelationshipBetweenGroups(Relationship.Hate, relgrpA, relgrpB);
  78. World.SetRelationshipBetweenGroups(Relationship.Respect, relgrpA, relgrpA);
  79. World.SetRelationshipBetweenGroups(Relationship.Respect, relgrpB, relgrpB);
  80.  
  81. //Put Player in Team B
  82. Game.Player.Character.RelationshipGroup = relgrpB;
  83. //managedPedsTeamA.Add(Game.Player.Character);
  84. }
  85.  
  86. //Happens every 10 ms
  87. void OnTick(object sender, EventArgs e)
  88. {
  89. //I build here a Frequenzy divisor for things that do not have to happen so often
  90. int TickDivisor = 50;
  91. TickCnt++;
  92. if (TickCnt > TickDivisor)
  93. {
  94. TickCnt = 0;
  95. DividedTick(sender, e);//Happens every 500 ms
  96. }
  97.  
  98. //HUD
  99. UIText txtA = new UIText(
  100. PointsTeamA.ToString(),
  101. new System.Drawing.Point(0, 0),
  102. 1,
  103. System.Drawing.Color.Red);
  104. txtA.Draw();
  105.  
  106. UIText txtB = new UIText(
  107. PointsTeamB.ToString(),
  108. new System.Drawing.Point(100, 0),
  109. 1,
  110. System.Drawing.Color.Yellow);
  111. txtB.Draw();
  112. }
  113.  
  114. //Happens every 500 ms
  115. void DividedTick(object sender, EventArgs e)
  116. {
  117. CheckPeds(managedPedsTeamA);
  118. CheckPeds(managedPedsTeamB);
  119.  
  120. int livingA = 0;
  121. int livingB = 0;
  122.  
  123. foreach (Ped ped in managedPedsTeamA)
  124. if (ped.IsAlive)
  125. livingA++;
  126.  
  127. foreach (Ped ped in managedPedsTeamB)
  128. if (ped.IsAlive)
  129. livingB++;
  130.  
  131. if ((livingB + livingB) < 25)
  132. {
  133. if (livingA > livingB)
  134. CreateNewPed("B");
  135. else
  136. CreateNewPed("A");
  137. }
  138. CleanUpDeath();
  139. }
  140.  
  141. string GetManagedPedInfo(string team)
  142. {
  143. int dead = 0;
  144. int idle = 0;
  145. int walking = 0;
  146. List<Ped>l = null;
  147.  
  148. if (team == "A")
  149. l = managedPedsTeamA;
  150.  
  151. if (team == "B")
  152. l = managedPedsTeamB;
  153.  
  154. if (l != null)
  155. {
  156. foreach (Ped ped in l)
  157. {
  158. if (ped.IsDead)
  159. dead++;
  160.  
  161. if (ped.IsWalking)
  162. walking++;
  163.  
  164. if (ped.IsIdle)
  165. idle++;
  166. }
  167. }
  168.  
  169. return "Team" + team + ": " + managedPedsTeamA.Count + " | dead: " + dead.ToString() + " | idle: " + idle.ToString() + " | walking: " + walking.ToString();
  170. }
  171.  
  172. void CleanUpDeath()
  173. {
  174. while (LöschIndizies.Count > 5)
  175. {
  176. int killIndex = -1;
  177. //Durchsuche Liste A
  178. for (int i = 0; i < managedPedsTeamA.Count;i++)
  179. {
  180. if (LöschIndizies[0].Handle == managedPedsTeamA[i].Handle)
  181. {
  182. killIndex = i;
  183. }
  184. }
  185. if (killIndex != -1)
  186. {
  187. managedPedsTeamA[killIndex].Delete();
  188. managedPedsTeamA.RemoveAt(killIndex);
  189. }
  190. else
  191. {
  192. //Durchsuche Liste B
  193. for (int i = 0; i < managedPedsTeamB.Count; i++)
  194. {
  195. if (LöschIndizies[0].Handle == managedPedsTeamB[i].Handle)
  196. {
  197. killIndex = i;
  198. }
  199. }
  200. if (killIndex != -1)
  201. {
  202. managedPedsTeamB[killIndex].Delete();
  203. managedPedsTeamB.RemoveAt(killIndex);
  204. }
  205. }
  206.  
  207. //Entfernen aus Löschliste
  208. if (killIndex != -1)
  209. LöschIndizies.RemoveAt(0);
  210. }
  211.  
  212. /*
  213. //FiFo PedsToDelete Buffer
  214. while (LöschIndizies.Count > 5)
  215. {
  216. if (targetList.Count > 0)
  217. {
  218. if (LöschIndizies.Remove(targetList[0]))
  219. {
  220. //UI.Notify("delete from L-List");
  221. targetList[0].Delete();
  222. targetList.RemoveAt(0);
  223. }
  224. }
  225. }
  226. */
  227. }
  228.  
  229. void CheckPeds(List<Ped> targetList)
  230. {
  231. Ped player = Game.Player.Character;
  232.  
  233. foreach (Ped ped in targetList)
  234. {/*
  235. bool isNear = false;
  236. if (World.GetDistance(player.Position, ped.Position) < 100f)
  237. {
  238. isNear = true;
  239. //UI.Notify("nearly " + ped.Handle.ToString());
  240. }
  241.  
  242. //Cleaning Up far away Peds
  243. if (!isNear)
  244. {
  245. LöschIndizies.Add(ped);
  246. }*/
  247. //else
  248. {
  249. //setting Up Tasks: Every one who idle goto the enemy spawnpoint
  250. if (ped.IsIdle)
  251. {
  252. if (targetList == managedPedsTeamA)
  253. ped.Task.GoTo(spawnLocB);
  254. if(targetList == managedPedsTeamB)
  255. ped.Task.GoTo(spawnLocA);
  256. }
  257. }
  258.  
  259. //Cleaning Up death Peds
  260. if (ped.IsDead) // Puts death ped onto the delete-list
  261. {
  262. Ped killer = ped.GetKiller() as Ped;
  263.  
  264. if (killer != null)
  265. {
  266. if (!LöschIndizies.Contains(ped))
  267. {
  268. if (IsPedInTeam(killer, managedPedsTeamA))
  269. {
  270. PointsTeamA++;
  271. }
  272.  
  273. if (IsPedInTeam(killer, managedPedsTeamB))
  274. {
  275. PointsTeamB++;
  276. }
  277.  
  278. if(killer.Equals(player))
  279. PointsTeamB++;
  280.  
  281. LöschIndizies.Add(ped);
  282. //UI.Notify(killer.Handle.ToString() + " kills " + ped.Handle.ToString());
  283. }
  284. }
  285. }
  286. }
  287.  
  288.  
  289. /*
  290. //Delete noted Peds
  291. foreach (Ped lped in LöschIndizies)
  292. {
  293. targetList.Remove(lped);
  294. //UI.Notify("Remove " + lped.Handle.ToString());
  295. lped.Delete();
  296. }
  297. */
  298. //UI.Notify(PointsTeamA.ToString() + " : " + PointsTeamB.ToString());
  299.  
  300. }
  301.  
  302. /// <summary>
  303. /// Results true if the ped is in the List
  304. /// </summary>
  305. /// <param name="ped">The ped to check</param>
  306. /// <param name="TeamList">The List with all the Teammeber</param>
  307. /// <returns></returns>
  308. bool IsPedInTeam(Ped ped, List<Ped> TeamList)
  309. {
  310. foreach(Ped teammember in TeamList)
  311. {
  312. if (ped.Handle == teammember.Handle)
  313. return true;
  314. }
  315. return false;
  316. }
  317.  
  318. //Use this for cathing the KeyDown Event
  319. void OnKeyDown(object sender, KeyEventArgs e)
  320. {
  321. }
  322.  
  323. GTA.Math.Vector3 spawnLocA = new GTA.Math.Vector3(0, 0, 0);
  324. GTA.Math.Vector3 spawnLocB = new GTA.Math.Vector3(0, 0, 0);
  325.  
  326. //for securing that a spawnpoint has defined before each team creates its Peds
  327. bool IsSpawnLocADefined = false;
  328. bool IsSpawnLocBDefined = false;
  329.  
  330. /// <summary>
  331. /// Creates a new Ped
  332. /// </summary>
  333. /// <param name="team">Team A or B</param>
  334. void CreateNewPed(string team)
  335. {
  336. //If there are both Spawnpoints defined
  337. if (IsSpawnLocADefined && IsSpawnLocBDefined)
  338. {
  339. //depending on team we build a small list of models for a random selection
  340. List<string> model_names = new List<string>();
  341. if (team == "A")
  342. {
  343. //Tip: Google one of the strings for find lists of Modelnames
  344. //TEAM A = COPS
  345. model_names.Add("s_m_m_security_01");
  346. model_names.Add("s_m_y_blackops_01");
  347. model_names.Add("s_m_y_marine_01");
  348. model_names.Add("s_m_y_swat_01");
  349. model_names.Add("s_f_y_ranger_01");
  350. model_names.Add("s_f_y_sheriff_01");
  351. model_names.Add("s_m_y_cop_01");
  352. model_names.Add("s_f_y_cop_01");
  353. }
  354. if (team == "B")
  355. {
  356. //TEAM B = GANG
  357. model_names.Add("g_f_y_ballas_01");
  358. model_names.Add("g_m_y_ballaeast_01");
  359. model_names.Add("g_m_y_ballaorig_01");
  360. model_names.Add("g_m_y_ballasout_01");
  361. model_names.Add("g_f_y_vagos_01");
  362. model_names.Add("g_f_y_lost_01");
  363. model_names.Add("g_f_y_families_01");
  364. model_names.Add("g_m_y_famca_01");
  365. model_names.Add("g_m_y_famdnf_01");
  366. }
  367.  
  368. //for random selection
  369. Random r = new Random();
  370.  
  371. //This will become the new created ped
  372. Ped ped = null;
  373.  
  374. //Yes.. the following code is uggly (to much copy paste for team A & B, nicer would be to isolated this in a new method)
  375. //if there are excepitons in the follwing lines check the spelling of your modelnames
  376. if (team == "A")
  377. {
  378. ped = GTA.World.CreatePed(model_names[r.Next(0, model_names.Count)], spawnLocA);
  379.  
  380. //Relationship&weapon TEAM A
  381. if (ped != null)
  382. {
  383. managedPedsTeamA.Add(ped);
  384. ped.RelationshipGroup = relgrpA;
  385. ped.Weapons.Give(GTA.Native.WeaponHash.CarbineRifle, 1, true, true);
  386. }
  387. }
  388.  
  389. if (team == "B")
  390. {
  391. ped = GTA.World.CreatePed(model_names[r.Next(0, model_names.Count)], spawnLocB);
  392.  
  393. //Relationship&weapon TEAM B
  394. if (ped != null)
  395. {
  396. managedPedsTeamB.Add(ped);
  397. ped.RelationshipGroup = relgrpB;
  398. ped.Weapons.Give(GTA.Native.WeaponHash.AssaultRifle, 1, true, true);
  399. }
  400. }
  401.  
  402. //There should be no tasks but...
  403. ped.Task.ClearAllImmediately();
  404.  
  405. //ped.Task.FightAgainst(Game.Player.Character);
  406.  
  407.  
  408. //Weapon (native)
  409. //ped.Weapons.Give(GTA.Native.WeaponHash.CarbineRifle, 1, true, true);
  410.  
  411. //blip on the GTA map
  412. Blip blip = ped.AddBlip();
  413. if (blip != null)
  414. {
  415. if (team == "A")
  416. blip.Color = BlipColor.Red;
  417.  
  418. if(team == "B")
  419. blip.Color = BlipColor.Yellow;
  420. blip.Scale = 0.5f;
  421. }
  422.  
  423. //Output for debugging
  424. //UI.Notify(ped.Handle.ToString() + " spawned for team " + team );
  425. }
  426. else
  427. //If there are not both Spawnpoints defined
  428. UI.Notify("Press H = TeamA or J = Team B to define the teams spawnlocation at your actual position");
  429. }
  430.  
  431. //Use this for cathing the KeyUp Event
  432. void OnKeyUp(object sender, KeyEventArgs e)
  433. {
  434. //Set SpawnPos for Team A
  435. if (e.KeyCode == Keys.H)
  436. {
  437. //A Reference to the Player
  438. Ped player = Game.Player.Character;
  439.  
  440. //Use this for one meter in front of the player
  441. //spawnLoc = player.Position + (player.ForwardVector * 1);
  442.  
  443. //Define the playerpos as the spawnpos for the team
  444. spawnLocA = player.Position;
  445.  
  446. //notice that location is defined
  447. IsSpawnLocADefined = true;
  448.  
  449. //A Blip for the spawn pos
  450. Blip blip = World.CreateBlip(spawnLocA, 1.5f);
  451. blip.Color = BlipColor.Red;
  452. blip.Scale = 5f;
  453. UI.Notify("Point A is ready");
  454. }
  455.  
  456. //Set SpawnPos for Team B
  457. if (e.KeyCode == Keys.J)
  458. {
  459. //for code comments see a few lines up
  460. Ped player = Game.Player.Character;
  461. spawnLocB = player.Position;
  462.  
  463. IsSpawnLocBDefined = true;
  464.  
  465. Blip blip = World.CreateBlip(spawnLocB, 1.5f);
  466. blip.Color = BlipColor.Yellow;
  467. blip.Scale = 5f;
  468.  
  469. //feedback
  470. UI.Notify("Point B is ready");
  471. }
  472. }
  473. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement