Advertisement
noentiendero

Gang War: gangs vs. cops [dinamic]

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