Advertisement
noentiendero

Gang Wars: cops vs gangs

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