Jump to content

AddMember not working


Noox

Recommended Posts

Hello,

 

I've got this piece of code

public void mainTick(object sender, EventArgs e)        {            if(inRampage)            {                seconds -= 2;                if (seconds <= 0)                {                    minutes--;                    seconds = 58;                }                Player.Character.Weapons.FromType(weapon).Ammo = 500;                if (Player.Character.Weapons.Current != weapon)                     Player.Character.Weapons.Select(weapon);                if (Player.Character.Health <= 50 && !healthIsBeingAdded)                    Player.Character.Health += 10;                if (Player.WantedLevel > 0)                    Player.WantedLevel = 0;                Random rnd = new Random();                Vector3 playerPos = World.GetNextPositionOnStreet(Player.Character.Position.Around(100.0F));                canSpawn = rnd.Next(0, 100) % 2 == 0;                if(canSpawn)                {                    enemy = World.CreatePed("M_M_ENFORCER", playerPos, RelationshipGroup.Criminal);                    enBlip = enemy.AttachBlip();                    enemy.SetPathfinding(true, true, true);                    enemy.ChangeRelationship(RelationshipGroup.Player, Relationship.Hate);                    enemy.AlwaysDiesOnLowHealth = true;                    enemy.RandomizeOutfit();                    enemy.CowerInsteadOfFleeing = true;                    enemy.Task.FightAgainst(Player.Character);                    Weapon weaponz = Weapon.SMG_MP5;                    enemy.Weapons.FromType(weaponz).Ammo = 500;                    enemy.Weapons.Select(weaponz);                    enemy.Task.GoTo(Player.Character);                    enemyGroup.AddMember(enemy);                }                Game.DisplayText(Convert.ToString(enemyGroup.MemberCount), 4000);                if (seconds == 31 && canGiveMoneys)                {                    Player.Money += 2000;                    canGiveMoneys = false;                }                canGiveMoneys = true;            }        }

And MemberCount always returns 0, it always worked before, why did it stop? :(

Edited by Noox
Link to comment
Share on other sites

Hello,

 

I've got this piece of code

public void mainTick(object sender, EventArgs e)        {            if(inRampage)            {                seconds -= 2;                if (seconds <= 0)                {                    minutes--;                    seconds = 58;                }                Player.Character.Weapons.FromType(weapon).Ammo = 500;                if (Player.Character.Weapons.Current != weapon)                     Player.Character.Weapons.Select(weapon);                if (Player.Character.Health <= 50 && !healthIsBeingAdded)                    Player.Character.Health += 10;                if (Player.WantedLevel > 0)                    Player.WantedLevel = 0;                Random rnd = new Random();                Vector3 playerPos = World.GetNextPositionOnStreet(Player.Character.Position.Around(100.0F));                canSpawn = rnd.Next(0, 100) % 2 == 0;                if(canSpawn)                {                    enemy = World.CreatePed("M_M_ENFORCER", playerPos, RelationshipGroup.Criminal);                    enBlip = enemy.AttachBlip();                    enemy.SetPathfinding(true, true, true);                    enemy.ChangeRelationship(RelationshipGroup.Player, Relationship.Hate);                    enemy.AlwaysDiesOnLowHealth = true;                    enemy.RandomizeOutfit();                    enemy.CowerInsteadOfFleeing = true;                    enemy.Task.FightAgainst(Player.Character);                    Weapon weaponz = Weapon.SMG_MP5;                    enemy.Weapons.FromType(weaponz).Ammo = 500;                    enemy.Weapons.Select(weaponz);                    enemy.Task.GoTo(Player.Character);                    enemyGroup.AddMember(enemy);                }                Game.DisplayText(Convert.ToString(enemyGroup.MemberCount), 4000);                if (seconds == 31 && canGiveMoneys)                {                    Player.Money += 2000;                    canGiveMoneys = false;                }                canGiveMoneys = true;            }        }

And MemberCount always returns 0, it always worked before, why did it stop? :(

Is the ped(s) spawning?

Link to comment
Share on other sites

Maybe change your enemyGroup.AddMember(enemy); to this:

int memberCountBeforeNewPed = enemyGroup.MemberCount;while (enemyGroup.MemberCount == memberCountBeforeNewPed){   enemyGroup.AddMember(enemy);}

This will check if the ped was added to the group yet, and if not, then add him. Though this could result in an infinite loop if the enemy is never added, so you may want it more like this:

int memberCountBeforeNewPed = enemyGroup.MemberCount, numTries = 0;while (enemyGroup.MemberCount == memberCountBeforeNewPed && numTries < 20){   enemyGroup.AddMember(enemy);   numTries++;}
Link to comment
Share on other sites

It doesn't work, anyway I tried adding the player to this group and it gives me an error, something like "non existing object" so maybe the group doesn't exist?

If it doesn't that's weird though as I've already used enemyGroup = new Group(leader)

Link to comment
Share on other sites

Write something that checks if they exist. Like this

if (ped.Exists()){   if (group.Exists())   {      //Add ped to group   }   else   {      Game.DisplayText("Group doesn't exist");   }}else{   Game.DisplayText("Ped doesn't exist");}
Link to comment
Share on other sites

They both exist :panic:

I'd skip the group section but they keep shooting each other, is there a way to avoid this without adding them to a group?

Link to comment
Share on other sites

Maybe change the relationship between the enemy peds. Other then that, I don't know.

Link to comment
Share on other sites

That worked! Also got a kill counter :)

I finished my first mod thanks to you guys, I love you(no homo eheh) :inlove:

Here's a screenshot, I'm happy :D

http://i.imgur.com/uBO1mq7.jpg

Edited by Noox
Link to comment
Share on other sites

Looks nice. Glad I could help :)

You have done so much more than I did in 4 days. My first mod was a check engine light :D

Link to comment
Share on other sites

Thanks!

Well, as long as we're satisfied when our job is done everything is fine :p

Link to comment
Share on other sites

Thanks!

SInce when the mission starts all the peds disappear is there a way to let them appear again when it's over?

 

EDIT: I forgot to change the ped and vehicle density, fixed now ^_^

Edited by Noox
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • 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.