Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. Red Dead Redemption 2

      1. PC
      2. Gameplay
      3. Missions
      4. Help & Support
    2. Red Dead Online

      1. Gameplay
      2. Find Lobbies & Outlaws
      3. Help & Support
      4. Frontier Pursuits
    1. Crews & Posses

      1. Recruitment
    2. Events

    1. GTA Online

      1. Diamond Casino & Resort
      2. DLC
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Grand Theft Auto Series

    3. GTA 6

    4. GTA V

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

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

    7. GTA Vice City Stories

    8. GTA Liberty City Stories

    9. GTA San Andreas

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

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

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

      1. GTA Advance
      2. GTA 2
      3. GTA
    13. 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. 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. News

    2. Forum Support

    3. Site Suggestions

Sign in to follow this  
MrRobinson

If already ran, don't allow to run again.

Recommended Posts

MrRobinson
Alright so this is pretty basic stuff, I know the logic to it, but I don't know how to get it to work.


What I want to do is let the person select an option in the function and then the code registers the choice, but if the person tries to go back to that option and rechoose it doesn't let them.


Could someone help me? Heres the function (If you need the full code I can PM you it)





void process_manager_menu()
{
const float lineWidth = 250.0;
const int lineCount = 3;

std::string caption = "MANAGER TYPE";

static struct {
LPCSTR text;
bool *pState;
bool *pUpdated;
} lines[lineCount] = {
{"BANK MANAGER", NULL, NULL},
{"CLUB MANAGER", NULL, NULL},
{"SHOP MANAGER", NULL, NULL},
};

DWORD waitTime = 150;
while (true)
{
// timed menu draw, used for pause after active line switch
DWORD maxTickCount = GetTickCount() + waitTime;
do
{
// draw menu
draw_menu_line(caption, lineWidth, 15.0, 18.0, 0.0, 5.0, false, true);
for (int i = 0; i < lineCount; i++)
if (i != activeLineIndexPlayer)
draw_menu_line(line_as_str(lines[i].text, lines[i].pState),
lineWidth, 9.0, 60.0 + i * 36.0, 0.0, 9.0, false, false);
draw_menu_line(line_as_str(lines[activeLineIndexPlayer].text, lines[activeLineIndexPlayer].pState),
lineWidth + 1.0, 11.0, 56.0 + activeLineIndexPlayer * 36.0, 0.0, 7.0, true, false);

update_features();
WAIT(0);
} while (GetTickCount() < maxTickCount);
waitTime = 0;

// process buttons
bool bSelect, bBack, bUp, bDown;
get_button_state(&bSelect, &bBack, &bUp, &bDown, NULL, NULL);
if (bSelect)
{

// common variables
BOOL bPlayerExists = ENTITY::DOES_ENTITY_EXIST(PLAYER::PLAYER_PED_ID());
Player player = PLAYER::PLAYER_ID();
Ped playerPed = PLAYER::PLAYER_PED_ID();

switch (activeLineIndexPlayer)
{
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
default:
if (lines[activeLineIndexPlayer].pState)
*lines[activeLineIndexPlayer].pState = !(*lines[activeLineIndexPlayer].pState);
if (lines[activeLineIndexPlayer].pUpdated)
*lines[activeLineIndexPlayer].pUpdated = true;
}
waitTime = 200;
} else
if (bBack || trainer_switch_pressed())
{
break;
} else
if (bUp)
{
if (activeLineIndexPlayer == 0)
activeLineIndexPlayer = lineCount;
activeLineIndexPlayer--;
waitTime = 150;
} else
if (bDown)
{
activeLineIndexPlayer++;
if (activeLineIndexPlayer == lineCount)
activeLineIndexPlayer = 0;
waitTime = 150;
}
}
}




Share this post


Link to post
Share on other sites
c39687

use a bool to flag when the user has selected the option and use this flag to block code from selecting it again... this is example code to show the idea, you need to determine how to apply to your own code...

bool optionSelected = false;... if (UserSelectedOption()){    if (!optionSelected)    {        optionSelected = true;        Msg("Option Selected!");    }    else    {        Msg("Sorry, you already selected this!");    }}

make sense?

Edited by c39687

Share this post


Link to post
Share on other sites
c39687

i'll take that as a no lol

Share this post


Link to post
Share on other sites
MrRobinson

i'll take that as a no lol

Sorry been watching a film, Urm Ill try this tomorrow thanks for helping, and yes this does make sense

Share this post


Link to post
Share on other sites
c39687

oh ok cool

Share this post


Link to post
Share on other sites
MrRobinson

oh ok cool

Alright, I put it in my own code, I've been trying for about 3 hours now surfing the web and I can't find anything to help me.

if (UserSelectedOption())				{

That is giving me problems, I have defined it, I have tried setting it to if the player presses the select option it triggers UserSelectedOption but nothing, I have a feeling it has something to do with a string but I can't seem to get round it.

 

Could you help me?

Share this post


Link to post
Share on other sites
c39687

 

oh ok cool

Alright, I put it in my own code, I've been trying for about 3 hours now surfing the web and I can't find anything to help me.

if (UserSelectedOption())				{

That is giving me problems, I have defined it, I have tried setting it to if the player presses the select option it triggers UserSelectedOption but nothing, I have a feeling it has something to do with a string but I can't seem to get round it.

 

Could you help me?

 

 

The code you posted above is already handling the UserSelected part for you, just block the code inside the switch statement... like this...

 

 

switch (activeLineIndexPlayer){    case 0:        if (!case0Selected)        {            case0Selected = true;            //do code for selecting this menu item for the first time        }        else        {            //do code for this menu item already selected        }        break;}
Edited by c39687

Share this post


Link to post
Share on other sites
MrRobinson

 

 

oh ok cool

Alright, I put it in my own code, I've been trying for about 3 hours now surfing the web and I can't find anything to help me.

if (UserSelectedOption())				{

That is giving me problems, I have defined it, I have tried setting it to if the player presses the select option it triggers UserSelectedOption but nothing, I have a feeling it has something to do with a string but I can't seem to get round it.

 

Could you help me?

 

yeah sure, first tell me how a user selects an option, by keypress?? Also, let me see how you defined this method and I can make a suggestion.

 

You open the menu by pressing F5 you select by pressing NUMPAD 5

 

I had defined it before with just

int UserSelectedOption;

but its not having a define error anymore it gives me the error

 

 

expression preceding parentheses of apparent call must have (pointer-to-) function type

 

I think its got something to do with the

bool optionSelected = false;

but heres the hole menu selection

int activeLineIndexManagerMenu = 0;bool optionSelected = false;void process_manager_menu(){	const float lineWidth = 250.0;	const int lineCount = 2;		std::string caption = "MANAGER TYPE";	static struct {		LPCSTR		text;		bool		*pState;		bool		*pUpdated;	} lines[lineCount] = {		{"BANK MANAGER", NULL, NULL},		{"CLUB MANAGER", NULL, NULL}	};	DWORD waitTime = 150;	while (true)	{		// timed menu draw, used for pause after active line switch		DWORD maxTickCount = GetTickCount() + waitTime;		do 		{			// draw menu			draw_menu_line(caption, lineWidth, 15.0, 18.0, 0.0, 5.0, false, true);			for (int i = 0; i < lineCount; i++)				if (i != activeLineIndexManagerMenu)					draw_menu_line(line_as_str(lines[i].text, lines[i].pState), 								   lineWidth, 9.0, 60.0 + i * 36.0, 0.0, 9.0, false, false);			draw_menu_line(line_as_str(lines[activeLineIndexManagerMenu].text, lines[activeLineIndexManagerMenu].pState), 						   lineWidth + 1.0, 11.0, 56.0 + activeLineIndexManagerMenu * 36.0, 0.0, 7.0, true, false);			update_features();			WAIT(0);		} while (GetTickCount() < maxTickCount);		waitTime = 0;		// process buttons		bool bSelect, bBack, bUp, bDown;		get_button_state(&bSelect, &bBack, &bUp, &bDown, NULL, NULL);		if (bSelect)		{			// common variables			BOOL bPlayerExists = ENTITY::DOES_ENTITY_EXIST(PLAYER::PLAYER_PED_ID());			Player player = PLAYER::PLAYER_ID();			Ped playerPed = PLAYER::PLAYER_PED_ID();			switch (activeLineIndexManagerMenu)			{			case 0:			{				int UserSelectedOption = true;				PLAYER::START_PLAYER_TELEPORT(playerPed, 257.055f, 221.135f, 106.286f, 180, 1, 1, 1);				set_status_text("Welcome to your new job, At random points in the day you will be given tasks, comeplete them to earn a bonus check.");				if (UserSelectedOption())				{					if (!optionSelected)					{						optionSelected = true;						set_status_text("Option Selected!");					}					else					{						set_status_text("Sorry, you already selected this!");					}				}				process_bank_menu();			}					break;				case 1:				{					PLAYER::START_PLAYER_TELEPORT(playerPed, 126.135f, -1278.583f, 29.270f, 180, 1, 1, 1);					set_status_text("Welcome to your new job, At random points in the day you will be given tasks, comeplete them to earn a bonus check.");					if (UserSelectedOption())					{						if (!optionSelected)						{							optionSelected = true;							set_status_text("Option Selected!");						}						else						{							set_status_text("Sorry, you already selected this!");						}					}					process_club_menu();				}					break;				default:					if (lines[activeLineIndexManagerMenu].pState)						*lines[activeLineIndexManagerMenu].pState = !(*lines[activeLineIndexManagerMenu].pState);					if (lines[activeLineIndexManagerMenu].pUpdated)						*lines[activeLineIndexManagerMenu].pUpdated = true;								}			waitTime = 200;		} else		if (bBack || trainer_switch_pressed())		{			break;		} else		if (bUp)		{			if (activeLineIndexManagerMenu == 0) 				activeLineIndexManagerMenu = lineCount;			activeLineIndexManagerMenu--;			waitTime = 150;		} else		if (bDown)		{			activeLineIndexManagerMenu++;			if (activeLineIndexManagerMenu == lineCount) 				activeLineIndexManagerMenu = 0;						waitTime = 150;		}	}}

Share this post


Link to post
Share on other sites
c39687

oh hey i edited my response because i noticed it in the code after i typed that... look at my previous post

Share this post


Link to post
Share on other sites
MrRobinson

oh hey i edited my response because i noticed it in the code after i typed that... look at my previous post

Ah thanks :D I'll try this later, I'm teaching someone LUA over TeamViewer :D

Share this post


Link to post
Share on other sites
c39687

sure no problem ;)

Share this post


Link to post
Share on other sites
MrRobinson

sure no problem ;)

Hey I just tested it then and it doesn't work, so what its doing is its skipping straight to the already selected its not doing anything for the first time it's selected

                        BOOL bPlayerExists = ENTITY::DOES_ENTITY_EXIST(PLAYER::PLAYER_PED_ID());			Player player = PLAYER::PLAYER_ID();			Ped playerPed = PLAYER::PLAYER_PED_ID();			int case0Selected;			switch (activeLineIndexManagerMenu)			{			case 0:			{				if (!case0Selected)				{					case0Selected = true;					PLAYER::START_PLAYER_TELEPORT(playerPed, 257.055f, 221.135f, 106.286f, 180, 1, 1, 1);					set_status_text("Welcome to your new job, At random points in the day you will be given tasks, comeplete them to earn a bonus check.");				}				else				{					set_status_text("Sorry, you will have to sell this business and buy a new one, or buy another.");				}				break;
Edited by MrRobinson

Share this post


Link to post
Share on other sites
Fireboyd78

Dude, c3 is trying to teach you the basics of how to do this. He is posting pseudo-code to demonstrate code logic. You aren't supposed to copy and paste it.

 

If you can't figure out how to implement it on your own without having someone hold your hand, maybe you should learn how to program?

Share this post


Link to post
Share on other sites
MrRobinson

Dude, c3 is trying to teach you the basics of how to do this. He is posting pseudo-code to demonstrate code logic. You aren't supposed to copy and paste it.

 

If you can't figure out how to implement it on your own without having someone hold your hand, maybe you should learn how to program?

Thats not pseudo code, I am doing a course on Python and Pseudo code. I admit I am not the best a C++ but everyone has to learn, I know he is giving me guidance and then I have to implement it, thats what I am trying to do, if it doesn't work, I ask him why its not working. If you ain't going to help dont post mate.

Share this post


Link to post
Share on other sites
Fireboyd78

Pseudo-code is not limited to Python. And I'm a programmer myself, why else would I be posting here?

 

You don't understand basic code logic. What you're asking for help with is probably one of the easiest things you could do in programming, and instead of trying to implement it into your own code (regardless of programming language), you're copy and pasting someone else's code!

 

Stay in school, kid.

Share this post


Link to post
Share on other sites
c39687

 

Dude, c3 is trying to teach you the basics of how to do this. He is posting pseudo-code to demonstrate code logic. You aren't supposed to copy and paste it.

 

If you can't figure out how to implement it on your own without having someone hold your hand, maybe you should learn how to program?

Thats not pseudo code, I am doing a course on Python and Pseudo code. I admit I am not the best a C++ but everyone has to learn, I know he is giving me guidance and then I have to implement it, thats what I am trying to do, if it doesn't work, I ask him why its not working. If you ain't going to help dont post mate.

 

he just means i am making up code to demonstrate an idea. Yeah the problem is you don't fully understand what the code your editing is actually doing. By the time this code gets to the switch statement, the script has already determined a menu option was selected by the user. So all you have to do is handle each menu selection in the switch statement. You simply use a bool to flag your script how to act. Make a bool for every menu option or whatever you want to use as flags. Try to write a script from the beginning instead of editing Alex's code. By all means use his code as an example but you should write it from the beginning to understand what every line of code does. You are new to programming and jumping into the middle of some complex code you didn't write will not be easy for you to edit. Try to write it on your own and then what I'm telling you will make a lot more sense.

Edited by c39687

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

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