Log in to reply
 

[C#][Tutorial] Basics of creating a script PART 2



  • Part 2 of the creating a script tutorial!

    NOTE: You must've completed the first tutorial to follow this one!

    In this tutorial, we will cover the following:
    Native calling.
    Vectors and car spawning
    Ini handling with build-in classes
    Vehicle handling(requested)

    In the last tutorial, we left off at a reset wanted level script. In this script, I will cover the different features of SHVDN and how to use them.

    1) Native Calling
    SHVDN is basically a wrapper for the C++ ScriptHook. It calls the natives to do things in the game. But there are a few things that are not in SHVDN and for those we go the old school manual native calling.
    To call a native, we use this:
    alt text
    We can easily set a blackout using World.SetBlackout(bool status) but if we want to do it manually, this is the code we use:
    alt text
    There are a lot of natives, around 5000, and Alexander Blade has made an awesome website for researching natives.
    Native DB
    Some natives, however are not that simple.
    For example, the native
    _WORLD3D_TO_SCREEN2D
    dont return a Vector2 or a position. They use something called OutputArguments. We will discuss them in a later tutorial.

    2) Vectors and car spawning
    To determine a position, GTA uses Vectors. There are two types of Vectors. Vector 2 and Vector 3. The Vector3 is very commonly used. Vector3 consists of three floats, x, y, and z. These are positions in 3d space. It's hard to explain them, but just know that they determine a position. Vector 2 is the same thing, it only doesnt have the 3D element to it, and only has x and y. Those positions are the screen positions. But lets focus on Vector3s for now. For example, I want to spawn a car at a set location, 5 units front of the player. For spawning a car, we use the static World.CreateVehicle method and a Vector3 for the position:
    alt text
    Now there is a lot going on here. I'll try to explain everything.
    Vector3 position - this is declaring a new Vector3 class

    Game.Player.Character - this may be confusing. Remember, Game.Player is the actual Player class and Game.Player.Character is a Ped class. If you want to do anything playerish like wantedlevels, it will be in Game.Player. If you want to do tasks to the player, it is in Game.Player.Character. I will explain this later on.

    Game.Player.Character.Position - self explanatory, this returns a Vector3 coordinate of the player's ped.

    Game.Player.Character.ForwardVector - it returns the vector you are facing.

    Game.Player.Character.Position + Game.Player.Character.ForwardVector - basic rule of vectors, if you add a vector to another vector, you get a direction. In this cause we get a direction relative to our position and our heading.

    Game.Player.Character.Position + Game.Player.Character.ForwardVector * 5 - this adds to the direction so it is 5 units.

    Hope this makes sense :P

    Ini handling
    If you are a hardcore C# programmer, you probably wouldn't like these classes, but these are ok for simple Inis. SHVDN uses the class ScriptSettings. This is how you load an ini:
    alt text
    Do note this will throw an exception if the path doesnt exist. The string path should be easy to understand, since i said you require the basics of C#.
    To get values from an ini:
    alt text
    Easy to understand, "SECTION" is the section, "NAME" is the name of the key, and "DEFAULTVALUE" is something that the class would default to, if it didnt find the key.
    This is how the ini should look like:

    [SECTION]
    NAME=VALUE

    To set values, we use nearly the same thing:
    alt text

    Vehicle Handling
    As requested, I am doing this also.

    Opening and closing doors
    alt text
    The first parameter is simple, it is an enum with all the doors.
    The second parameter is if you want it to be loose, again self-explanatory
    The third parameter is if you want it to open instantly

    Yes, its as simple as that.
    alt text
    Again, simple.
    Second parameter is if you want it to close instantly.

    indicators
    alt text
    Simple, right?

    Colors
    alt text
    Simple again.

    In the next tutorial, we will look into the Tick event and the OutputArguments stuff. Until then, bye!



  • @GTAVModder4Life amazing, you are the best. tutorial 2 the same day. cant wait following your script. visual studio is loading :smile: ok i see the parameters but now we need to define a key which activates or deactivates the indicators, am i right? and i have to put every single door, hood, trunk and so in an extra line there is no "open all" parameter? or is it called native? the most difficult task is to translate all this stuff to my language. my english is not the best :wink: means "vehiclehash.adder" spawns the (car) adder 5 units in front of me/the player or is it a variabel and the part which car we add comes later? or opens a window ingame where i can enter the name of the car i wish to spawn?
    sorry that i have so many questions but the beginning is the hardest, so excuse all those maybe very simple questions. but maybe i can help you with zmodeler3 a bit (have seen your request) to give you a little bit back...ähm...to thank you (oh man sorry for my poor poor english, hope u understand still what i mean) so if you have a specific question to zmodeler i can make a video to explain or can give you an answer in the badest english you have ever read :disappointed:
    hope there is very soon a german - english tutorial on gta5mods :sweat_smile:

    tobsicred v = World.CreateBrain(BrainHash.InsertEnglish, position)



  • @TobsiCred you can make a key definition like this:
    alt text
    This is my whole onKeyDown event. in this one, if you press H or K, it creates an Adder 5 units front of you. But if you pressed H, the vehicle would have its indicators on. If you pressed K, it will have the front left(driver side) door open. For the ZModeler, I have quite figured it out, but if i need help i will contact you ;)

    Basically, this whole tutorial was info on how to use it. In the last tutorial, I showed you how to do key events so I just put info here on how to use SHVDN


Log in to reply
 

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