Jump to content

[NEED HELP] Fix Dialog problem


sina alex

Recommended Posts

there i have test a FS to make an interior list with dialog style listitem every thing worked correctly but one part of FS will switch and changed with the main game mode code

FS code work and dialogs showed to player

this part work correctly - cmd->inlist->      ShowPlayerDialog(playerid, D_IM, DIALOG_STYLE_LIST, "List Interior ha","Manazel", "Entekhab", "Khorooj");

this part work correctly - if dialog id = D_IMand select item 0 and response > ShowPlayerDialog(playerid, D_MANAZEL, DIALOG_STYLE_LIST, "List Interior ha","Emarat\nmamuli\nkuchik", "Entekhab", "Khorooj");

this part is problem!!! -  - if dialog id = D_MANAZEL and select item 0 and response > ShowPlayerDialog(playerid, D_MANEMARAT, DIALOG_STYLE_LIST, "List Interior ha","maddog", "Entekhab", "Khorooj"); "exit");

after player choose Emarat on D_MANAZEL dialog,then D_MANEMARAT must showed to player but it wont run and the login wrong password of main GM showed.!

there is enum and ondialog response of main GM:

enum
{
	DIALOG_UNUSED,
	DIALOG_LOGIN,
	DIALOG_REGISTER,
};
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	switch (dialogid)
	{
 // Useful for dialogs that contain only information and we do nothing depending on whether they responded or not
		case DIALOG_LOGIN:
		{
			if (!response) return Kick(playerid);
			new hashed_pass[65];
			SHA256_PassHash(inputtext, Player[playerid][Salt], hashed_pass, 65);
			if (strcmp(hashed_pass, Player[playerid][Password]) == 0)
			{
				//correct password, spawn the player
				ShowPlayerDialog(playerid, DIALOG_UNUSED, DIALOG_STYLE_MSGBOX, "Login", "You have been successfully logged in.", "Okay", "");
				KillTimer(Player[playerid][LoginTimer]);
				Player[playerid][LoginTimer] = 0;
				Player[playerid][IsLoggedIn] = true;
				// spawn the player to their last saved position after login
				SetSpawnInfo(playerid, NO_TEAM, 0, Player[playerid][X_Pos], Player[playerid][Y_Pos], Player[playerid][Z_Pos], Player[playerid][A_Pos], 0, 0, 0, 0, 0, 0);
				SpawnPlayer(playerid);
			}
			else
			{
				Player[playerid][LoginAttempts]++;
				if (Player[playerid][LoginAttempts] >= 3)
				{
					ShowPlayerDialog(playerid, DIALOG_UNUSED, DIALOG_STYLE_MSGBOX, "Login", "You have mistyped your password too often (3 times).", "Okay", "");
					DelayedKick(playerid);
				}
				else ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Wrong password!\nPlease enter your password in the field below:", "Login", "Abort");
			}
		}
		case DIALOG_REGISTER:
		{
			if (!response) return Kick(playerid);
			if (strlen(inputtext) <= 5) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Registration", "Your password must be longer than 5 characters!\nPlease enter your password in the field below:", "Register", "Abort");
			// 16 random characters from 33 to 126 (in ASCII) for the salt
			for (new i = 0; i < 16; i++) Player[playerid][Salt][i] = random(94) + 33;
			SHA256_PassHash(inputtext, Player[playerid][Salt], Player[playerid][Password], 65);
			// sends an INSERT query
			orm_save(Player[playerid][ORM_ID], "OnPlayerRegister", "d", playerid);
		}
		default: return 0; // dialog ID was not found, search in other scripts
	}
	return 1;
}

 

and there is my target FS code:

enum
{
D_IM,
D_MANAZEL,
D_MANEMARAT
};

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	switch (dialogid)
	{
	 case D_IM:
	 {
	  if(response)
	  {
       switch(listitem)
	   {
    	case 0 : ShowPlayerDialog(playerid, D_MANAZEL, DIALOG_STYLE_LIST, "List Interior ha","Emarat\nmamuli\nkuchik", "Entekhab", "Khorooj");
	   }
	  }
	 }
	 case D_MANAZEL:
	 {
	  if(response)
	  {
       switch(listitem)
	   {
    	case 0 : ShowPlayerDialog(playerid, D_MANEMARAT, DIALOG_STYLE_LIST, "List Interior ha","maddog", "Entekhab", "Khorooj");
	   }
	  }
	 }
	 case D_MANEMARAT:
	 {
	  if(response)
	  {
       switch(listitem)
	   {
    	case 0 : Playertptoint(playerid, 1267.663208, -781.323242, 1091.906250, 5);
	   }
	  }
	 }
	}
	return 0;
}

 

Edited by sina alex
Link to comment
Share on other sites

  • 2 months later...

Most probably is because IDs u are using for dialogs from your mode are same with those in your filterscript, because 'enum' is starting from 0 in both files.

I would recommend you to use a dialog processor like y_dialog (from YSI) or easyDialog, will improve your code readability because u will not create a thousand of branches in OnDialogResponse and not risking mix-up of IDs because those dialog handlers are working with public functions to execute the code for dialogs.

  • Like 1
Link to comment
Share on other sites

On 2/15/2023 at 10:30 PM, Sancky said:

Most probably is because IDs u are using for dialogs from your mode are same with those in your filterscript, because 'enum' is starting from 0 in both files.

I would recommend you to use a dialog processor like y_dialog (from YSI) or easyDialog, will improve your code readability because u will not create a thousand of branches in OnDialogResponse and not risking mix-up of IDs because those dialog handlers are working with public functions to execute the code for dialogs.

thank you for this important tip i will test 

Link to comment
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.

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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more details you can also review our Terms of Use and Privacy Policy.