Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

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

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

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

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

    2. Support

    3. Suggestions

[C#] Help with Pedestrian Variations Script


CR_Jayhawk11
 Share

Recommended Posts

I am currently new to coding (especially for Grand Theft Auto V) and was searching for some answers to change the clothing of certain pedestrians. I have come across many tutorials, but most are confusing and tend to be unspecific. I vaguely understand how to start the script and set-up the pedestrian variation thanks to this forum topic, however I am looking to change a pedestrian not the player. Please correct me if I am wrong, but this is how that is normally constructed in C#:

Function.Call(Hash.SET_PED_COMPONENT_VARIATION, Game.Player.Character, 2, 1, 0, 2)

It probably is something very simple, but I can not find the correct way to input a normal pedestrian. The model I am specifically referring to, and would like to change, is the s_m_y_marine_03. I have tried using a pedestrian hash along with a long list of other crazy combinations to replace the player portion of this line, but all have been a complete failure. Am I able to switch with a non-playable character, or can I only change the clothing and props of the active player?

 

The reason that I ask is that I am hoping to add to the Bodyguard Squads mod by Eddlm. My dream is that when I spawn a group of a certain pedestrian model from the mod menu, they all have the exact same features. In this instance, I would like each s_m_y_marine_03 to have a regular helmet, rather than some having gas masks while others have both or nothing at all. Can this be accomplished by scripting? Or is there an easier way to accomplish this, like deleting the gas mask texture and drawable mesh portion from a certain file? If so, please let me know. This is the major part of the script I am attempting to make, so any input on correct ways to build this script would be greatly appreciated. Thanks!

Edited by CR_Jayhawk11
Link to comment
Share on other sites

First off, you first have to create or get an already created ped to do this. If you don't have a ped created, create him using:

Ped myPed = World.CreatePed();

Use the needed parameters to create him. If you want to get the closest ped use:

Ped myPed = World.GetClosestPed(Game.Player.Character.Position, 30f);

To get the targeted ped use:

Ped myPed = Game.Player.GetTargetedEntity as Ped;

There many other ways too, just search on ScriptHookVDotNet's github page. After you have the ped use this:

Function.Call(Hash.SET_PED_COMPONENT_VARIATION, myPed, 2, 1, 0, 2)

its good to use all this in a key bind:

if(e.KeyCode == Keys.R){   Ped myPed = (your method);      if(myPed == null) return;   Function.Call(Hash.SET_PED_COMPONENT_VARIATION, myPed, 2, 1, 0, 2);   UI.ShowSubtitle("Component's changed!");}
Edited by AHK1221
Link to comment
Share on other sites

 

First off, you first have to create or get an already created ped to do this. If you don't have a ped created, create him using:

Ped myPed = World.CreatePed();

Use the needed parameters to create him. If you want to get the closest ped use:

Ped myPed = World.GetClosestPed(Game.Player.Character.Position, 30f);

To get the targeted ped use:

Ped myPed = Game.Player.GetTargetedEntity as Ped;

There many other ways too, just search on ScriptHookVDotNet's github page. After you have the ped use this:

Function.Call(Hash.SET_PED_COMPONENT_VARIATION, myPed, 2, 1, 0, 2)

its good to use all this in a key bind:

if(e.KeyCode == Keys.R){   Ped myPed = (your method);      if(myPed == null) return;   Function.Call(Hash.SET_PED_COMPONENT_VARIATION, myPed, 2, 1, 0, 2);   UI.ShowSubtitle("Component's changed!");}

Thanks so much for your reply! This helps me a lot. However, can you set the pedestrian as one specific model and for the components to change for it throughout the entire world? Or do you absolutely have to create one?

Link to comment
Share on other sites

 

 

 

 

 

 

First off, you first have to create or get an already created ped to do this. If you don't have a ped created, create him using:

Ped myPed = World.CreatePed();

Use the needed parameters to create him. If you want to get the closest ped use:

Ped myPed = World.GetClosestPed(Game.Player.Character.Position, 30f);

To get the targeted ped use:

Ped myPed = Game.Player.GetTargetedEntity as Ped;

There many other ways too, just search on ScriptHookVDotNet's github page. After you have the ped use this:

Function.Call(Hash.SET_PED_COMPONENT_VARIATION, myPed, 2, 1, 0, 2)

its good to use all this in a key bind:

if(e.KeyCode == Keys.R){   Ped myPed = (your method);      if(myPed == null) return;   Function.Call(Hash.SET_PED_COMPONENT_VARIATION, myPed, 2, 1, 0, 2);   UI.ShowSubtitle("Component's changed!");}

Thanks so much for your reply! This helps me a lot. However, can you set the pedestrian as one specific model and for the components to change for it throughout the entire world? Or do you absolutely have to create one?

 

It could be done, however I haven't tested it so may not work:

Ped[] allPeds;Model yourPedModel = new Model("s_m_y_marine_03");public yourClass(){    this.KeyDown += onKeyDown;}private void onKeyDown(object sender, KeyEventArgs e){    if(e.KeyCode == Keys.B)    {        allPeds = World.GetAllPeds(yourPedModel);            if(allPeds == null) return;                for(int i = 0;i < allPeds.Length;i++)        {            Function.Call(Hash.SET_PED_COMPONENT_VARIATION, allPeds[i], 2, 1, 0, 2);        }    }}

if you want this to happen automatically(MAY NOT WORK!!!):

Ped[] allPeds;Model yourPedModel = new Model("s_m_y_marine_03");public yourClass(){    this.Tick += onTick;}private void onTick(object sender, EventArgs e){       allPeds = World.GetAllPeds(yourPedModel);        if(allPeds == null) return;    for(int i = 0;i < allPeds.Length;i++)    {        Function.Call(Hash.SET_PED_COMPONENT_VARIATION, allPeds[i], 2, 1, 0, 2);    }}
Edited by AHK1221
Link to comment
Share on other sites

It works! Thank you so much! I will definitely keep you in mind for anything else involving scripting.

Link to comment
Share on other sites

It works! Thank you so much! I will definitely keep you in mind for anything else involving scripting.

 

Glad to help you out.
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
 Share

  • 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.