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. DLC
      2. Find Lobbies & Players
      3. Guides & Strategies
      4. Vehicles
      5. Content Creator
      6. Help & Support
      7. The Diamond Casino Heist
    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  
qiangqiang101

[C#/VB] Get NearbyPeds enter vehicle on random seat?

Recommended Posts

qiangqiang101

How to get nearby peds enter my vehicle and choose random seat?

and also if the seat is taken, the existing ped will get out of the vehicle?

Share this post


Link to post
Share on other sites
bilago

Here is some rough code that should get you going...

 

 

            //Random Generator            Random r = new Random();                        //Put all vehicle seats in a list            List<VehicleSeat> seats = new List<VehicleSeat>() { VehicleSeat.LeftFront, VehicleSeat.LeftRear, VehicleSeat.RightFront, VehicleSeat.RightRear };             //Make sure player is in vehicle, if not dont continue             if(!Game.Player.Character.IsInVehicle())               return;            //Get players current vehicle            Vehicle v = Game.Player.Character.CurrentVehicle;            //if null player is not in a vehicle            if (v != null)            {                   //getting all peds within a 10f radius                Ped[] peds = World.GetNearbyPeds(Game.Player.Character, 10f);                //enumerate through all the peds in array                for (int i = 0; i < peds.Length; i++)                {                       //check to see if this ped is in a vehicle already, if they are skip them                       if(peds[i].IsInVehicle())                         continue;                       //Get Random Seat                      VehicleSeat RandomSeat = seats[r.Next(0, seats.Count)];                                             //is seat empty?                        if (!v.IsSeatFree(RandomSeat))                        {                            //getting the pedestrian sitting in the seat, lets tell him to leave the vehicle but leave the door open                            v.GetPedOnSeat(RandomSeat).Task.LeaveVehicle(v, false);                                                   }                    //seat is empty, have this pedestrian enter the vehicle at that seat                       peds[i].Task.EnterVehicle(v, RandomSeat);                }            }
Edited by bilago
  • Like 1

Share this post


Link to post
Share on other sites
qiangqiang101

 

Here is some rough code that should get you going...

 

 

            //Random Generator            Random r = new Random();                        //Put all vehicle seats in a list            List<VehicleSeat> seats = new List<VehicleSeat>() { VehicleSeat.LeftFront, VehicleSeat.LeftRear, VehicleSeat.RightFront, VehicleSeat.RightRear };             //Make sure player is in vehicle, if not dont continue             if(!Game.Player.Character.IsInVehicle())               return;            //Get players current vehicle            Vehicle v = Game.Player.Character.CurrentVehicle;            //if null player is not in a vehicle            if (v != null)            {                   //getting all peds within a 10f radius                Ped[] peds = World.GetNearbyPeds(Game.Player.Character, 10f);                //enumerate through all the peds in array                for (int i = 0; i < peds.Length; i++)                {                       //check to see if this ped is in a vehicle already, if they are skip them                       if(peds[i].IsInVehicle())                         continue;                       //Get Random Seat                      VehicleSeat RandomSeat = seats[r.Next(0, seats.Count)];                                             //is seat empty?                        if (!v.IsSeatFree(RandomSeat))                        {                            //getting the pedestrian sitting in the seat, lets tell him to leave the vehicle but leave the door open                            v.GetPedOnSeat(RandomSeat).Task.LeaveVehicle(v, false);                                                   }                    //seat is empty, have this pedestrian enter the vehicle at that seat                       peds[i].Task.EnterVehicle(v, RandomSeat);                }            }

 

Thanks the code works, but 3 question

1. If i was driving a bus or coach, the bus has 16 seats include the driver and the coach has 10 seats include the driver, but there's only "VehicleSeat.LeftFront, VehicleSeat.LeftRear, VehicleSeat.RightFront, VehicleSeat.RightRear", how to have other seats?

 

2. How to calm the passenger, they enter my bus and shout "take cover, take cover" or "f*cked!" or "sh*t" and they looking confusing

 

3. Why some pedestrian not enter my bus even i command them to enter my bus?

Share this post


Link to post
Share on other sites
bilago

 

 

 

 

1. If i was driving a bus or coach, the bus has 16 seats include the driver and the coach has 10 seats include the driver, but there's only "VehicleSeat.LeftFront, VehicleSeat.LeftRear, VehicleSeat.RightFront, VehicleSeat.RightRear", how to have other seats?

 

2. How to calm the passenger, they enter my bus and shout "take cover, take cover" or "f*cked!" or "sh*t" and they looking confusing

 

3. Why some pedestrian not enter my bus even i command them to enter my bus?

 

 

1. VehicleSeat doesn't expose more than 4 seat locations, I don't know of any mods that get around that, so perhaps its not possible with current coding or no one has figured it out yet.

 

2. You probably need to set the Relationship of that pedestrian, probably Relationship.Like or Relationship.Companion

 

3. The code I sent you was not tested by me I just wrote it on a whim so I don't know if there are bugs or not. Driver seat is included in the random seat selection, since you're the driver you're not being ejected and that pedestrian cannot sit there.

Share this post


Link to post
Share on other sites
leftas

 

 

 

 

 

1. If i was driving a bus or coach, the bus has 16 seats include the driver and the coach has 10 seats include the driver, but there's only "VehicleSeat.LeftFront, VehicleSeat.LeftRear, VehicleSeat.RightFront, VehicleSeat.RightRear", how to have other seats?

 

2. How to calm the passenger, they enter my bus and shout "take cover, take cover" or "f*cked!" or "sh*t" and they looking confusing

 

3. Why some pedestrian not enter my bus even i command them to enter my bus?

 

 

1. VehicleSeat doesn't expose more than 4 seat locations, I don't know of any mods that get around that, so perhaps its not possible with current coding or no one has figured it out yet.

 

2. You probably need to set the Relationship of that pedestrian, probably Relationship.Like or Relationship.Companion

 

3. The code I sent you was not tested by me I just wrote it on a whim so I don't know if there are bugs or not. Driver seat is included in the random seat selection, since you're the driver you're not being ejected and that pedestrian cannot sit there.

 

1. Lol, maybe scripthookvdotnet developers was lazy to add more value to enum ?

 

Also about list, it's worthless and memory wasteful. These values are already in enum which you can enumerate.

 

All the best,

Paul.

Share this post


Link to post
Share on other sites
bilago

 

 

1. Lol, maybe scripthookvdotnet developers was lazy to add more value to enum ?

 

 

Also about list, it's worthless and memory wasteful. These values are already in enum which you can enumerate.

 

All the best,

Paul.

 

1. Looks like it

 

2. The List class is the generic equivalent of the ArrayList class, which is the same class you would use to store the Seats enum, it also is beneficial if you want to remove specific entries from being used (in this case we don't want to include VehicleSeat.Driver or VehicleSeat.FrontLeft) which will save the developer from having to code in logic to avoid those options and the extra cpu cycles each tick to run that logic.

 

Share this post


Link to post
Share on other sites
bilago

This is the VehicleSeat enum exposed:

 

public enum VehicleSeat
{
None = -3,
Any = -2,
LeftFront = -1,
Driver = -1,
Passenger = 0,
RightFront = 0,
LeftRear = 1,
RightRear = 2,
}
It would be as simple as figuring out the remaining seat int values (3 -> vehicles max seats)
or when a seat is taken you can try doing:
pedestrian.Task.ShuffleToNextVehicleSeat(vehicle)

I don't know how that task is handled if the bus is full though.

 

 

 

 


Edited by bilago

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.

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.