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