[C#] Grand Theft Auto V: Modding Guide Part 2 - Your first mod

Results 1 to 9 of 9
  1. #1
    not a DEVELOPER Droppy is offline
    DeveloperRank
    Feb 2012 Join Date
    /home/droppyLocation
    2,092Posts

    [C#] Grand Theft Auto V: Modding Guide Part 2 - Your first mod

    Following from : http://forum.ragezone.com/f578/grand...guide-1100772/
    _____________________________________________

    In this part 2 I'll cover the basics of the mod writing, including simple snippets, basic C# coding, etc.

    Read me: everything I know is what I gathered through time. I had no programming classes, so I may make a few mistakes here and there. You sure can correct me anytime you want, through this thread or through PM, and I'll make sure to fix it. Same if you need any help, I'd rather if you comment here on the thread, but if you want to PM, feel free to do so. There isn't many documentations I can go and check out, so this is only what I've accomplished.

    This is not a tutorial on how to write C#, but how to use main methods. I'll try to explain everything regardless, though.

    In-game resolution of 800x600 for easier screenshot!

    You may have seen and used our latest example of UI.Notify, that shows you a notification "Hello World!" in the game's screen.

    This will be a simple explaination on how it works.

    The GTA Namespace

    The GTA namespace is from the ScriptHookV.net.

    It covers: GTA, GTA.Native, GTA.Math and GTA.NaturalMotion.

    What is the ScriptHookV.net and the GTA Namespace?

    The GTA namespace is the implementation of the ScriptHookV. Resuming what it does, it implements the nativedb ( GTAV NATIVE DB ) into a .NET Library.

    Ok, so... Let's begin with the basics?

    Sure. First, make sure that you have followed throughly the last part of the tutorial, and that everything is working correctly. Make a new project if you want to, I'm going to explain line by line, trying always to simplify.

    You'll see in your code these few lines in the beginning:

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    In a simpler meaning, it will make use of the namespaces into the file, so it's namespaces can be accessed through the code.

    More about namespaces/using: https://msdn.microsoft.com/en-us//library/0d941h9d.aspx

    We are going to make use of the GTA namespace, so add under using System.Threading.Tasks; :
    Code:
    using GTA;
    using GTA.Natives;
    This will make accessible the GTA and GTA.Natives in your code.

    Code:
    namespace RagezoneTest
    {
        public class RZTest
        {    }
    }
    This will be your main script. What will call all the logic, methods, and everything else.

    You have to extend the class Script (which is from ScriptHookV.net).

    This extended class will be the main class of your mod.

    Your code will be like this:

    Code:
    namespace RagezoneTest
    {
        public class RZTest : Script
        {    }
    }
    Then we have to make our main method (constructor), so add inside the class RZTest:

    Code:
    public RZTest()
    {
         // This is where your code goes!
    }
    Your code now will be ready.

    Your code will be like this:

    PHP Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using GTA;
    using GTA.Natives;

    namespace 
    RagezoneTest
    {
        public class 
    RZTest Script
        
    {
            public 
    RZTest()
            {
                
    // This is where your code goes!
            
    }
        }

    The construct of the RZTest will run only once, but we will work in there for now, for the code examples...

    First, let's talk about the Game, World, UI classes.

    Game class contains a few settings you will use, as for your default Player and others. You can trigger auto save, get current FPS (Game.FPS), get game language (Game.Language) , get your current player (Game.Player), get if game is paused (Game.IsPaused), even set thermal vision!

    World class contains world management and settings. You can add an explosion, you can get all peds, get all peds nearby, get all vehicles, get all vehicles nearby, get all entities, create blip, create camera, set blackout (turn all lights off), and lots of others. Create peds and vehicles are also made with this.

    UI class contains UI modifications, settings, and others. You have methods to notifications, show subtitles, draw textures, etc.

    First, let's add something to show the FPS and language. Remember, this is only going to show as soon as the trainer is loaded. We haven't made the tick function yet, nor anything to persist with the code.

    Code:

    Code:
    UI.ShowSubtitle("~r~RaGEZONE~w~ FPS: " + Game.FPS + " / " + Game.Language);
    This is going to add a subtitle showing your current FPS and your current language.

    Whole code:
    Spoiler:

    PHP Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using GTA;

    namespace 
    RagezoneTest
    {
        public class 
    RZTest Script
        
    {
            public 
    RZTest()
            {
                
    UI.ShowSubtitle("~r~RaGEZONE~w~ FPS: " Game.FPS " / " Game.Language);
            }
        }



    Example of result: RaGEZONE FPS: 60 / English

    In-game result:



    Remember: if you are trying this out, press the button Insert to reload the script!

    It's going to only show the frames once (not being updated). It's fine for now. Play with it if you want!

    As you can notice, there's a color difference between RaGEZONE and the fps count/language. Why? It's the text format.

    It works like this, you write ~yourcolor~word. ~r~ stands for red, ~g~ for green, ~b~ for blue.

    "~r~MentaL says: ~g~Droppy ~b~rocks!"

    Result: http://i.imgur.com/PsGsLg6.png

    Cheat table:

    Code:
    ~r~ red
    ~g~ green
    ~b~ blue
    ~w~ white (default)
    ~p~ purple
    ~o~ orange
    ~y~ yellow
    This applies to most of the in-game UI, including notifications. Example: http://prntscr.com/aufsyx

    Code:
    UI.Notify("~r~MentaL says: ~g~Droppy ~b~rocks!");
    But... what can I do with it?

    For now, not much. Considering the script is being thrown out already, and has no more utility (it doesn't loop, after all).

    ----------------------------------------------------------------
    Let's start to talk about the Ped and Player...

    What is the Player class? Player class is the in-game "you". It's behind the Ped itself.

    What is the Ped class? Ped class is the in-game "doll". It can either be "you" (Franklin, Trevor or Michael), or it can be any other Ped walking on the street.

    What is the different between the two of them? Think the Player as the soul, and the Ped as the body. Only you (the player) has the Player class set, though. Is like only you have a soul AND a body, and the rest only have a body.

    ----------------------------------------------------------------
    A few codes if you wanna play by yourself until the next part comes out:
    Spoiler:

    PHP Code:
    Game.Player.Money += 10000// gives 10k GTA$
    Game.Player.Money -= 5000// takes 5k GTA$
    Game.Player.WantedLevel 3// set wanted level to 3
    Game.Player.Character.Weapons.Give(WeaponHash.Revolver10000truetrue); // gives player a revolver with 10k of ammo, equiped and loaded. 
    Extra:

    Loops all peds, gives them an AdvancedRifle, and makes them fight against you hehe
    PHP Code:
    foreach(Ped p in World.GetAllPeds())
                {
                    
    p.Weapons.Give(WeaponHash.AdvancedRifle10000truetrue);
                    
    p.Task.FightAgainst(Game.Player.Character);
                } 
    Kill all players:
    PHP Code:
    foreach(Ped p in World.GetAllPeds())
                {
                    
    p.Kill();
                } 
    Delete all players:
    PHP Code:
    foreach(Ped p in World.GetAllPeds())
                {
                    
    p.Delete();
                } 

    Delete all cars:
    PHP Code:
    foreach(Vehicle v in World.GetAllVehicles())
    {
        
    v.Delete();

    Last edited by Droppy; 20-04-16 at 05:37 AM.

    Subscribe | Rules
    PM Me | Add Me

    Developer
    &
    Ex-Moderator




  2. #2
    what a twat is this hat? ovflowd is offline
    Alpha MaleRank
    Sep 2011 Join Date
    /etc/rc.localLocation
    2,255Posts

    Re: [C#] Grand Theft Auto V: Modding Guide Part 2 - Your first mod

    Thats' really amazing @Droppy! Sensational Tutorials.



  3. #3
    xHosts.uk Robot is offline
    True MemberRank
    Apr 2015 Join Date
    EnglandLocation
    728Posts

    Re: [C#] Grand Theft Auto V: Modding Guide Part 2 - Your first mod

    I remember when we had a few conversations about you modding gta. Great tutorial, very detailed!

    xHosts - Support Staff - Visit us today @ xhosts.uk

  4. #4
    what a twat is this hat? ovflowd is offline
    Alpha MaleRank
    Sep 2011 Join Date
    /etc/rc.localLocation
    2,255Posts

    Re: [C#] Grand Theft Auto V: Modding Guide Part 2 - Your first mod

    Please @Droppy do a Part 3!!!



  5. #5
    Alpha Member bramdebouvere is offline
    Alpha MaleRank
    Aug 2006 Join Date
    BelgiumLocation
    2,457Posts

    Re: [C#] Grand Theft Auto V: Modding Guide Part 2 - Your first mod

    Wow that's fucking awesome. I need to try this sometime

  6. #6

    Re: [C#] Grand Theft Auto V: Modding Guide Part 2 - Your first mod

    Well done dude, I'm planning to do a 'pastebin' website for GTA V codes...
    I'm into GTA V modding since last year, it's a great area, I learned a lot, creating peds, maps, tools...
    I wish this new zone is approved.

  7. #7
    not a DEVELOPER Droppy is offline
    DeveloperRank
    Feb 2012 Join Date
    /home/droppyLocation
    2,092Posts

    Re: [C#] Grand Theft Auto V: Modding Guide Part 2 - Your first mod

    Quote Originally Posted by Met0do View Post
    Well done dude, I'm planning to do a 'pastebin' website for GTA V codes...
    I'm into GTA V modding since last year, it's a great area, I learned a lot, creating peds, maps, tools...
    I wish this new zone is approved.
    at0m there ar etons of information missing. if there's a new GTA V section id surely make new tutorials about it, until then i see no point on updating these..

    Subscribe | Rules
    PM Me | Add Me

    Developer
    &
    Ex-Moderator



  8. #8
    StoP Callin me MentaL I'm Not MentaL is offline
    GammaRank
    Dec 2008 Join Date
    Guang Dong, PRCLocation
    4,279Posts

    Re: [C#] Grand Theft Auto V: Modding Guide Part 2 - Your first mod

    noice!!

  9. #9
    Newbie headbangboy is offline
    MemberRank
    Apr 2018 Join Date
    VancouverLocation
    4Posts

    Re: [C#] Grand Theft Auto V: Modding Guide Part 2 - Your first mod

    Sick tutorial dude! Salute from Vancouver :)



Advertisement