Home Tools Generate working C# code while in game V1.0 – GTA 5 mod

Generate working C# code while in game V1.0 – GTA 5 mod

0
Generate working C# code while in game V1.0 – GTA 5 mod


Introduction
I recently uploaded a LemonUI script that captures just under 100 different locations each with their own x,y,z and heading coordinates. Obviously to do this manually would have been crazy. Instead I saved the coordinates for each teleport, using Menyoo xml. and then I wrote a program to parse everything out and create working code. This worked really well however my curious side nagged me to find an even better way. The solution was simple, generate the code in game itself, no Menyoo required.

For all these items below, of course you would substitute your own code, but the process will be essentially the same. As stated above, this was done for LemonUI based mods and specifically for the GTA V Tourist, but using your imagination hopefully you will realize it can be used for any script or mod that requires capturing information such as coordinates for locations. It could easily be adapted, for example, for capturing ped components (drawables, textures) or vehicle characteristics (models, colors, extras, modkits, etc).

Features
The code in this download will generate three key components for LemonUI based applications
1. The Menu Item Definition (for the new entry in the menu)
In this script template’s context:
new NativeItem(“Tahir Javan House”, “”) //spaces allowed, generated by a single entry

2. The Event Handler/Subscriber (for the item activation)
Menu10_Items[6].Activated += (sender, e) => Menu10_6_Tahir Javan House(); // spaces replaced buy underscore, the item numbers are incremented by the script. Same single entry as above.

3. Teleport Method (for the method that handles the teleportation and effects)
private void Menu10_6_Tahir Javan House() {
FadeInOutEffects(() =>
{
Vector3 position = new Vector3(-3086.868f, 341.6472f, 7.375443f);
float heading = 27.75087f;
TeleportWithCam(position, heading, -15f, 4f, CameraFxMs, false);
});
}
// once again, the method is created from one single entry and the number (10_6) is incremented by the script.

Usage
This is definitely not for LemonUI beginners but again give it a shot if you want. The .cs extension is from Visual studio and renaming to .3.cs will not remove the requirement for compilation.

1. On a keypress, F5 here, the dev will be presented with a prompt for the location name.
2.The script will capture the player’s coordinates and with some pre-defined code concatenate working code.
3. This code will then be used in Visual Studio to complete your script.
4. On a side note, given the captured code’s 3 sections need to go in specific locations (methods, handlers, items) I used AI to sort the code numerically for me in those 3 categories which took it less than 2 seconds. By numerically, we mean item1, 2, 3, 4, etc.

So all in all this approach is extremely efficient and also eliminates all errors doing manual entries. In fact, at one point, using a manual process (exceptionally) I screwed up the coordinates for Trevor’s Trailer location. This can’t happen with the script.

Other
Location names, as they will appear in the menu and to the user, can have spaces. Since methods can’t have spaces, although this isn’t a concern for user, the spaces will be replaced by underscores.

Advanced users will notice something missing. You need to add items to the menu. This isn’t required in the script because you will use a generic solution that applies to all your items like this:

private void AddItemsToMenu(NativeMenu menu, List items)
{
foreach (var item in items)
{
menu.Add(item);
item.TitleFont = GTA.UI.Font.ChaletComprimeCologneNotGamerName; //optional
}
}

Credits:

JohnFromGWN

Download mod

File File size

CodeCreation
1 KB



Source link

NO COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Exit mobile version