Sharpiee Posted June 13, 2016 Share Posted June 13, 2016 (edited) I am going off the code snippets from the original NativeTrainer source code for drawing a menu. Whenever I press my button to activate the menu GUI, my game freezes and crashes. This is a small part of the code I have at the moment: void drawRect(float A_0, float A_1, float A_2, float A_3, int A_4, int A_5, int A_6, int A_7){ GRAPHICS::DRAW_RECT((A_0 + (A_2 * 0.5f)), (A_1 + (A_3 * 0.5f)), A_2, A_3, A_4, A_5, A_6, A_7);}void renderMenuLine(std::string title, float optionWidth, float optionHeight, float optionTop, float optionLeft, float textLeft, bool active, bool menuTitle, bool rescaleText = true){ //Default Values int text_col[4] = { 255, 0, 0, 255 }, rect_col[4] = { 0, 0, 0, 255 }; float text_scale = 0.35; int font = 0; //Hover if (active) { text_col[0] = 255; text_col[1] = 255; text_col[2] = 255; rect_col[0] = 50; rect_col[1] = 50; rect_col[2] = 50; if (rescaleText) text_scale = 0.40; } if (menuTitle) { rect_col[0] = 255; rect_col[1] = 255; rect_col[2] = 255; rect_col[3] = 255; if (rescaleText) text_scale = 0.50; font = 1; } int screen_w, screen_h; GRAPHICS::GET_SCREEN_RESOLUTION(&screen_w, &screen_h); textLeft += optionLeft; float lineWidthScaled = optionWidth / (float)screen_w; // line width float lineTopScaled = optionTop / (float)screen_h; // line top offset float textLeftScaled = textLeft / (float)screen_w; // text left offset float lineHeightScaled = optionHeight / (float)screen_h; // line height float lineLeftScaled = optionLeft / (float)screen_w; //Upper Text UI::SET_TEXT_FONT(font); UI::SET_TEXT_SCALE(0.0, text_scale); UI::SET_TEXT_COLOUR(text_col[0], text_col[1], text_col[2], text_col[3]); UI::SET_TEXT_CENTRE(0); UI::SET_TEXT_DROPSHADOW(0, 0, 0, 0, 0); UI::SET_TEXT_EDGE(0, 0, 0, 0, 0); UI::_SET_TEXT_ENTRY("STRING"); UI::_ADD_TEXT_COMPONENT_STRING((LPSTR)title.c_str()); UI::_DRAW_TEXT(textLeftScaled, (((lineTopScaled + 0.00278f) + lineHeightScaled) - 0.005f)); //Lower Text UI::SET_TEXT_FONT(font); UI::SET_TEXT_SCALE(0.0, text_scale); UI::SET_TEXT_COLOUR(text_col[0], text_col[1], text_col[2], text_col[3]); UI::SET_TEXT_CENTRE(0); UI::SET_TEXT_DROPSHADOW(0, 0, 0, 0, 0); UI::SET_TEXT_EDGE(0, 0, 0, 0, 0); UI::_SET_TEXT_GXT_ENTRY("STRING"); UI::_ADD_TEXT_COMPONENT_STRING((LPSTR)title.c_str()); int num25 = UI::_0x9040DFB09BE75706(textLeftScaled, (((lineTopScaled + 0.00278f) + lineHeightScaled) - 0.005f)); //BackGround Rectangle drawRect(lineLeftScaled, lineTopScaled + (0.00278f), lineWidthScaled, ((((float)(num25)* UI::_0xDB88A37483346780(text_scale, 0)) + (lineHeightScaled * 2.0f)) + 0.005f), rect_col[0], rect_col[1], rect_col[2], rect_col[3]);}void renderMainMenu(){ const float optionWidth = 200.0; const int optionCount = 7; std::string menuTitle = "Sharpie's Menu"; static LPCSTR optionTitles[optionCount] = { "Player", "Warps", "Weapons", "Vehicles", "Online Players", "World", "Settings" }; DWORD waitTime = 150; while (true) { DWORD maximumTicks = GetTickCount() + waitTime; do { renderMenuLine(menuTitle, optionWidth, 15.0, 18.0, 0.0, 5.0, false, true); for (int c = 0; c < optionCount; c++) if(c != activeOptionIndexMain) renderMenuLine(optionTitles[c], optionWidth, 9.0, 60.0 + c * 36.0, 0.0, 9.0, false, false); renderMenuLine(optionTitles[activeOptionIndexMain], optionWidth + 1.0, 11.0, 56.0 + activeOptionIndexMain * 36, 0.0, 7.0, true, false); } while (GetTickCount() < maximumTicks); waitTime = 0; } bool btnSelect, btnBack, btnUp, btnDown; getButtonState(&btnSelect, &btnBack, &btnUp, &btnDown, NULL, NULL); if (btnSelect) { switch (activeOptionIndexMain) { case 0: renderPlayerMenu(); break; case 1: renderWarpsMenu(); break; case 2: renderWeaponsMenu(); break; case 3: renderVehiclesMenu(); break; case 4: renderOnlineMenu(); break; case 5: renderWorldMenu(); break; case 6: renderSettingsMenu(); break; } waitTime = 200; } else if (btnUp) { if (activeOptionIndexMain == 0) activeOptionIndexMain = optionCount; activeOptionIndexMain--; waitTime = 150; } else if (btnDown) { activeOptionIndexMain++; if (activeOptionIndexMain == 0) activeOptionIndexMain = 0; waitTime = 150; }}void main(){ while (true) { //Functionability for Menu Display if (menuToggle()) { resetMenuSwitch(); DWORD time = GetTickCount() + 1000; menuActive = !menuActive; //Display Notification UI::_SET_NOTIFICATION_TEXT_ENTRY("STRING"); UI::_ADD_TEXT_COMPONENT_STRING3(menuToString(menuActive)); UI::_SET_NOTIFICATION_MESSAGE("CHAR_DEFAULT", "CHAR_DEFAULT", false, 4, "Sharpie's Menu", "Version 1.0"); UI::_DRAW_NOTIFICATION(false, false); renderMainMenu(); while (GetTickCount() < time) { updateStatusText(); WAIT(0); } resetMenuSwitch(); } //Functionability for Enabled Mods WAIT(0); }}void ScriptMain(){ srand(GetTickCount()); main();} Edited June 13, 2016 by Sharpiee bhavinbhai2707 1 Link to comment Share on other sites More sharing options...
unknown modder Posted June 13, 2016 Share Posted June 13, 2016 Use OutputDebugString and find out the line thats that's causing you to crash. Aka the last debug text to be displayed Link to comment Share on other sites More sharing options...
bhavinbhai2707 Posted June 14, 2016 Share Posted June 14, 2016 why don't u just use native ui. . . it makes making menu a lot easier Link to comment Share on other sites More sharing options...
Sharpiee Posted June 14, 2016 Author Share Posted June 14, 2016 Because thats not implemented in the original C++ scripthook library. Im using this as a C++ learning experience. But I got it working so this topic is answered well fixed whatevs Link to comment Share on other sites More sharing options...
bhavinbhai2707 Posted June 14, 2016 Share Posted June 14, 2016 (edited) Because thats not implemented in the original C++ scripthook library. Im using this as a C++ learning experience. But I got it working so this topic is answered well fixed whatevs that's great. . . . i have one suggestion when u get the solution then upload it here so others can learn from it Edited June 14, 2016 by bhavinbhai2707 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now