Games

Write the script for GTA 5 for GTA 5

This lesson will come in handy if you decide to do to suddenly playing your own helper script that will perform any required tasks.
Today I'm going to show you how to zaspavnit′ a car next to the player, change its color and tuning parts. All this will happen by pressing a specific key on the keyboard. You also learn how to work with a class player, for example, you can remove the visibility of the player by pressing a specific key.
Well, with all this, we will withdraw the relevant inscription on the screen using native functions of the game. Perhaps start a. ..

Each script begins by creating a simple text file in the scripts folder, which is located in the folder with the game. Name the file, for example myFirstScript, and then save the file with the extension ".cs". Open a file in a simple notebook and connect classes GTA and system libraries. This is done as follows:


using GTA;
using GTA.Native;
using GTA.Math;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;


The next step is to create a class derived from the class script. Pay attention to the class name matches the name of the script file.
Look at the code:

public class myFirstScript : Script  // объявление нашего класса
{
    public myFirstScript() // конструктор класса, функция которая срабатывает первой при создании класса
    {

    }	
}

Now it is up to small. Connect the event handler the keystrokes on the keyboard and actually accomplish our task.
The handler is connected as follows:

public class myFirstScript : Script 
{
    public myFirstScript() 
    {
       KeyDown += onkeydown;  // указываем на то, что клавиатурой занимается наша функция
    }

    void onkeydown(object sender, KeyEventArgs e) // наш обработчик
    {
       if (e.KeyCode == Keys.K)
       {
          // если нажали на клавишу K
       }
       if (e.KeyCode == Keys.J)
       {
          // если нажали на клавишу J
       }
    }	
}

Next proceed to the spavnu machine. You can do this as follows:

		var position = Game.Player.Character.GetOffsetInWorldCoords(new Vector3(0, 5, 0)); // берем координаты игрока и прибавляем смещение 5 игровых метров от него
		var heading = Game.Player.Character.Heading - 90; // берем поворот игрока
		var vehicle = World.CreateVehicle(VehicleHash.Dubsta, position, heading); // создаем машину под названием Dubsta
		vehicle.DirtLevel = 15f;   // указываем уровень грязи
		vehicle.CustomPrimaryColor = Color.White; // указываем первичный цвет
		vehicle.CustomSecondaryColor = Color.Black; // указываем вторичный цвет
		vehicle.PlaceOnGround(); // ставим машину на свои координаты
		Function.Call(Hash.SET_VEHICLE_MOD_KIT, vehicle.Handle, 0);  // включаем тюнинг
		vehicle.SetMod(VehicleMod.FrontBumper, 3, true); // ставим передний бампер
		vehicle.SetMod(VehicleMod.RearBumper, 1, true); // задний бампер

The following line of code will hide the player in case of pressing and do again the player is visible when you click:

Game.Player.Character.IsVisible = !Game.Player.Character.IsVisible;

And finally show the message by calling native functions to do this, create your own function is similar to the following:

    public void PrintText(string text, int time)
    {
            GTA.Native.Function.Call(GTA.Native.Hash._0xB87A37EEB7FAA67D, "STRING");
            GTA.Native.Function.Call(GTA.Native.Hash._ADD_TEXT_COMPONENT_STRING, text);
            GTA.Native.Function.Call(GTA.Native.Hash._0x9D77056A530643F6, time, 1);
    }

An example of a function call is PrintText ("hello world!", 10000);

Look at the complete source if you need to download the script myFirstScript.zip. Successful scripting.
Oh Yes ... almost forgot, make sure to put in the game Net ScriptHook, otherwise it will not work smile


using GTA;
using GTA.Native;
using GTA.Math;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;

public class myFirstScript : Script
{
    public myFirstScript()
    {
        KeyDown += onkeydown;
    }
	

public void PrintText(string text, int time)
    {
            GTA.Native.Function.Call(GTA.Native.Hash._0xB87A37EEB7FAA67D, "STRING");
            GTA.Native.Function.Call(GTA.Native.Hash._ADD_TEXT_COMPONENT_STRING, text);
            GTA.Native.Function.Call(GTA.Native.Hash._0x9D77056A530643F6, time, 1);
    }

    void onkeydown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.K)
        {
		var position = Game.Player.Character.GetOffsetInWorldCoords(new Vector3(0, 5, 0));
		var heading = Game.Player.Character.Heading - 90;
		var vehicle = World.CreateVehicle(VehicleHash.Dubsta, position, heading);
		vehicle.DirtLevel = 15f;
		vehicle.CustomPrimaryColor = Color.White;
		vehicle.CustomSecondaryColor = Color.Black;
		vehicle.NumberPlate = "GTA V";
		vehicle.PlaceOnGround();
		Function.Call(Hash.SET_VEHICLE_MOD_KIT, vehicle.Handle, 0);
		vehicle.SetMod(VehicleMod.FrontBumper, 3, true);
		vehicle.SetMod(VehicleMod.RearBumper, 1, true);
		vehicle.SetMod(VehicleMod.Hood, 2, true);
		PrintText("spawned Dubsta", 10000);

        }
	else if(e.KeyCode == Keys.J)
	{
		Game.Player.Character.IsVisible = !Game.Player.Character.IsVisible;
		PrintText("change visibility", 10000);
	}
    }
}

Result in the screenshots:
Пишем скрипт для GTA 5

Пишем скрипт для GTA 5
73
0
4
Like:  4
smalloff
smalloff

Published on 3 August 2016

To favorites
Share
Share:
Information
There are no comments yet. Your comment will be first.
Information
You must be registered to leave a comment on this publication.

Site rules и privacy policy

© 2012-2024 GameModding.com All rights reserved.