Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

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

Joined
Feb 22, 2012
Messages
2,100
Reaction score
1,271
Following from : http://forum.ragezone.com/f578/grand-theft-auto-modding-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 ( ) 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:

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 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 ( ), 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:
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:
PHP:
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:

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


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:

Cheat table:

Code:
~r~ [COLOR="#B22222"]red[/COLOR]
~g~ [COLOR="#008000"]green[/COLOR]
~b~ [COLOR="#0000CD"]blue[/COLOR]
~w~ white (default)
~p~ [COLOR="#800080"]purple[/COLOR]
~o~ [COLOR="#FF8C00"]orange[/COLOR]
~y~ [COLOR="#FFFF00"]yellow[/COLOR]

This applies to most of the in-game UI, including notifications. Example:

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:
PHP:
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.Revolver, 10000, true, true); // 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:
foreach(Ped p in World.GetAllPeds())
            {
                p.Weapons.Give(WeaponHash.AdvancedRifle, 10000, true, true);
                p.Task.FightAgainst(Game.Player.Character);
            }

Kill all players:
PHP:
foreach(Ped p in World.GetAllPeds())
            {
                p.Kill();
            }

Delete all players:
PHP:
foreach(Ped p in World.GetAllPeds())
            {
                p.Delete();
            }


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

Attachments

You must be registered for see attachments list
Last edited:
Retired
Joined
Apr 15, 2015
Messages
715
Reaction score
238
I remember when we had a few conversations about you modding gta. Great tutorial, very detailed!
 
Newbie Spellweaver
Joined
Jun 1, 2012
Messages
44
Reaction score
99
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.
 
Joined
Feb 22, 2012
Messages
2,100
Reaction score
1,271
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..
 
Initiate Mage
Joined
Oct 22, 2020
Messages
1
Reaction score
0
Wow, dude! This is really useful. And you say you've never had any programming classes? It's even more impressive. I've never tried to make modes by myself, only downloaded them, specially cars modes or weapons. I'm just learning how to program in C and I have to say your tutorials are really useful. And it's better to learn by modding your favourite game than by doing some boring stuff. Also, I've read that will be released soon and wonder if it's possible to install mods on mobile version?
 
Last edited:
Back
Top