I'm developing a game modification for GTAV, but I got stuck. I want to display options on the screen using a loop and I kinda got that working, but it isn't displaying correctly.
This is what code I'm using to display the text:
void DRAW_TEXT(char* text, float x, float y, float s_x, float s_y, int font, bool outline, bool Shadow, bool center, bool RightJustify, int r, int g, int b, int a){
UI::SET_TEXT_COLOUR(r, g, b, a);
UI::SET_TEXT_DROPSHADOW(0, 0, 0, 0, 0);
if (outline) UI::SET_TEXT_OUTLINE();
UI::SET_TEXT_FONT(font);
UI::SET_TEXT_CENTRE(center);
UI::SET_TEXT_RIGHT_JUSTIFY(RightJustify);
UI::SET_TEXT_SCALE(s_x, s_y);
UI::BEGIN_TEXT_COMMAND_DISPLAY_TEXT(STRING);
UI::ADD_TEXT_COMPONENT_SUBSTRING_PLAYER_NAME(text);
UI::END_TEXT_COMMAND_DISPLAY_TEXT(x, y);
}
Then I loop it like so:
for (int i = 0; i < optionCount; i++) {
if (i == selectedIndex) {
DRAW_TEXT(MenuOptions[i], 0.169 + (0.230 * (i / 3)), 0.228 + (0.040 * (i / 3)), 0.35, 0.35, 0, false, false, false, false, 0, 0, 0, 255);
} else {
DRAW_TEXT(MenuOptions[i], 0.169 + (0.230 * (i / 3)), 0.228 + (0.040 * (i / 3)), 0.35, 0.35, 0, false, false, false, false, 255, 255, 255, 255);
}
}
The outcome of that is like this:
How can I make it so it displays all the options under eachother instead of next to eachother like so:
Option 1
Option 2
Option 3
etc..
In your code you're using i / 3
expression, which won't work as you expected unless you cast i
to floating-point type. You need to use something like this:
DRAW_TEXT(MenuOptions[i], 0.169 + (0.230 * ((double)i / 3)), 0.228 + (0.040 * ((double)i / 3)), 0.35, 0.35, 0, false, false, false, false, 0, 0, 0, 255);