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. Gameplay
      2. Missions
      3. Help & Support
    2. Red Dead Online

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

      1. Recruitment
    2. Events

    1. GTA Online

      1. Arena War
      2. After Hours
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Grand Theft Auto Series

    3. GTA Next

    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 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 Mods
    10. GTA Vice City

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

      1. Guides & Strategies
      2. Help & Support
      3. GTA 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

Noox

Hello, this is what I have done so far

public void spawnMobileAlly()        {            Group mobileGroup = Player.Group;            if (pGroup.MemberCount == 3)                Game.DisplayText("Too many group members");            else            {                Vector3 playerPos = Player.Character.Position.Around(50.0f);                Vehicle veh = World.CreateVehicle("INTRUDER", playerPos);                Ped[] mobilePeds = new Ped[3];                for (int i = 0; i < mobilePeds.Length; i++) {                     mobilePeds[i] = World.CreatePed(allyModel, playerPos, RelationshipGroup.Player);                    mobilePeds[i].WarpIntoVehicle(veh, ) //what should I put as seat?            }        }

but I don't know how the seats are called, by using visual studio intellisense I can see there is no driver or passenger, could you help me? thanks :)

Share this post


Link to post
Share on other sites
leftas

Class named VehicleSeat :) example of use:

VehicleSeat.Driver
Regards,

Paul.

Edited by leftas

Share this post


Link to post
Share on other sites
Noox

Thanks! How do I let them reach Niko by not leaving the vehicle?

Share this post


Link to post
Share on other sites
leftas

Just reach or and follow ?

 

Regards,

Paul.

Share this post


Link to post
Share on other sites
Noox

Reach.

Share this post


Link to post
Share on other sites
leftas
mobilePeds[i].Task.DriveTo(...);

This function. Also check Doc. from hazardx http://www.hazardx.com/details.php?file=89 There is everyhing. Or you can search in source code(C++) :)

 

Regards,

Paul.

Share this post


Link to post
Share on other sites
Noox

I finished it but it's not working, after 30 minutes of looking I gave up.

This is the mess I made

public void spawnMobileAlly()        {           pGroup = Player.Group;            if (pGroup.MemberCount == 3)                Game.DisplayText("Too many group members");            else            {                Vector3 playerPos = Player.Character.Position.Around(50.0f);                Vehicle veh = World.CreateVehicle("INTRUDER", playerPos);                Ped[] mobilePeds = new Ped[3];                for (int i = 0; i < mobilePeds.Length; i++)                {                    mobilePeds[i] = World.CreatePed(allyModel, playerPos, RelationshipGroup.Player);                    if (i == 0)                        mobilePeds[i].WarpIntoVehicle(veh, VehicleSeat.Driver);                    else                        mobilePeds[i].WarpIntoVehicle(veh, VehicleSeat.AnyPassengerSeat);                }                mobilePeds[1].Task.DriveTo(Player.Character, 250, false);                float mobDistance = mobilePeds[1].Position.DistanceTo(Player.Character.Position);                if (mobDistance < 2)                {                    for (int i = 0; i < mobilePeds.Length; i++)                    {                        mobilePeds[i].Task.LeaveVehicle();                        applyGroupProperties(mobilePeds[i]);                    }                }            }        }

applyGroupProperties:

public void applyGroupProperties(Ped p)        {            p.CurrentRoom = Player.Character.CurrentRoom;            p.WillDoDrivebys = true;            p.Armor = 500;            p.PriorityTargetForEnemies = true;            p.DuckWhenAimedAtByGroupMember = true;            p.AlwaysDiesOnLowHealth = true;            p.SetPathfinding(true, true, true);            Weapon weapon = Player.Character.Weapons.Current;            p.Weapons.FromType(weapon).Ammo = 500;            p.Weapons.Select(weapon);            p.RelationshipGroup = RelationshipGroup.Player;            p.ChangeRelationship(RelationshipGroup.Player, Relationship.Companion);            p.CantBeDamagedByRelationshipGroup(RelationshipGroup.Player, true);            pGroup.AddMember(p);        }

They spawn correctly (well, not correctly since most of the times they're not in the road :p) but they don't move and if I get closer they don't leave the vehicle, what's the problem?

Share this post


Link to post
Share on other sites
leftas

With last lines of spawn. That need's to be in loop to check. But I don't know how to do that don't need to loop(like for you) always applyGroupProperties I have workaround but it's dumb(it's i++ workaround)... Just I don't get your line

mobilePeds[1].Task.DriveTo(Player.Character, 250, false);

Array starts from 0 and your driver is at 0 not at 1 ?

Edited by leftas

Share this post


Link to post
Share on other sites
Noox

With last lines of spawn. That need's to be in loop to check. But I don't know how to do that don't need to loop(like for you) always applyGroupProperties I have workaround but it's dumb(it's i++ workaround)... Just I don't get your line

mobilePeds[1].Task.DriveTo(Player.Character, 250, false);

Array starts from 0 and your driver is at 0 not at 1 ?

lol I'm stupid, I forgot that eheh.

Now the driver comes to me but they don't disembark so I think that this piece of code is not working, I'll put a Game.DisplayText to see if the function is executed.

float mobDistance = mobilePeds[1].Position.DistanceTo(Player.Character.Position);                if (mobDistance < 2)                {                    for (int i = 0; i < mobilePeds.Length; i++)                    {                        mobilePeds[i].Task.LeaveVehicle();                        applyGroupProperties(mobilePeds[i]);                    }                }
Edited by Noox

Share this post


Link to post
Share on other sites
Rugz007

Which Mod You Making :D ??

Share this post


Link to post
Share on other sites
leftas

Also

applyGroupProperties(mobilePeds[i]);

this should be not in your loop but when you creating ped :)

 

So you can put in loop(main tick)

if (mobDistance < 2)                {                    for (int i = 0; i < mobilePeds.Length; i++)                    {                        if (movilePeds[i].isInVehicle())                                mobilePeds[i].Task.LeaveVehicle();                    }                }

EDIT: I said to you You just executing this one time(Key press) so it's not checking if they in your range or not, you need to put ^ this code in loop(main tick)

 

Regards,

Paul.

Edited by leftas

Share this post


Link to post
Share on other sites
Noox

Thanks but it's still not working, the condition always returns false, I inserted a debug message but it doesn't pop-up in game.

Share this post


Link to post
Share on other sites
leftas

I think 2 is too small(don't know how it's calculated in GTA 4) but I think this just too small. try to put 15

And you put that code in loop yea ?

 

Regards,

Paul.

Share this post


Link to post
Share on other sites
Noox

Yeah it's in the loop, I tried 20 already and it didn't work.

EDIT: Nevermind, I understood wrong because i didn't notice your edit, I'll see if it works now!

Alright I made the changes but now the script has an error in the main thick, the console says "error during thick "blabla" and then System.NullReferenceException so I think it's trying to say that the object I'm working on doesn't exist.

 

This is the entire code

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows.Forms;using GTA;namespace Mob{    public class Mob : Script    {        Group pGroup;        Model allyModel = "M_Y_BOUNCER_02";        Vector3 playerPos;        Vehicle veh;        Ped[] mobilePeds = new Ped[3];        float mobDistance;        public Mob()        {            Interval = Settings.GetValueInteger("INTERVAL", "SETTINGS", 1000);            playerPos = Player.Character.Position.Around(50.0f);            veh = World.CreateVehicle("INTRUDER", playerPos);            this.Tick += new EventHandler(testTick);            this.KeyDown += new GTA.KeyEventHandler(this.testKeyDown);        }        public void testTick(object sender, EventArgs e)        {            if(Exists(mobilePeds[0]))                mobDistance = mobilePeds[0].Position.DistanceTo(Player.Character.Position);            if (mobDistance < 15)            {                for (int i = 0; i < mobilePeds.Length; i++)                {                    if (mobilePeds[i].isInVehicle())                        mobilePeds[i].Task.LeaveVehicle();                }            }        }        public void testKeyDown(object sender, GTA.KeyEventArgs e)        {            switch (e.Key)            {                case Keys.N:                    spawnAlly();                    break;                case Keys.Delete:                    if(pGroup.MemberCount > 1)                    {                        foreach (Ped member in pGroup)                        {                            member.Weapons.RemoveAll();                            member.Die();                        }                        pGroup.RemoveAllMembers();                                           }                    break;                case Keys.End:                    spawnMobileAlly();                    break;            }        }        public void spawnAlly()        {            pGroup = Player.Group;            if (pGroup.MemberCount >= 3)                Game.DisplayText("Max member count reached!");            else            {                Ped p = World.CreatePed(allyModel, Player.Character.Position.Around(5.0f), RelationshipGroup.Player);                applyGroupProperties(p);            }        }        public void spawnMobileAlly()        {           pGroup = Player.Group;            if (pGroup.MemberCount == 3)                Game.DisplayText("Too many group members");            else            {                for (int i = 0; i < mobilePeds.Length; i++)                {                    mobilePeds[i] = World.CreatePed(allyModel, playerPos, RelationshipGroup.Player);                    if (i == 0)                        mobilePeds[i].WarpIntoVehicle(veh, VehicleSeat.Driver);                    else                        mobilePeds[i].WarpIntoVehicle(veh, VehicleSeat.AnyPassengerSeat);                    applyGroupProperties(mobilePeds[i]);                }                mobilePeds[0].Task.DriveTo(Player.Character, 250, true);            }        }        public void applyGroupProperties(Ped p)        {            p.CurrentRoom = Player.Character.CurrentRoom;            p.WillDoDrivebys = true;            p.Armor = 500;            p.PriorityTargetForEnemies = true;            p.DuckWhenAimedAtByGroupMember = true;            p.AlwaysDiesOnLowHealth = true;            p.SetPathfinding(true, true, true);            Weapon weapon = Player.Character.Weapons.Current;            p.Weapons.FromType(weapon).Ammo = 500;            p.Weapons.Select(weapon);            p.RelationshipGroup = RelationshipGroup.Player;            p.ChangeRelationship(RelationshipGroup.Player, Relationship.Companion);            p.CantBeDamagedByRelationshipGroup(RelationshipGroup.Player, true);            pGroup.AddMember(p);        }    }}

Thanks for the help.

EDIT: Nevermind, fixed it, I just needed to put the other if statement under if Exists but there is a problem, when they leave the vehicle they don't follow me, it's like the AI is disabled, they do nothing :(

EDIT2: Fixed that as well :) needed to apply their properties after they left the vehicle!

Thanks a lot leftas!

Edited by Noox

Share this post


Link to post
Share on other sites
Noox

Which Mod You Making :D ??

Just to get started you press a key and some guys come to help with a vehicle :)

Share this post


Link to post
Share on other sites
Rugz007

Very advanced as the 1st mod ;)

 

 

Mine was a helispwaner

Share this post


Link to post
Share on other sites
leftas

Hm I will notice that. But the problem is that you applying it x times when you are not in the vehicle. But you can fix that by

if (mobilePeds[i].isInVehicle()){      mobilePeds[i].Task.LeaveVehicle();      applyGroupProperties(mobilePeds[i]);}

Or even if you don't want to start loop you just check if driver in the vehicle and then check distance and start loop ;) I don't like to start loop because for it, uses more resources and you applying the same sh*t over and over again....

Share this post


Link to post
Share on other sites
Noox

Thanks, that should be more optimized :p
I noticed that I have one more problem, basically if I keep pressing del new vehicles with a new crew will keep spawning even if I use that if statement, why that?

I tried doing a counter which is initialized to 0 then when the key is pressed it checks if it's 0 (could have used a boolean var but whatever) then if it is 0 it creates a new vehicle and it gets incremented but still vehicles keep spawning with new NPCs but just the first 3 are inside the car.

How can I fix that?

Edited by Noox

Share this post


Link to post
Share on other sites
leftas

Hm I can't understand this sentence

 

I noticed that I have one more problem, basically if I keep pressing del new vehicles with a new crew will keep spawning even if I use that if statement, why that?

Sorry but I can't understand what you mean by that ?

Can you give me an example ?

Again sorry!

 

Regards,

Paul.

Share this post


Link to post
Share on other sites
Noox

Let's say I have to press X to spawn a group of guys inside the vehicle.

I press X, new vehicle spawns somewhere with 3 NPCs, the NPCs go inside the vehicle.

I have a variable that counts how many vehicles there are, when I press X the first time the vehicle count goes to 1 and when I press X again the the game checks if the vehicle count is 0, since there is a vehicle already it will not spawn it again with 3 more guys.

This does not happen, even if the vehicle count is 1 it still spawns a vehicle, an empty one.

 

EDIT: Since one function spawned some guys on foot there was some kind of conflict with the group variable, I deleted that function and everything is working fine! Thanks again :)

Edited by Noox

Share this post


Link to post
Share on other sites
leftas

Can you show me the code, how you do that ?

 

Regards,

Paul.

Share this post


Link to post
Share on other sites
Noox

Sure, here's the function, also, is there a way to change the blip color and remove it when the ped is dead? I see nothing in the documentation, just attachBlip().

        public void spawnMobileAlly()        {            pGroup = Player.Group;            playerPos = Player.Character.Position.Around(50.0f);            if (pGroup.MemberCount < 3) //if there are less than 3 members in my group then create a vehicle            {                veh = World.CreateVehicle("INTRUDER", playerPos);            }            if (pGroup.MemberCount >= 3) //if there are more than 3 members in my group do nothing and display text                Game.DisplayText("Too many group members");            else                         //otherwise spawn 3 NPCs            {                for (int i = 0; i < mobilePeds.Length; i++)                {                    if(pGroup.MemberCount <= 3)                         mobilePeds[i] = World.CreatePed(allyModel, playerPos, RelationshipGroup.Player);                    if (i == 0)                        mobilePeds[i].WarpIntoVehicle(veh, VehicleSeat.Driver);                    else                        mobilePeds[i].WarpIntoVehicle(veh, VehicleSeat.AnyPassengerSeat);                    //applyGroupProperties(mobilePeds[i]);                    //pGroup.AddMember(mobilePeds[i]);                }                mobilePeds[0].Task.DriveTo(Player.Character, 250, true);            }            mobilePeds[0].AttachBlip();        }
Edited by Noox

Share this post


Link to post
Share on other sites
leftas

You need to have blip like

Blip yea = mobilePeds[0].AttachBlip(); // not tested
yea.color = BlipColor.Red; // not tested

also RGB way

yea.SetColorRGB(System.Drawing.Color.Moccasin);

Just after reading you comment again saw that you solved your problem :D

 

Regards,

Paul.

Edited by leftas

Share this post


Link to post
Share on other sites
Noox

Eheh actually not, I wasn't very careful.

The game was still spawning vehicles but in places I couldn't see them, I fixed it by slightly changing the conditional statement.

Thanks for all the help!

 public void spawnMobileAlly()        {            pGroup = Player.Group;            playerPos = Player.Character.Position.Around(10.0f);            if (pGroup.MemberCount >= 3)                return;            veh = World.CreateVehicle("INTRUDER", playerPos);            if (pGroup.MemberCount >= 3)                Game.DisplayText("Too many group members");            else            {                for (int i = 0; i < mobilePeds.Length; i++)                {                    if(pGroup.MemberCount <= 3)                         mobilePeds[i] = World.CreatePed(allyModel, playerPos, RelationshipGroup.Player);                    if (i == 0)                        mobilePeds[i].WarpIntoVehicle(veh, VehicleSeat.Driver);                    else                        mobilePeds[i].WarpIntoVehicle(veh, VehicleSeat.AnyPassengerSeat);                    //applyGroupProperties(mobilePeds[i]);                    //pGroup.AddMember(mobilePeds[i]);                }                mobilePeds[0].Task.DriveTo(Player.Character, 250, true);            }        }

Share this post


Link to post
Share on other sites
PlayPrey

Hey, I can actually help :D

 

To force a vehicle to spawn on the road use the ' World.GetNextPositionOnStreet ' in vector3 location, an example on its use:

World.CreateVehicle(World.GetNextPositionOnStreet(Player.Character.Position.Around(10.0F)));

Share this post


Link to post
Share on other sites
Jitnaught

 

Hey, I can actually help :D

 

To force a vehicle to spawn on the road use the ' World.GetNextPositionOnStreet ' in vector3 location, an example on its use:

World.CreateVehicle(World.GetNextPositionOnStreet(Player.Character.Position.Around(10.0F)));

I was JUST about to post this lol

Share this post


Link to post
Share on other sites
Noox

 

Hey, I can actually help :D

 

To force a vehicle to spawn on the road use the ' World.GetNextPositionOnStreet ' in vector3 location, an example on its use:

World.CreateVehicle(World.GetNextPositionOnStreet(Player.Character.Position.Around(10.0F)));

That was very helpful! Thanks a lot, most of the time they were spawning in the roofs :p

Share this post


Link to post
Share on other sites
Jitnaught

 

Sure, here's the function, also, is there a way to change the blip color and remove it when the ped is dead? I see nothing in the documentation, just attachBlip().

        public void spawnMobileAlly()        {            pGroup = Player.Group;            playerPos = Player.Character.Position.Around(50.0f);            if (pGroup.MemberCount < 3) //if there are less than 3 members in my group then create a vehicle            {                veh = World.CreateVehicle("INTRUDER", playerPos);            }            if (pGroup.MemberCount >= 3) //if there are more than 3 members in my group do nothing and display text                Game.DisplayText("Too many group members");            else                         //otherwise spawn 3 NPCs            {                for (int i = 0; i < mobilePeds.Length; i++)                {                    if(pGroup.MemberCount <= 3)                         mobilePeds[i] = World.CreatePed(allyModel, playerPos, RelationshipGroup.Player);                    if (i == 0)                        mobilePeds[i].WarpIntoVehicle(veh, VehicleSeat.Driver);                    else                        mobilePeds[i].WarpIntoVehicle(veh, VehicleSeat.AnyPassengerSeat);                    //applyGroupProperties(mobilePeds[i]);                    //pGroup.AddMember(mobilePeds[i]);                }                mobilePeds[0].Task.DriveTo(Player.Character, 250, true);            }            mobilePeds[0].AttachBlip();        }

 

Put this in a tick to detect if any of the peds are dead, and if so, delete the blip.

foreach (Ped p in mobilePeds)            {                if (p.isDead)                {                    blip.Delete();                }            }

Also you could add this in the tick too, if you want to detect if the vehicle is alive.

if (!veh.isAlive)            {                blip.Delete();            }

Share this post


Link to post
Share on other sites
leftas

 

 

Sure, here's the function, also, is there a way to change the blip color and remove it when the ped is dead? I see nothing in the documentation, just attachBlip().

        public void spawnMobileAlly()        {            pGroup = Player.Group;            playerPos = Player.Character.Position.Around(50.0f);            if (pGroup.MemberCount < 3) //if there are less than 3 members in my group then create a vehicle            {                veh = World.CreateVehicle("INTRUDER", playerPos);            }            if (pGroup.MemberCount >= 3) //if there are more than 3 members in my group do nothing and display text                Game.DisplayText("Too many group members");            else                         //otherwise spawn 3 NPCs            {                for (int i = 0; i < mobilePeds.Length; i++)                {                    if(pGroup.MemberCount <= 3)                         mobilePeds[i] = World.CreatePed(allyModel, playerPos, RelationshipGroup.Player);                    if (i == 0)                        mobilePeds[i].WarpIntoVehicle(veh, VehicleSeat.Driver);                    else                        mobilePeds[i].WarpIntoVehicle(veh, VehicleSeat.AnyPassengerSeat);                    //applyGroupProperties(mobilePeds[i]);                    //pGroup.AddMember(mobilePeds[i]);                }                mobilePeds[0].Task.DriveTo(Player.Character, 250, true);            }            mobilePeds[0].AttachBlip();        }

 

Put this in a tick to detect if any of the peds are dead, and if so, delete the blip.

foreach (Ped p in mobilePeds)            {                if (p.isDead)                {                    blip.Delete();                }            }

Also you could add this in the tick too, if you want to detect if the vehicle is alive.

if (!veh.isAlive)            {                blip.Delete();            }

Sheit, I misread that :D

Share this post


Link to post
Share on other sites
Rugz007

I also did wanted the delete thing thanks letsplayordy :D

 

 

You making progress faster ;)

 

Good Now i think my tutorials will come use to you :)

Share this post


Link to post
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
Sign in to follow this  

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

×

Important Information

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