djhonga2001

Gang Wars: ballas vs. families, knife only

Aug 11th, 2015
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* GTA V Gang War Mod (BALLAS VS. FAMILIES, KNIFE ONLY)
  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. }
  241.  
  242. }
  243.  
  244. /// <summary>
  245. /// Results true if the ped is in the List
  246. /// </summary>
  247. /// <param name="ped">The ped to check</param>
  248. /// <param name="TeamList">The List with all the Teammeber</param>
  249. /// <returns></returns>
  250. bool IsPedInTeam(Ped ped, List<Ped> TeamList)
  251. {
  252. foreach(Ped teammember in TeamList)
  253. {
  254. if (ped.Handle == teammember.Handle)
  255. return true;
  256. }
  257. return false;
  258. }
  259.  
  260. //Use this for cathing the KeyDown Event
  261. void OnKeyDown(object sender, KeyEventArgs e)
  262. {
  263. }
  264.  
  265. GTA.Math.Vector3 spawnLocA = new GTA.Math.Vector3(0, 0, 0);
  266. GTA.Math.Vector3 spawnLocB = new GTA.Math.Vector3(0, 0, 0);
  267.  
  268. //for securing that a spawnpoint has defined before each team creates its Peds
  269. bool IsSpawnLocADefined = false;
  270. bool IsSpawnLocBDefined = false;
  271.  
  272. /// <summary>
  273. /// Creates a new Ped
  274. /// </summary>
  275. /// <param name="team">Team A or B</param>
  276. void CreateNewPed(string team)
  277. {
  278. //If there are both Spawnpoints defined
  279. if (IsSpawnLocADefined && IsSpawnLocBDefined)
  280. {
  281. //depending on team we build a small list of models for a random selection
  282. List<string> model_names = new List<string>();
  283. if (team == "A")
  284. {
  285. //Tip: Google one of the strings for find lists of Modelnames
  286. model_names.Add("g_f_y_ballas_01");
  287. model_names.Add("g_m_y_ballaeast_01");
  288. model_names.Add("g_m_y_ballaorig_01");
  289. model_names.Add("g_m_y_ballasout_01");
  290. }
  291. if (team == "B")
  292. {
  293. model_names.Add("g_f_y_families_01");
  294. model_names.Add("g_m_y_famca_01");
  295. model_names.Add("g_m_y_famdnf_01");
  296. model_names.Add("g_m_y_famfor_01");
  297. }
  298.  
  299. //for random selection
  300. Random r = new Random();
  301.  
  302. //This will become the new created ped
  303. Ped ped = null;
  304.  
  305. //Yes.. the following code is uggly (to much copy paste for team A & B, nicer would be to isolated this in a new method)
  306. //if there are excepitons in the follwing lines check the spelling of your modelnames
  307. if (team == "A")
  308. {
  309. ped = GTA.World.CreatePed(model_names[r.Next(0, model_names.Count)], spawnLocA);
  310.  
  311. //Relationship
  312. if (ped != null)
  313. {
  314. managedPedsTeamA.Add(ped);
  315. ped.RelationshipGroup = relgrpA;
  316. }
  317. }
  318.  
  319. if (team == "B")
  320. {
  321. ped = GTA.World.CreatePed(model_names[r.Next(0, model_names.Count)], spawnLocB);
  322.  
  323. //Relationship
  324. if (ped != null)
  325. {
  326. managedPedsTeamB.Add(ped);
  327. ped.RelationshipGroup = relgrpB;
  328. }
  329. }
  330.  
  331. //There should be no tasks but...
  332. ped.Task.ClearAllImmediately();
  333.  
  334. //ped.Task.FightAgainst(Game.Player.Character);
  335.  
  336. //Setting Up Health and Ammo
  337. ped.Health = 50;
  338. ped.Armor = 50;
  339.  
  340. //Weapon
  341. ped.Weapons.Give(GTA.Native.WeaponHash.Knife, 1, true, true);
  342.  
  343. //blip on the GTA map
  344. Blip blip = ped.AddBlip();
  345. if (blip != null)
  346. {
  347. if (team == "A")
  348. blip.Color = BlipColor.Yellow;
  349.  
  350. if(team == "B")
  351. blip.Color = BlipColor.Green;
  352. blip.Scale = 0.5f;
  353. }
  354.  
  355. //Output for debugging
  356. //UI.Notify(ped.Handle.ToString() + " spawned for team " + team );
  357. }
  358. else
  359. //If there are not both Spawnpoints defined
  360. UI.Notify("Press H = TeamA or J = Team B to define the teams spawnlocation at your actual position");
  361. }
  362.  
  363. //Use this for cathing the KeyUp Event
  364. void OnKeyUp(object sender, KeyEventArgs e)
  365. {
  366. //Set SpawnPos for Team A
  367. if (e.KeyCode == Keys.H)
  368. {
  369. //A Reference to the Player
  370. Ped player = Game.Player.Character;
  371.  
  372. //Use this for one meter in front of the player
  373. //spawnLoc = player.Position + (player.ForwardVector * 1);
  374.  
  375. //Define the playerpos as the spawnpos for the team
  376. spawnLocA = player.Position;
  377.  
  378. //notice that location is defined
  379. IsSpawnLocADefined = true;
  380.  
  381. //A Blip for the spawn pos
  382. Blip blip = World.CreateBlip(spawnLocA, 1.5f);
  383. blip.Color = BlipColor.Red;
  384. blip.Scale = 5f;
  385. UI.Notify("Point A is ready");
  386. }
  387.  
  388. //Set SpawnPos for Team B
  389. if (e.KeyCode == Keys.J)
  390. {
  391. //for code comments see a few lines up
  392. Ped player = Game.Player.Character;
  393. spawnLocB = player.Position;
  394.  
  395. IsSpawnLocBDefined = true;
  396.  
  397. Blip blip = World.CreateBlip(spawnLocB, 1.5f);
  398. blip.Color = BlipColor.Yellow;
  399. blip.Scale = 5f;
  400.  
  401. //feedback
  402. UI.Notify("Point B is ready");
  403. }
  404. }
  405. }
Add Comment
Please, Sign In to add comment