Log in to reply
 

[Tutorial] Making a C# Bodyguard Script with "Grand Theft Auto V - Mod Creator"



  • After updating I have received 13 friend requests, and 18 messages on Steam for help/guide on how to start a script using the tool.
    So here it is:

    How to make a C# Script Mod for Grand Theft Auto V

    This tutorial is using Grand Theft Auto V - Mod Creator


    Before starting, please install the tool and ensure you have all of the files.

    The first step is to name your mod, this is going to be the name of your Class, and Namespace (for more information on classes & namespaces, visit these links: (Namespace, Class)

    Replace the following with your mod name:

    namespace ModName
    

    Next, replace these:

            string ModName = "MOD NAME";
            string Developer = "YOUR NAME";
            string Version = "1.0";
    

    In most cases, you will not need to change the Version, but feel free to do whatever you want.

    We will be making a simple bodyguard script.

    To start, lets insert a key press.
    We will use the KeyDown tool.
    Navigate to Insert --> KeyDown

    Image Unavailable

    Ensure that your cursor is inside of the "onKeyDown" method

    Image Unavailable

    Type your desired key and press "KeyDown". This will insert a new if statement (For information on if statements, click here)

    Here is an example of what your script may look like now:

    Image Unavailable

    Now lets create your bodyguard inside of the GTA V game world.
    To do this you will need to write some code yourself.
    Before we continue, we need to have our player and playerPed variables. (For information on variables, click here)
    To do this, you can use the Player tools.
    Navigate to Insert --> Player --> player Variable
    You also need the playerPed variable
    Navigate to Insert --> Player --> playerPed Variable

    Image Unavailable

    Your code should now look something like this

    Image Unavailable

    Now, lets spawn the bodyguard.
    You will be using the World.CreatePed() method. (For information on methods/functions, click here)
    Insert the following code to your script:

    Ped bodyguard = World.CreatePed(new Model(PedHash.Armoured02SMM), playerPed.Position);
    

    We have now created the bodyguard at the players position and can mess with him using his variable bodyguard.
    PedHash.Armoured02SMM is the bodyguard's model hash, you can change this if you'd like.

    Next step is to give him weapons, we will just give him a Pistol for now.
    Insert the following code:

    bodyguard.Weapons.Give(WeaponHash.Pistol, 9999, true, true);
    

    This code gives the bodyguard a pistol with 9999 ammo. You can add more weapons if you would like, just copy and change the WeaponHash.

    Now we need to give the bodyguard some armor.
    You can use the Ped.Armor variable.

    bodyguard.Armor = 100; // Armor ranges from 1-100
    

    We're almost done, we need to add the bodyguard to the players group so he protects the player.
    We are using a native from the NativeDB here, using the GTA.Native.Function.Call() method

    PedGroup playerGroup = playerPed.CurrentPedGroup; // gets the players current group
    Function.Call(Hash.SET_PED_AS_GROUP_MEMBER, bodyguard, playerGroup); // puts the bodyguard into the players group
    

    You are gonna need to set the combat ability as well.

    Function.Call(Hash.SET_PED_COMBAT_ABILITY, bodyguard, 100); // 100 = attack
    

    The final step here is optional, but we are going to notify the player when a bodyguard is spawned.
    We can use the tool Notify for this.
    Navigate to Insert --> UI --> Notify

    Image Unavailable

    Feel free to change "Bodyguard spawned!" to whatever you like.

    You're done, to check, make sure your code looks similar to this:

    Image Unavailable

    All that is left now is to save your file and run the game!

    Press File --> Save As... and navigate to your Grand Theft Auto V folder,
    we need to put this file in the scripts folder, if you do not have this folder, create it.

    Image Unavailable

    Lets run the game and test the script.

    If everything is right, then you should get this:

    Image Unavailable

    Enjoy, I will be posting more tutorials soon!

    Reply with any troubles you may run into.



  • @FIFASam said in [Tutorial] Making a C# Bodyguard Script with "Grand Theft Auto V - Mod Creator":

    Before starting, please install the tool and ensure you have all of the files.

    wtf after i installed when i opened my gta this popped up

    alt text



  • @jedijosh920 said in [Tutorial] Making a C# Bodyguard Script with "Grand Theft Auto V - Mod Creator":

    @FIFASam said in [Tutorial] Making a C# Bodyguard Script with "Grand Theft Auto V - Mod Creator":

    Before starting, please install the tool and ensure you have all of the files.

    wtf after i installed when i opened my gta this popped up

    alt text

    really weird josh ill look into that ok sr ?



  • @FIFASam thx daddy :blush:



  • The mod creator just adds some snippets of code so that you don't have to type it. Just use Visual Studio, it has more features like intellisense and stuff.



  • @AHK1221 You're right, but this is a neat tool for beginners, who may not be used to visual studio.



  • @jedijosh920 why downvote me :(



  • Hello, i have problem if i want to save the srcipt its say me C:\Program Files (x86)\FIFApps\V Creator\Files\recent.mc is denied. :(


Log in to reply
 

Looks like your connection to GTA5-Mods.com Forums was lost, please wait while we try to reconnect.