- Joined
- Feb 22, 2012
- Messages
- 2,103
- 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 (
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:
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; :
This will make accessible the GTA and GTA.Natives in your code.
This will be your main script. What will call all the logic, methods, and everything else.
You have to
This extended class will be the main class of your mod.
Your code will be like this:
Then we have to make our main method (
Your code now will be ready.
Your code will be like this:
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:
This is going to add a subtitle showing your current FPS and your current language.
Whole code:
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:
Cheat table:
This applies to most of the in-game UI, including notifications. Example:
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:
Extra:
Loops all peds, gives them an AdvancedRifle, and makes them fight against you hehe
Kill all players:
Delete all players:
Delete all cars:
_____________________________________________
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 (
You must be registered to see links
) 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:
You must be registered to see links
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
You must be registered to see links
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 (
You must be registered to see links
), 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:
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:
You must be registered to see links
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:
You must be registered to see links
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: