Create Your Own Trainer - Part 3
Adding Our First Item
In this section we will see how to add one item to our menu. To do this we will first write the line of code that will give us the display, as show in the screenshot below. There are optional elements but let's keep things as simple as possible for now.
private static readonly NativeItem SpawnSportster = new NativeItem("Spawn HD Sportster", "");
Now as a second step we need to add this to our menu with this line of code:
menu.Add(SpawnSportster); SpawnSportster.Activated += VHDIron883;
The third and final step is to add the code that will spawn the motorcycle below. This function will be called: private void VHDIron883(object sender, EventArgs e)
So those are the three steps required to add a single item to a menu. This tutorial won't teach you how to program, just how to create the Trainer/Menu framework, but I'm providing the working code.
You can view the full code here.
Note: depending on the code you use, you might need to add more references or create additional using statements. You will also need to write declarations. As an example, there are dozens of ways to spawn vehicles such as cars and motorcycles. In the code below, for simplicity, we use PP to replace Game.Player.Character, in other words the player. The declaration will look like this:
public static Ped PP = Game.Player.Character;
One way to spawn a vehicle is like this:
Vehicle vehicle15 = World.CreateVehicle("HDIron883", PP.Position + PP.ForwardVector * 3.0f, PP.Heading + 90);
If you write the code as above, you will need to add using GTA.Native which is included in the SHVND3 reference we have already added in Part 1.
Another way of doing the same thing is like this:
Vehicle vehicle15 = World.CreateVehicle("HDIron883", PP.GetOffsetPosition(new Vector3(2, 0, 0)), PP.Heading + 90);
However this second method not only requires GTA.Native but it also requires GTA.Math because of the new Vector. Thankfully this is also included in our SHVDN3. As mentioned above, this isn't a tutorial about programming, but we will reemphasize that there are many ways to write code. Some using Native Functions, some using SHVDN3 functions, and often both.
The full working code can be copied from this Pastebin page.