Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. Red Dead Redemption 2

      1. PC
      2. Gameplay
      3. Missions
      4. Help & Support
    2. Red Dead Online

      1. Gameplay
      2. Find Lobbies & Outlaws
      3. Help & Support
      4. Frontier Pursuits
    1. Crews & Posses

      1. Recruitment
    2. Events

    1. GTA Online

      1. Diamond Casino & Resort
      2. DLC
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Grand Theft Auto Series

    3. GTA 6

    4. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    5. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA IV Mods
    6. GTA Chinatown Wars

    7. GTA Vice City Stories

    8. GTA Liberty City Stories

    9. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA SA Mods
    10. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA VC Mods
    11. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA III Mods
    12. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    13. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    3. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. News

    2. Forum Support

    3. Site Suggestions

Sign in to follow this  
Noox

I need help putting 3 NPCs into a vehicle

Recommended Posts

Jitnaught

I need more help (sorry but I'm a newbie :( )

I made this

 

 

namespace ClassLibrary2{    public class AIBehaviour : Script    {        Group enGroup;        public void escape()        {            Random pol = new Random();            int x = pol.Next(0, 3);            Game.DisplayText(Convert.ToString(x));            switch(x)            {                case 0:                    Player.WantedLevel = 2;                    policeEscape();                    Game.DisplayText("Cops!");                    break;                case 1:                    Game.DisplayText("Criminal");                    enemySpawn();                    break;                case 2:                    Game.DisplayText("Nothing");                    Player.Money += 2000;                    break;            }        }        public void policeEscape()        {            while(Player.WantedLevel > 0)            {            }            War.canRequest = false;            War.inMission = false;            Player.Money += 3000;        }        public void enemySpawn()        {            string[] modelArray = { "F_M_BUSINESS_02", "F_M_BUSINESS_01", "F_M_PEASTEURO_01", "F_M_RUNNER" };            Ped[] pedList = new Ped[4];            for(int i = 0; i < 4; i++)            {                Vector3 playerPos = World.GetNextPositionOnStreet(Player.Character.Position.Around(20.0F));                pedList[i] = World.CreatePed(modelArray[i], playerPos, RelationshipGroup.Criminal);                criminalProp(pedList[i]);                enGroup.AddMember(pedList[0]);            }            while(enGroup.MemberCount > 0)            {            }            War.inMission = false;            War.canRequest = false;            Player.Money += 5000;        }        public void criminalProp(Ped ped)        {            ped.WillDoDrivebys = true;            ped.Armor = 0;            ped.PriorityTargetForEnemies = true;            ped.AlwaysDiesOnLowHealth = true;            ped.SetPathfinding(true, true, true);            Weapon weapon = Weapon.SMG_Uzi;            ped.Weapons.FromType(weapon).Ammo = 250;            ped.Weapons.Select(weapon);            ped.RelationshipGroup = RelationshipGroup.Criminal;            ped.ChangeRelationship(RelationshipGroup.Criminal, Relationship.Hate);            ped.AttachBlip();        }    }}

 

 

 

Which, to make things random all it does is either make the player wanted by cops, by a criminal group or nothing.

The problem is that when the criminal group spawns everything is fine but sometimes it freezes, I made many tests and it never froze when the criminals spawned.

Also, they don't shoot me but they shoot each other and enGroup = pedList[0].Group; doesn't work.

Thanks again for the help.

 

EDIT: I know all the whiles with nothing inside are bad and they are performance eaters but it's temporary.

 

This

while(enGroup.MemberCount > 0)            {            }

should be more like this

while(enGroup.MemberCount < 0){   }

(I changed the greater than to a less than sign. If you add a ped to the group, the member count will be above 0, so you would be in the while loop forever.

Share this post


Link to post
Share on other sites
Noox

 

I need more help (sorry but I'm a newbie :( )

I made this

 

 

namespace ClassLibrary2{    public class AIBehaviour : Script    {        Group enGroup;        public void escape()        {            Random pol = new Random();            int x = pol.Next(0, 3);            Game.DisplayText(Convert.ToString(x));            switch(x)            {                case 0:                    Player.WantedLevel = 2;                    policeEscape();                    Game.DisplayText("Cops!");                    break;                case 1:                    Game.DisplayText("Criminal");                    enemySpawn();                    break;                case 2:                    Game.DisplayText("Nothing");                    Player.Money += 2000;                    break;            }        }        public void policeEscape()        {            while(Player.WantedLevel > 0)            {            }            War.canRequest = false;            War.inMission = false;            Player.Money += 3000;        }        public void enemySpawn()        {            string[] modelArray = { "F_M_BUSINESS_02", "F_M_BUSINESS_01", "F_M_PEASTEURO_01", "F_M_RUNNER" };            Ped[] pedList = new Ped[4];            for(int i = 0; i < 4; i++)            {                Vector3 playerPos = World.GetNextPositionOnStreet(Player.Character.Position.Around(20.0F));                pedList[i] = World.CreatePed(modelArray[i], playerPos, RelationshipGroup.Criminal);                criminalProp(pedList[i]);                enGroup.AddMember(pedList[0]);            }            while(enGroup.MemberCount > 0)            {            }            War.inMission = false;            War.canRequest = false;            Player.Money += 5000;        }        public void criminalProp(Ped ped)        {            ped.WillDoDrivebys = true;            ped.Armor = 0;            ped.PriorityTargetForEnemies = true;            ped.AlwaysDiesOnLowHealth = true;            ped.SetPathfinding(true, true, true);            Weapon weapon = Weapon.SMG_Uzi;            ped.Weapons.FromType(weapon).Ammo = 250;            ped.Weapons.Select(weapon);            ped.RelationshipGroup = RelationshipGroup.Criminal;            ped.ChangeRelationship(RelationshipGroup.Criminal, Relationship.Hate);            ped.AttachBlip();        }    }}

 

 

 

Which, to make things random all it does is either make the player wanted by cops, by a criminal group or nothing.

The problem is that when the criminal group spawns everything is fine but sometimes it freezes, I made many tests and it never froze when the criminals spawned.

Also, they don't shoot me but they shoot each other and enGroup = pedList[0].Group; doesn't work.

Thanks again for the help.

 

EDIT: I know all the whiles with nothing inside are bad and they are performance eaters but it's temporary.

 

This

while(enGroup.MemberCount > 0)            {            }

should be more like this

while(enGroup.MemberCount < 0){   }

(I changed the greater than to a less than sign. If you add a ped to the group, the member count will be above 0, so you would be in the while loop forever.

 

But I'm supposed to kill that group, wouldn't it be the same thing?

Share this post


Link to post
Share on other sites
Jitnaught

 

 

I need more help (sorry but I'm a newbie :( )

I made this

 

 

namespace ClassLibrary2{    public class AIBehaviour : Script    {        Group enGroup;        public void escape()        {            Random pol = new Random();            int x = pol.Next(0, 3);            Game.DisplayText(Convert.ToString(x));            switch(x)            {                case 0:                    Player.WantedLevel = 2;                    policeEscape();                    Game.DisplayText("Cops!");                    break;                case 1:                    Game.DisplayText("Criminal");                    enemySpawn();                    break;                case 2:                    Game.DisplayText("Nothing");                    Player.Money += 2000;                    break;            }        }        public void policeEscape()        {            while(Player.WantedLevel > 0)            {            }            War.canRequest = false;            War.inMission = false;            Player.Money += 3000;        }        public void enemySpawn()        {            string[] modelArray = { "F_M_BUSINESS_02", "F_M_BUSINESS_01", "F_M_PEASTEURO_01", "F_M_RUNNER" };            Ped[] pedList = new Ped[4];            for(int i = 0; i < 4; i++)            {                Vector3 playerPos = World.GetNextPositionOnStreet(Player.Character.Position.Around(20.0F));                pedList[i] = World.CreatePed(modelArray[i], playerPos, RelationshipGroup.Criminal);                criminalProp(pedList[i]);                enGroup.AddMember(pedList[0]);            }            while(enGroup.MemberCount > 0)            {            }            War.inMission = false;            War.canRequest = false;            Player.Money += 5000;        }        public void criminalProp(Ped ped)        {            ped.WillDoDrivebys = true;            ped.Armor = 0;            ped.PriorityTargetForEnemies = true;            ped.AlwaysDiesOnLowHealth = true;            ped.SetPathfinding(true, true, true);            Weapon weapon = Weapon.SMG_Uzi;            ped.Weapons.FromType(weapon).Ammo = 250;            ped.Weapons.Select(weapon);            ped.RelationshipGroup = RelationshipGroup.Criminal;            ped.ChangeRelationship(RelationshipGroup.Criminal, Relationship.Hate);            ped.AttachBlip();        }    }}

 

 

 

Which, to make things random all it does is either make the player wanted by cops, by a criminal group or nothing.

The problem is that when the criminal group spawns everything is fine but sometimes it freezes, I made many tests and it never froze when the criminals spawned.

Also, they don't shoot me but they shoot each other and enGroup = pedList[0].Group; doesn't work.

Thanks again for the help.

 

EDIT: I know all the whiles with nothing inside are bad and they are performance eaters but it's temporary.

 

This

while(enGroup.MemberCount > 0)            {            }

should be more like this

while(enGroup.MemberCount < 0){   }

(I changed the greater than to a less than sign. If you add a ped to the group, the member count will be above 0, so you would be in the while loop forever.

 

But I'm supposed to kill that group, wouldn't it be the same thing?

 

I'm not sure what you mean, but if you have

while(enGroup.MemberCount > 0)            {            }

it will be an infinite loop (most of the time), which will freeze the script.

Share this post


Link to post
Share on other sites
Noox

 

 

 

I need more help (sorry but I'm a newbie :( )

I made this

 

 

namespace ClassLibrary2{    public class AIBehaviour : Script    {        Group enGroup;        public void escape()        {            Random pol = new Random();            int x = pol.Next(0, 3);            Game.DisplayText(Convert.ToString(x));            switch(x)            {                case 0:                    Player.WantedLevel = 2;                    policeEscape();                    Game.DisplayText("Cops!");                    break;                case 1:                    Game.DisplayText("Criminal");                    enemySpawn();                    break;                case 2:                    Game.DisplayText("Nothing");                    Player.Money += 2000;                    break;            }        }        public void policeEscape()        {            while(Player.WantedLevel > 0)            {            }            War.canRequest = false;            War.inMission = false;            Player.Money += 3000;        }        public void enemySpawn()        {            string[] modelArray = { "F_M_BUSINESS_02", "F_M_BUSINESS_01", "F_M_PEASTEURO_01", "F_M_RUNNER" };            Ped[] pedList = new Ped[4];            for(int i = 0; i < 4; i++)            {                Vector3 playerPos = World.GetNextPositionOnStreet(Player.Character.Position.Around(20.0F));                pedList[i] = World.CreatePed(modelArray[i], playerPos, RelationshipGroup.Criminal);                criminalProp(pedList[i]);                enGroup.AddMember(pedList[0]);            }            while(enGroup.MemberCount > 0)            {            }            War.inMission = false;            War.canRequest = false;            Player.Money += 5000;        }        public void criminalProp(Ped ped)        {            ped.WillDoDrivebys = true;            ped.Armor = 0;            ped.PriorityTargetForEnemies = true;            ped.AlwaysDiesOnLowHealth = true;            ped.SetPathfinding(true, true, true);            Weapon weapon = Weapon.SMG_Uzi;            ped.Weapons.FromType(weapon).Ammo = 250;            ped.Weapons.Select(weapon);            ped.RelationshipGroup = RelationshipGroup.Criminal;            ped.ChangeRelationship(RelationshipGroup.Criminal, Relationship.Hate);            ped.AttachBlip();        }    }}

 

 

 

Which, to make things random all it does is either make the player wanted by cops, by a criminal group or nothing.

The problem is that when the criminal group spawns everything is fine but sometimes it freezes, I made many tests and it never froze when the criminals spawned.

Also, they don't shoot me but they shoot each other and enGroup = pedList[0].Group; doesn't work.

Thanks again for the help.

 

EDIT: I know all the whiles with nothing inside are bad and they are performance eaters but it's temporary.

 

This

while(enGroup.MemberCount > 0)            {            }

should be more like this

while(enGroup.MemberCount < 0){   }

(I changed the greater than to a less than sign. If you add a ped to the group, the member count will be above 0, so you would be in the while loop forever.

 

But I'm supposed to kill that group, wouldn't it be the same thing?

 

I'm not sure what you mean, but if you have

while(enGroup.MemberCount > 0)            {            }

it will be an infinite loop (most of the time), which will freeze the script.

 

To get the mission done the group must be killed, if it's < 0 wouldn''t it be useless? And as I said above when the criminal group is spawned it doesn't freeze.

Share this post


Link to post
Share on other sites
Jitnaught

 

 

 

 

I need more help (sorry but I'm a newbie :( )

I made this

 

 

namespace ClassLibrary2{    public class AIBehaviour : Script    {        Group enGroup;        public void escape()        {            Random pol = new Random();            int x = pol.Next(0, 3);            Game.DisplayText(Convert.ToString(x));            switch(x)            {                case 0:                    Player.WantedLevel = 2;                    policeEscape();                    Game.DisplayText("Cops!");                    break;                case 1:                    Game.DisplayText("Criminal");                    enemySpawn();                    break;                case 2:                    Game.DisplayText("Nothing");                    Player.Money += 2000;                    break;            }        }        public void policeEscape()        {            while(Player.WantedLevel > 0)            {            }            War.canRequest = false;            War.inMission = false;            Player.Money += 3000;        }        public void enemySpawn()        {            string[] modelArray = { "F_M_BUSINESS_02", "F_M_BUSINESS_01", "F_M_PEASTEURO_01", "F_M_RUNNER" };            Ped[] pedList = new Ped[4];            for(int i = 0; i < 4; i++)            {                Vector3 playerPos = World.GetNextPositionOnStreet(Player.Character.Position.Around(20.0F));                pedList[i] = World.CreatePed(modelArray[i], playerPos, RelationshipGroup.Criminal);                criminalProp(pedList[i]);                enGroup.AddMember(pedList[0]);            }            while(enGroup.MemberCount > 0)            {            }            War.inMission = false;            War.canRequest = false;            Player.Money += 5000;        }        public void criminalProp(Ped ped)        {            ped.WillDoDrivebys = true;            ped.Armor = 0;            ped.PriorityTargetForEnemies = true;            ped.AlwaysDiesOnLowHealth = true;            ped.SetPathfinding(true, true, true);            Weapon weapon = Weapon.SMG_Uzi;            ped.Weapons.FromType(weapon).Ammo = 250;            ped.Weapons.Select(weapon);            ped.RelationshipGroup = RelationshipGroup.Criminal;            ped.ChangeRelationship(RelationshipGroup.Criminal, Relationship.Hate);            ped.AttachBlip();        }    }}

 

 

 

Which, to make things random all it does is either make the player wanted by cops, by a criminal group or nothing.

The problem is that when the criminal group spawns everything is fine but sometimes it freezes, I made many tests and it never froze when the criminals spawned.

Also, they don't shoot me but they shoot each other and enGroup = pedList[0].Group; doesn't work.

Thanks again for the help.

 

EDIT: I know all the whiles with nothing inside are bad and they are performance eaters but it's temporary.

 

This

while(enGroup.MemberCount > 0)            {            }

should be more like this

while(enGroup.MemberCount < 0){   }

(I changed the greater than to a less than sign. If you add a ped to the group, the member count will be above 0, so you would be in the while loop forever.

 

But I'm supposed to kill that group, wouldn't it be the same thing?

 

I'm not sure what you mean, but if you have

while(enGroup.MemberCount > 0)            {            }

it will be an infinite loop (most of the time), which will freeze the script.

 

To get the mission done the group must be killed, if it's < 0 wouldn''t it be useless? And as I said above when the criminal group is spawned it doesn't freeze.

 

You said it sometimes freezes...

It would be useless if it was > 0. Let me give you an example.

 

Ok, so you start the game, and the number of peds in the group is 0. You do whatever to spawn whatever, which creates a ped and adds it to the group. Now, if you added the ped to the group, it's going to add 1 to the group. That means that when the code gets to your while statement, the number of peds in the group WILL be above 0, so it will try and do the code in the while loop (which is nothing). This will result in a freeze (which you did in fact say happened sometimes).

 

Now, I'm guessing the reason you put this while statement is because you don't want to do anything before your ped is added to the group. So, if you changed > 0 to < 0, it would check if the ped was added or not, and if not, then do the code in the while loop.

Edited by LetsPlayOrDy

Share this post


Link to post
Share on other sites
Noox

 

 

 

 

 

I need more help (sorry but I'm a newbie :( )

I made this

 

 

namespace ClassLibrary2{    public class AIBehaviour : Script    {        Group enGroup;        public void escape()        {            Random pol = new Random();            int x = pol.Next(0, 3);            Game.DisplayText(Convert.ToString(x));            switch(x)            {                case 0:                    Player.WantedLevel = 2;                    policeEscape();                    Game.DisplayText("Cops!");                    break;                case 1:                    Game.DisplayText("Criminal");                    enemySpawn();                    break;                case 2:                    Game.DisplayText("Nothing");                    Player.Money += 2000;                    break;            }        }        public void policeEscape()        {            while(Player.WantedLevel > 0)            {            }            War.canRequest = false;            War.inMission = false;            Player.Money += 3000;        }        public void enemySpawn()        {            string[] modelArray = { "F_M_BUSINESS_02", "F_M_BUSINESS_01", "F_M_PEASTEURO_01", "F_M_RUNNER" };            Ped[] pedList = new Ped[4];            for(int i = 0; i < 4; i++)            {                Vector3 playerPos = World.GetNextPositionOnStreet(Player.Character.Position.Around(20.0F));                pedList[i] = World.CreatePed(modelArray[i], playerPos, RelationshipGroup.Criminal);                criminalProp(pedList[i]);                enGroup.AddMember(pedList[0]);            }            while(enGroup.MemberCount > 0)            {            }            War.inMission = false;            War.canRequest = false;            Player.Money += 5000;        }        public void criminalProp(Ped ped)        {            ped.WillDoDrivebys = true;            ped.Armor = 0;            ped.PriorityTargetForEnemies = true;            ped.AlwaysDiesOnLowHealth = true;            ped.SetPathfinding(true, true, true);            Weapon weapon = Weapon.SMG_Uzi;            ped.Weapons.FromType(weapon).Ammo = 250;            ped.Weapons.Select(weapon);            ped.RelationshipGroup = RelationshipGroup.Criminal;            ped.ChangeRelationship(RelationshipGroup.Criminal, Relationship.Hate);            ped.AttachBlip();        }    }}

 

 

 

Which, to make things random all it does is either make the player wanted by cops, by a criminal group or nothing.

The problem is that when the criminal group spawns everything is fine but sometimes it freezes, I made many tests and it never froze when the criminals spawned.

Also, they don't shoot me but they shoot each other and enGroup = pedList[0].Group; doesn't work.

Thanks again for the help.

 

EDIT: I know all the whiles with nothing inside are bad and they are performance eaters but it's temporary.

 

This

while(enGroup.MemberCount > 0)            {            }

should be more like this

while(enGroup.MemberCount < 0){   }

(I changed the greater than to a less than sign. If you add a ped to the group, the member count will be above 0, so you would be in the while loop forever.

 

But I'm supposed to kill that group, wouldn't it be the same thing?

 

I'm not sure what you mean, but if you have

while(enGroup.MemberCount > 0)            {            }

it will be an infinite loop (most of the time), which will freeze the script.

 

To get the mission done the group must be killed, if it's < 0 wouldn''t it be useless? And as I said above when the criminal group is spawned it doesn't freeze.

 

You said it sometimes freezes...

It would be useless if it was > 0. Let me give you an example.

 

Ok, so you start the game, and the number of peds in the group is 0. You do whatever to spawn whatever, which creates a ped and adds it to the group. Now, if you added the ped to the group, it's going to add 1 to the group. That means that when the code gets to your while statement, the number of peds in the group WILL be above 0, so it will try and do the code in the while loop (which is nothing). This will result in a freeze (which you did in fact say happened sometimes).

 

Now, I'm guessing the reason you put this while statement is because you don't want to do anything before your ped is added to the group. So, if you changed > 0 to < 0, it would check if the ped was added or not, and if not, then do the code in the while loop.

 

Actually not, this is what I want to do:

A group of 4 is spawned.

To end the "mission" every group member must be dead, so, while the group member count is greater than 0 it has to do nothing, when it is equal than 0 the mission must end.

Also, there is on more problem, as I said in the other post enGroup = pedList[0].Group; is not working.

Share this post


Link to post
Share on other sites
Jitnaught

 

 

 

 

 

 

I need more help (sorry but I'm a newbie :( )

I made this

 

 

namespace ClassLibrary2{    public class AIBehaviour : Script    {        Group enGroup;        public void escape()        {            Random pol = new Random();            int x = pol.Next(0, 3);            Game.DisplayText(Convert.ToString(x));            switch(x)            {                case 0:                    Player.WantedLevel = 2;                    policeEscape();                    Game.DisplayText("Cops!");                    break;                case 1:                    Game.DisplayText("Criminal");                    enemySpawn();                    break;                case 2:                    Game.DisplayText("Nothing");                    Player.Money += 2000;                    break;            }        }        public void policeEscape()        {            while(Player.WantedLevel > 0)            {            }            War.canRequest = false;            War.inMission = false;            Player.Money += 3000;        }        public void enemySpawn()        {            string[] modelArray = { "F_M_BUSINESS_02", "F_M_BUSINESS_01", "F_M_PEASTEURO_01", "F_M_RUNNER" };            Ped[] pedList = new Ped[4];            for(int i = 0; i < 4; i++)            {                Vector3 playerPos = World.GetNextPositionOnStreet(Player.Character.Position.Around(20.0F));                pedList[i] = World.CreatePed(modelArray[i], playerPos, RelationshipGroup.Criminal);                criminalProp(pedList[i]);                enGroup.AddMember(pedList[0]);            }            while(enGroup.MemberCount > 0)            {            }            War.inMission = false;            War.canRequest = false;            Player.Money += 5000;        }        public void criminalProp(Ped ped)        {            ped.WillDoDrivebys = true;            ped.Armor = 0;            ped.PriorityTargetForEnemies = true;            ped.AlwaysDiesOnLowHealth = true;            ped.SetPathfinding(true, true, true);            Weapon weapon = Weapon.SMG_Uzi;            ped.Weapons.FromType(weapon).Ammo = 250;            ped.Weapons.Select(weapon);            ped.RelationshipGroup = RelationshipGroup.Criminal;            ped.ChangeRelationship(RelationshipGroup.Criminal, Relationship.Hate);            ped.AttachBlip();        }    }}

 

 

 

Which, to make things random all it does is either make the player wanted by cops, by a criminal group or nothing.

The problem is that when the criminal group spawns everything is fine but sometimes it freezes, I made many tests and it never froze when the criminals spawned.

Also, they don't shoot me but they shoot each other and enGroup = pedList[0].Group; doesn't work.

Thanks again for the help.

 

EDIT: I know all the whiles with nothing inside are bad and they are performance eaters but it's temporary.

 

This

while(enGroup.MemberCount > 0)            {            }

should be more like this

while(enGroup.MemberCount < 0){   }

(I changed the greater than to a less than sign. If you add a ped to the group, the member count will be above 0, so you would be in the while loop forever.

 

But I'm supposed to kill that group, wouldn't it be the same thing?

 

I'm not sure what you mean, but if you have

while(enGroup.MemberCount > 0)            {            }

it will be an infinite loop (most of the time), which will freeze the script.

 

To get the mission done the group must be killed, if it's < 0 wouldn''t it be useless? And as I said above when the criminal group is spawned it doesn't freeze.

 

You said it sometimes freezes...

It would be useless if it was > 0. Let me give you an example.

 

Ok, so you start the game, and the number of peds in the group is 0. You do whatever to spawn whatever, which creates a ped and adds it to the group. Now, if you added the ped to the group, it's going to add 1 to the group. That means that when the code gets to your while statement, the number of peds in the group WILL be above 0, so it will try and do the code in the while loop (which is nothing). This will result in a freeze (which you did in fact say happened sometimes).

 

Now, I'm guessing the reason you put this while statement is because you don't want to do anything before your ped is added to the group. So, if you changed > 0 to < 0, it would check if the ped was added or not, and if not, then do the code in the while loop.

 

Actually not, this is what I want to do:

A group of 4 is spawned.

To end the "mission" every group member must be dead, so, while the group member count is greater than 0 it has to do nothing, when it is equal than 0 the mission must end.

Also, there is on more problem, as I said in the other post enGroup = pedList[0].Group; is not working.

 

 

Instead of making a while statement, just create the peds and whatever in those functions, then have a tick that checks if the peds are dead yet or not.

 

I don't see enGroup = pedList[0].Group; in your code. Could you direct my attention to where it it?

Edited by LetsPlayOrDy

Share this post


Link to post
Share on other sites
Noox

I forgot to copy it after I changed the script

 

 

namespace ClassLibrary2{    public class AIBehaviour : Script    {        Group enGroup;        public void escape()        {            Random pol = new Random();            int x = pol.Next(0, 3);            Game.DisplayText(Convert.ToString(x));            switch(x)            {                case 0:                    Player.WantedLevel = 2;                    policeEscape();                    Game.DisplayText("Cops!");                    break;                case 1:                    Game.DisplayText("Criminal");                    enemySpawn();                    break;                case 2:                    Game.DisplayText("Nothing");                    Player.Money += 2000;                    break;            }        }        public void policeEscape()        {            while(Player.WantedLevel > 0)            {            }            War.canRequest = false;            War.inMission = false;            Player.Money += 3000;        }        public void enemySpawn()        {            string[] modelArray = { "F_M_BUSINESS_02", "F_M_BUSINESS_01", "F_M_PEASTEURO_01", "F_M_RUNNER" };            Ped[] pedList = new Ped[4];            for(int i = 0; i < 4; i++)            {                Vector3 playerPos = World.GetNextPositionOnStreet(Player.Character.Position.Around(20.0F));                pedList[i] = World.CreatePed(modelArray[i], playerPos, RelationshipGroup.Criminal);                if(i == 0)                    enGroup = pedList[i].Group; //if statement so it doesn't get repeated                criminalProp(pedList[i]);                enGroup.AddMember(pedList[0]);            }            while(enGroup.MemberCount > 0)            {            }            War.inMission = false;            War.canRequest = false;            Player.Money += 5000;        }        public void criminalProp(Ped ped)        {            ped.WillDoDrivebys = true;            ped.Armor = 0;            ped.PriorityTargetForEnemies = true;            ped.AlwaysDiesOnLowHealth = true;            ped.SetPathfinding(true, true, true);            Weapon weapon = Weapon.SMG_Uzi;            ped.Weapons.FromType(weapon).Ammo = 250;            ped.Weapons.Select(weapon);            ped.RelationshipGroup = RelationshipGroup.Criminal;            ped.ChangeRelationship(RelationshipGroup.Criminal, Relationship.Hate);            ped.AttachBlip();        }    }}

 

 

Share this post


Link to post
Share on other sites
Jitnaught

I forgot to copy it after I changed the script

 

 

namespace ClassLibrary2{    public class AIBehaviour : Script    {        Group enGroup;        public void escape()        {            Random pol = new Random();            int x = pol.Next(0, 3);            Game.DisplayText(Convert.ToString(x));            switch(x)            {                case 0:                    Player.WantedLevel = 2;                    policeEscape();                    Game.DisplayText("Cops!");                    break;                case 1:                    Game.DisplayText("Criminal");                    enemySpawn();                    break;                case 2:                    Game.DisplayText("Nothing");                    Player.Money += 2000;                    break;            }        }        public void policeEscape()        {            while(Player.WantedLevel > 0)            {            }            War.canRequest = false;            War.inMission = false;            Player.Money += 3000;        }        public void enemySpawn()        {            string[] modelArray = { "F_M_BUSINESS_02", "F_M_BUSINESS_01", "F_M_PEASTEURO_01", "F_M_RUNNER" };            Ped[] pedList = new Ped[4];            for(int i = 0; i < 4; i++)            {                Vector3 playerPos = World.GetNextPositionOnStreet(Player.Character.Position.Around(20.0F));                pedList[i] = World.CreatePed(modelArray[i], playerPos, RelationshipGroup.Criminal);                if(i == 0)                    enGroup = pedList[i].Group; //if statement so it doesn't get repeated                criminalProp(pedList[i]);                enGroup.AddMember(pedList[0]);            }            while(enGroup.MemberCount > 0)            {            }            War.inMission = false;            War.canRequest = false;            Player.Money += 5000;        }        public void criminalProp(Ped ped)        {            ped.WillDoDrivebys = true;            ped.Armor = 0;            ped.PriorityTargetForEnemies = true;            ped.AlwaysDiesOnLowHealth = true;            ped.SetPathfinding(true, true, true);            Weapon weapon = Weapon.SMG_Uzi;            ped.Weapons.FromType(weapon).Ammo = 250;            ped.Weapons.Select(weapon);            ped.RelationshipGroup = RelationshipGroup.Criminal;            ped.ChangeRelationship(RelationshipGroup.Criminal, Relationship.Hate);            ped.AttachBlip();        }    }}

 

 

When you're creating the first ped, create the group and make him the leader.

enGroup = new Group(pedList[i]); //Creates a new group with the current ped as the leader

Share this post


Link to post
Share on other sites
Noox

Everything is working fine finally, thanks a lot!

Share this post


Link to post
Share on other sites
Jitnaught

Everything is working fine finally, thanks a lot!

Anytime ;)

Share this post


Link to post
Share on other sites
Noox

I have a problem with the AI, when they spawn sometimes they follow me but most of the times they don't :(

public void spawnPartners()        {            pGroup = Player.Group;            string[] model = { "M_Y_GTRI_LO_01", "M_Y_GTRI_LO_02", "M_M_CHINATOWN_01" };            for(int i = 0; i < 3; i++)            {                Vector3 playerPos = World.GetNextPositionOnStreet(Player.Character.Position.Around(30.0F));                friendlyTeam[i] = World.CreatePed(model[i], playerPos, RelationshipGroup.Player);                /*if (i == 0)                {                    Blip blip = friendlyTeam[i].AttachBlip();                    blip.Friendly = true;                }*/                Blip blip = friendlyTeam[i].AttachBlip();                blip.Friendly = true;                applyTeamProperties(friendlyTeam[i]);            }        }        public void applyTeamProperties(Ped p)        {            p.CurrentRoom = Player.Character.CurrentRoom;            p.WillDoDrivebys = true;            p.Armor = 250;            p.PriorityTargetForEnemies = true;            p.DuckWhenAimedAtByGroupMember = true;            p.SetPathfinding(true, true, true);            Weapon weapon = Weapon.Rifle_M4;            p.Weapons.FromType(weapon).Ammo = 250;            p.RelationshipGroup = RelationshipGroup.Player;            p.ChangeRelationship(RelationshipGroup.Player, Relationship.Companion);            p.CantBeDamagedByRelationshipGroup(RelationshipGroup.Player, true);            p.CanSwitchWeapons = true;            pGroup.AddMember(p);        }

Share this post


Link to post
Share on other sites
leftas

I don't think that this code, does something about following(relationships). Post your all code. And you will need to wait for others to help because I am going for a week in Norway to fish :D

 

Regards,

Paul.

Share this post


Link to post
Share on other sites
Noox

Here it is and have fun! I'm calling the functions from another file but there is nothing AI related there.

To anyone who didn't read the post above the friendly NPCs I'm spawning sometimes don't move, and when they follow me after a while they stop.

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using GTA;namespace ClassLibrary1{    class GTAFunctions : Script    {        Group pGroup;        public static Ped[] friendlyTeam = new Ped[3];        public GTAFunctions()        {        }        public Ped randomizeObjective()        {            Ped[] totPeds = World.GetAllPeds();            Ped curPed = World.CreatePed("M_M_HPORTER_01", World.GetNextPositionOnStreet(Player.Character.Position.Around(300.0F)), RelationshipGroup.Dealer);            curPed.SetPathfinding(true, true, true);            curPed.Task.WanderAround();            return curPed;        }        public void spawnPartners()        {            pGroup = Player.Group;            string[] model = { "M_Y_GTRI_LO_01", "M_Y_GTRI_LO_02", "M_M_CHINATOWN_01" };            for(int i = 0; i < 3; i++)            {                Vector3 playerPos = World.GetNextPositionOnStreet(Player.Character.Position.Around(30.0F));                friendlyTeam[i] = World.CreatePed(model[i], playerPos, RelationshipGroup.Player);                /*if (i == 0)                {                    Blip blip = friendlyTeam[i].AttachBlip();                    blip.Friendly = true;                }*/                Blip blip = friendlyTeam[i].AttachBlip();                blip.Friendly = true;                applyTeamProperties(friendlyTeam[i]);            }        }        public void applyTeamProperties(Ped p)        {            p.CurrentRoom = Player.Character.CurrentRoom;            p.WillDoDrivebys = true;            p.Armor = 250;            p.PriorityTargetForEnemies = true;            p.DuckWhenAimedAtByGroupMember = true;            p.SetPathfinding(true, true, true);            Weapon weapon = Weapon.Rifle_M4;            p.Weapons.FromType(weapon).Ammo = 250;            p.RelationshipGroup = RelationshipGroup.Player;            p.ChangeRelationship(RelationshipGroup.Player, Relationship.Companion);            p.CantBeDamagedByRelationshipGroup(RelationshipGroup.Player, true);            p.CanSwitchWeapons = true;            pGroup.AddMember(p); //Partners sometimes don't follow me        }    }}
Edited by Noox

Share this post


Link to post
Share on other sites
Jitnaught

 

Here it is and have fun! I'm calling the functions from another file but there is nothing AI related there.

To anyone who didn't read the post above the friendly NPCs I'm spawning sometimes don't move, and when they follow me after a while they stop.

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using GTA;namespace ClassLibrary1{    class GTAFunctions : Script    {        Group pGroup;        public static Ped[] friendlyTeam = new Ped[3];        public GTAFunctions()        {        }        public Ped randomizeObjective()        {            Ped[] totPeds = World.GetAllPeds();            Ped curPed = World.CreatePed("M_M_HPORTER_01", World.GetNextPositionOnStreet(Player.Character.Position.Around(300.0F)), RelationshipGroup.Dealer);            curPed.SetPathfinding(true, true, true);            curPed.Task.WanderAround();            return curPed;        }        public void spawnPartners()        {            pGroup = Player.Group;            string[] model = { "M_Y_GTRI_LO_01", "M_Y_GTRI_LO_02", "M_M_CHINATOWN_01" };            for(int i = 0; i < 3; i++)            {                Vector3 playerPos = World.GetNextPositionOnStreet(Player.Character.Position.Around(30.0F));                friendlyTeam[i] = World.CreatePed(model[i], playerPos, RelationshipGroup.Player);                /*if (i == 0)                {                    Blip blip = friendlyTeam[i].AttachBlip();                    blip.Friendly = true;                }*/                Blip blip = friendlyTeam[i].AttachBlip();                blip.Friendly = true;                applyTeamProperties(friendlyTeam[i]);            }        }        public void applyTeamProperties(Ped p)        {            p.CurrentRoom = Player.Character.CurrentRoom;            p.WillDoDrivebys = true;            p.Armor = 250;            p.PriorityTargetForEnemies = true;            p.DuckWhenAimedAtByGroupMember = true;            p.SetPathfinding(true, true, true);            Weapon weapon = Weapon.Rifle_M4;            p.Weapons.FromType(weapon).Ammo = 250;            p.RelationshipGroup = RelationshipGroup.Player;            p.ChangeRelationship(RelationshipGroup.Player, Relationship.Companion);            p.CantBeDamagedByRelationshipGroup(RelationshipGroup.Player, true);            p.CanSwitchWeapons = true;            pGroup.AddMember(p); //Partners sometimes don't follow me        }    }}

Don't know if this will work, but you could make a timer then put this code into the tick event

foreach (Ped p in mobilePeds){   if (p.Exists() && p.isAlive)   {      p.Task.RunTo(Player.Character.Position);   }}

Share this post


Link to post
Share on other sites
Noox

I tried it already but without the timer, thanks for that.

Share this post


Link to post
Share on other sites
Jitnaught

I tried it already but without the timer, thanks for that.

No problem.

I can't believe this topic already has 75 replies (not including this one) lol

Share this post


Link to post
Share on other sites
Noox

I think it's better not to create more topics for simple questions, asked here for help a few times.

Share this post


Link to post
Share on other sites
Jitnaught

I think it's better not to create more topics for simple questions, asked here for help a few times.

Yeah you're right

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.