Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!   (85,461 visits to this link)

    2. News

    1. GTA Online

      1. Find Lobbies & Players
      2. Guides & Strategies
      3. Vehicles
      4. Content Creator
      5. Help & Support
    2. Crews

      1. Events
      2. Recruitment
    1. Grand Theft Auto Series

    2. GTA Next

    3. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    4. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA Mods
    5. GTA Chinatown Wars

    6. GTA Vice City Stories

    7. GTA Liberty City Stories

    8. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    9. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    10. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    11. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    12. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    3. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption 2

    2. Red Dead Redemption

    3. Rockstar Games

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Forum Support

    2. Site Suggestions

Sign in to follow this  
Zolika1351

ScriptHook menu VERY slow

Recommended Posts

Zolika1351

I've been making a menu, and it seems to be VERY, VERY slow at recognizing keypresses, and I have to hold down the next option key for at least a second before it actually does anything.

A bit of my menu code:

void Updatemenu(){	if (menu1 == 3)	{		menu1 = 0;	}	if (menu1 == -1)	{		menu1 = 2;	}	//Wait(1);	if (menu1 == 0)	{		//print("Action: Teleport To");		TEXT_DRAW(0.3, 0.3, 255, 255, 255, 255);		DisplayTextWithLiteralString((pos_x + 0.1500), (pos_y), "STRING", "Teleports");		TEXT_DRAW(0.3, 0.3, 127, 127, 127, 255);		DisplayTextWithLiteralString((pos_x + 0.1500), (pos_y + 0.032), "STRING", "Spawn");		TEXT_DRAW(0.3, 0.3, 127, 127, 127, 255);		DisplayTextWithLiteralString((pos_x + 0.1500), (pos_y + 0.032 + 0.032), "STRING", "Car Options");		if (SubMenuNumber == 1)		{			if (menu2 == 0)			{				TEXT_DRAW(0.3, 0.3, 255, 255, 255, 255);				DisplayTextWithLiteralString((pos_x + 0.3000), (pos_y), "STRING", "Player Teleports");				TEXT_DRAW(0.3, 0.3, 127, 127, 127, 255);				DisplayTextWithLiteralString((pos_x + 0.3000), (pos_y + 0.032), "STRING", "World Teleports");			}			if (menu2 == 1)			{				TEXT_DRAW(0.3, 0.3, 127, 127, 127, 255);				DisplayTextWithLiteralString((pos_x + 0.3000), (pos_y), "STRING", "Player Teleports");				TEXT_DRAW(0.3, 0.3, 255, 255, 255, 255);				DisplayTextWithLiteralString((pos_x + 0.3000), (pos_y + 0.032), "STRING", "World Teleports");			}			if (menu2 == 2)			{				menu2 = 0;			}			if (menu2 == -1)			{				menu2 = 1;			}		}		if (SubMenuNumber == 2)		{			if (menu2 == 0)			{				TEXT_DRAW(0.3, 0.3, 255, 255, 255, 255);				DisplayTextWithLiteralString((pos_x + 0.3000), (pos_y), "STRING", "Player Teleports");				TEXT_DRAW(0.3, 0.3, 127, 127, 127, 255);				DisplayTextWithLiteralString((pos_x + 0.3000), (pos_y + 0.032), "STRING", "World Teleports");				if (submenumode == 0)				{					TEXT_DRAW(0.3, 0.3, 255, 255, 255, 255);					DisplayTextWithLiteralString((pos_x + 0.4500), (pos_y), "STRING", "To Player");					TEXT_DRAW(0.3, 0.3, 127, 127, 127, 255);					DisplayTextWithLiteralString((pos_x + 0.4500), (pos_y + 0.032), "STRING", "Into Car");					mode = 0;				}				if (submenumode == 1)				{					TEXT_DRAW(0.3, 0.3, 127, 127, 127, 255);					DisplayTextWithLiteralString((pos_x + 0.4500), (pos_y), "STRING", "To Player");					TEXT_DRAW(0.3, 0.3, 255, 255, 255, 255);					DisplayTextWithLiteralString((pos_x + 0.4500), (pos_y + 0.032), "STRING", "Into Car");					mode = 1;				}				if (submenumode == 2)				{					submenumode = 0;				}				if (submenumode == -1)				{					submenumode = 1;				}			}			if (menu2 == 1)			{				TEXT_DRAW(0.3, 0.3, 127, 127, 127, 255);				DisplayTextWithLiteralString((pos_x + 0.3000), (pos_y), "STRING", "Player Teleports");				TEXT_DRAW(0.3, 0.3, 255, 255, 255, 255);				DisplayTextWithLiteralString((pos_x + 0.3000), (pos_y + 0.032), "STRING", "World Teleports");			}			if (menu2 == 2)			{				menu2 = 0;			}			if (menu2 == -1)			{				menu2 = 1;			}		}	}

Execution code:

// The real scriptvoid CustomFiberThread::ExecuteOption(){			if (mode == 0) // Teleport To			{				Ped hisplayermodel;				f32 hisX;				f32 hisY;				f32 hisZ;				GetPlayerChar(i, &hisplayermodel);				GetCharCoordinates(hisplayermodel, &hisX, &hisY, &hisZ); 				SetCharCoordinates(GetPlayerPed(), hisX, hisY, hisZ);			}			if (mode == 1) // Teleport Into Car			{				int seats;				Ped hisplayermodel;				Vehicle hiscar;				f32 hisX;				f32 hisY;				f32 hisZ;				Ped driver;				GetPlayerChar(i, &hisplayermodel);				if(IsCharInAnyCar(hisplayermodel))				{					GetCarCharIsUsing(hisplayermodel, &hiscar);					GetDriverOfCar(hiscar, &driver);					if(!DoesCharExist(driver)) WarpCharIntoCar(GetPlayerPed(),hiscar);					else for(seats = 0;seats <= 2;seats++)if(IsCarPassengerSeatFree(hiscar, seats)) WarpCharIntoCarAsPassenger(GetPlayerPed(),hiscar,seats);				}			}

Keypress code:

	while(IsThreadAlive())	{				if ((GetAsyncKeyState(VK_F7) & 1) != 0)		{			if(MenuYey)			{				MenuYey = false;			}			else if(!MenuYey)			{				MenuYey = true;			}		}		// Call Wait() so we can process other scripts/game code		// You must call Wait(...) in your loop code for a fiber thread!		if(MenuYey)		{			if ((GetAsyncKeyState(VK_NUMPAD2) & 1) != 0)			{				LogInfo("NUM 2 Pressed");				if(SubMenuNumber == 0)				{					menu1++;				}				else if(SubMenuNumber == 1)				{					menu2++;				}				else if(SubMenuNumber == 2)				{					submenumode++;				}				Updatemenu();			}			if ((GetAsyncKeyState(VK_NUMPAD8) & 1) != 0)			{				LogInfo("NUM 8 Pressed");				if(SubMenuNumber == 0)				{					menu1--;					Updatemenu();				}				else if(SubMenuNumber == 1)				{					menu2--;					Updatemenu();				}				else if(SubMenuNumber == 2)				{					submenumode--;					Updatemenu();				}				Updatemenu();			}			if ((GetAsyncKeyState(VK_NUMPAD5) & 1) != 0)			{				LogInfo("NUM 5 Pressed");				if(SubMenuNumber == 0)				{					SubMenuNumber = 1;				}				else if(SubMenuNumber == 1)				{					SubMenuNumber = 2;				}				else if(SubMenuNumber == 2)				{					ExecuteOption();				}			}			if ((GetAsyncKeyState(VK_NUMPAD0) & 1) != 0)			{				LogInfo("NUM 0 Pressed");				if(SubMenuNumber == 1)				{					SubMenuNumber = 0;				}				else if(SubMenuNumber == 2)				{					SubMenuNumber = 1;				}			}			if ((GetAsyncKeyState(VK_NUMPAD4) & 1) != 0)			{				LogInfo("NUM 4 Pressed");				i--;				UpdateISub();			}			if ((GetAsyncKeyState(VK_NUMPAD6) & 1) != 0)			{				LogInfo("NUM 6 Pressed");				i++;				UpdateIAdd();			}			if(IsNetworkSession())			{				NativeInvoke::Invoke<ScriptVoid>("GET_PLAYER_RGB_COLOUR", i, &gr, &gg, &gb);				TEXT_DRAW(0.3, 0.3, gr, gg, gb, 255);				DisplayTextWithLiteralString((pos_x), pos_y, "STRING", GetPlayerName(i));				if(NativeInvoke::Invoke<ScriptAny>("GET_HOST_ID") == i)				{					TEXT_DRAW(0.3, 0.3, gr, gg, gb, 255);					DisplayTextWithLiteralString((pos_x), (pos_y - 0.032), "STRING", "HOST");				}				if(NativeInvoke::Invoke<ScriptAny>("GET_HOST_ID") == GetPlayerId())				{					NativeInvoke::Invoke<ScriptVoid>("GET_PLAYER_RGB_COLOUR", GetPlayerId(), &gr, &gg, &gb);					TEXT_DRAW(0.3, 0.3, gr, gg, gb, 255);					DisplayTextWithLiteralString((pos_x), (pos_y + 0.032), "STRING", "YOU ARE HOST");				}			}			else			{				if(GetCurrentEpisode() == 0)				{					TEXT_DRAW(0.3, 0.3, 255, 255, 255, 255);					DisplayTextWithLiteralString((pos_x), pos_y, "STRING", "Niko Bellic");				}				if(GetCurrentEpisode() == 1)				{					TEXT_DRAW(0.3, 0.3, 255, 255, 255, 255);					DisplayTextWithLiteralString((pos_x), pos_y, "STRING", "Johnny Klebitz");				}				if(GetCurrentEpisode() == 2)				{					TEXT_DRAW(0.3, 0.3, 255, 255, 255, 255);					DisplayTextWithLiteralString((pos_x), pos_y, "STRING", "Luis Lopez");				}			}			Updatemenu();		}		else if ((GetAsyncKeyState(VK_NUMPAD4) & 1) != 0)		{			LogInfo("num4 Pressed");		}		else if ((GetAsyncKeyState(VK_NUMPAD6) & 1) != 0)		{			LogInfo("num6 Pressed");		}		else if ((GetAsyncKeyState(VK_NUMPAD5) & 1) != 0)		{			LogInfo("num5 Pressed");		}		else if ((GetAsyncKeyState(VK_NUMPAD8) & 1) != 0)		{			LogInfo("num8 Pressed");		}		else if ((GetAsyncKeyState(VK_NUMPAD2) & 1) != 0)		{			LogInfo("num2 Pressed");		}		Wait(0);	}

I know that the code itself is VERY unoptimized, but I have no idea how to optimize it. Any ideas? Selecting options/submenus seems to be instantaneous, but scrolling and going backwards is the slow part.

Edited by Zolika1351

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.