OnDialogResponse responds to everything
#1

When i choose an item from the DIALOG_WEAPONS it writes text into the player.txt from DIALOG_REGISTER. Please help.

Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == DIALOG_REGISTER)
	{
	    if(response)
		{
		    new File:players=fopen("players.txt", io_append);
			fwrite(players,inputtext);
			fclose(players);
		}
		if(response==1)
		{
			SendClientMessage(playerid,0xFF0000FF," nu");
		}
	}
	if(dialogid == DIALOG_WEAPONS)
	{
		if(response)
	 	{
		 	if(listitem == 0)
		 	{
		 		if(money > 999)
				{
					GivePlayerMoney(playerid, -1000);
					GivePlayerWeapon(playerid,46, 1); //Parachute
					SendClientMessage(playerid, 0xFF0000FF, "You bought a parachute.");
				}
				else
				{
					SendClientMessage(playerid, 0xFF0000FF, "Insufficient funds.");
				}
			}
                       if(listitem == 1)
		       {
		 		if(money > 499)
		   		{
		     		GivePlayerMoney(playerid, -500);
		  			GivePlayerWeapon(playerid, 22, 120); //9mm
		  			SendClientMessage(playerid, 0xFF0000FF, "You bought a 9mm pistol.");
				}
				else
				{
		  			SendClientMessage(playerid, 0xFF0000FF, "Insufficient funds.");
			 	}
			}
                 }
        }
}
Reply
#2

It seems like under DIALOG_REGISTER you are trying to use OnDialogReponse as a variable, not a bool.

Proper usage to check for a response is:

pawn Код:
if(response == true) // can also use if(response)
OR

pawn Код:
if(response == false) // can also use if(!response)
It's also best to use a switch statement for the list items. So for example:

pawn Код:
case DIALOG_DEFINE:
        {
            if(response)
            {
                switch(listitem)
                {
                    case 0: // same effect as if(listitem == 0)
                    case 1: // same effect as if(listitem == 1)
                    case 2: // same effect as if(listitem == 2)
                    case 3: // same effect as if(listitem == 3)
                }
            }
        }
You can do the same with the dialog ID's, as well.
Reply
#3

The only problem I can see for that happening is you defined the two dialogs with the same ID.

Also note that
pawn Код:
if(response)
and
pawn Код:
if(response == 1)
equate to the same thing.
Reply
#4

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
It seems like under DIALOG_REGISTER you are trying to use OnDialogReponse as a variable, not a bool.

Proper usage to check for a response is:

pawn Код:
if(response == true) // can also use if(response)
OR

pawn Код:
if(response == false) // can also use if(!response)
It's also best to use a switch statement for the list items. So for example:

pawn Код:
case DIALOG_DEFINE:
        {
            if(response)
            {
                switch(listitem)
                {
                    case 0: // same effect as if(listitem == 0)
                    case 1: // same effect as if(listitem == 1)
                    case 2: // same effect as if(listitem == 2)
                    case 3: // same effect as if(listitem == 3)
                }
            }
        }
You can do the same with the dialog ID's, as well.
If i use if(response==true) or if(response==false),i get this:
pawn Код:
warning 213: tag mismatch
Thanks for the case stuff,its really easier
Reply
#5

pawn Код:
if(response == true);
Or

pawn Код:
if(response == false);
Copy one of them and no more warnings.
Reply
#6

Quote:
Originally Posted by SilverKiller
Посмотреть сообщение
pawn Код:
if(response == true);
Or

pawn Код:
if(response == false);
Copy one of them and no more warnings.
I copied, got this:

pawn Код:
C:\Users\Justas\Desktop\TestServer\gamemodes\test3.pwn(247) : warning 213: tag mismatch
C:\Users\Justas\Desktop\TestServer\gamemodes\test3.pwn(247) : error 036: empty statement
Reply
#7

Then use

pawn Код:
if(response)
If your code still not working, check your dialog ID , it may be mixed up with something else.
Reply
#8

Quote:
Originally Posted by SilverKiller
Посмотреть сообщение
Then use

pawn Код:
if(response)
If your code still not working, check your dialog ID , it may be mixed up with something else.
Then im back to my original problem, when i choose items from DIALOG_WEAPONS it writes to my file palyers.txt
Reply
#9

Show us your DIALOG_REGISTER And DIALOG_WEAPONS defines.
Reply
#10

EDIT: didn't noticed your post correctly, as mentioned, if (response) and if(response == 1) are same thing, so problem is there,or in your Dialog id. check your #define of those ids
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)