Quantcast

Jump to content

» «
Photo

AddMember not working

14 replies to this topic
Noox
  • Noox

    changeScriptAbility(&myScriptAbility, "improve");

  • Members
  • Joined: 20 Jun 2014
  • None

#1

Posted 24 June 2014 - 10:57 AM Edited by Noox, 24 June 2014 - 10:57 AM.

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? :(


LetsPlayOrDy
  • LetsPlayOrDy

    Lets mod or die!

  • Members
  • Joined: 24 Aug 2013
  • United-States

#2

Posted 24 June 2014 - 11:27 AM

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?


Noox
  • Noox

    changeScriptAbility(&myScriptAbility, "improve");

  • Members
  • Joined: 20 Jun 2014
  • None

#3

Posted 24 June 2014 - 11:31 AM

Yes they are.


LetsPlayOrDy
  • LetsPlayOrDy

    Lets mod or die!

  • Members
  • Joined: 24 Aug 2013
  • United-States

#4

Posted 24 June 2014 - 01:17 PM

Did you create the group? Using enemyGroup = new Group(leaderPed); ?


Noox
  • Noox

    changeScriptAbility(&myScriptAbility, "improve");

  • Members
  • Joined: 20 Jun 2014
  • None

#5

Posted 24 June 2014 - 01:20 PM

Yes.


LetsPlayOrDy
  • LetsPlayOrDy

    Lets mod or die!

  • Members
  • Joined: 24 Aug 2013
  • United-States

#6

Posted 24 June 2014 - 01:29 PM

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++;
}

Noox
  • Noox

    changeScriptAbility(&myScriptAbility, "improve");

  • Members
  • Joined: 20 Jun 2014
  • None

#7

Posted 24 June 2014 - 01:46 PM

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)


LetsPlayOrDy
  • LetsPlayOrDy

    Lets mod or die!

  • Members
  • Joined: 24 Aug 2013
  • United-States

#8

Posted 24 June 2014 - 02:34 PM

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");
}

Noox
  • Noox

    changeScriptAbility(&myScriptAbility, "improve");

  • Members
  • Joined: 20 Jun 2014
  • None

#9

Posted 24 June 2014 - 02:41 PM

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?


LetsPlayOrDy
  • LetsPlayOrDy

    Lets mod or die!

  • Members
  • Joined: 24 Aug 2013
  • United-States

#10

Posted 24 June 2014 - 02:45 PM

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


Noox
  • Noox

    changeScriptAbility(&myScriptAbility, "improve");

  • Members
  • Joined: 20 Jun 2014
  • None

#11

Posted 24 June 2014 - 03:09 PM Edited by Noox, 24 June 2014 - 03:14 PM.

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


LetsPlayOrDy
  • LetsPlayOrDy

    Lets mod or die!

  • Members
  • Joined: 24 Aug 2013
  • United-States

#12

Posted 24 June 2014 - 03:18 PM

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


Noox
  • Noox

    changeScriptAbility(&myScriptAbility, "improve");

  • Members
  • Joined: 20 Jun 2014
  • None

#13

Posted 24 June 2014 - 03:21 PM

Thanks!

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


LordOfTheBongs
  • LordOfTheBongs

    Deceased

  • Members
  • Joined: 21 Sep 2013
  • None

#14

Posted 24 June 2014 - 03:37 PM Edited by LordOfTheBongs, 02 July 2014 - 05:28 PM.

...


Noox
  • Noox

    changeScriptAbility(&myScriptAbility, "improve");

  • Members
  • Joined: 20 Jun 2014
  • None

#15

Posted 24 June 2014 - 04:36 PM Edited by Noox, 24 June 2014 - 04:56 PM.

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 ^_^

  • Wiebrendh likes this




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users