OnDialogResponse
#1

Yo, i just tryed to add a Spawn Vehicle dialog
At the start i registed and got my money for registrering, then i spawned a car, but when i spawned the car i got the register cash again
Then i tryed to relog and see if it was only when i registed, but when i tryed to login it said WRONG PASSWORD
I know i have done something wrong between Register and Vehicle dialog, tell me how i can fix it please

Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch( dialogid )
    {
        case DIALOG_REGISTER:
        {
            if (!response) return Kick(playerid);
            if(response)
            {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
		GivePlayerMoney(playerid, 100000);
		new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"data");
                INI_WriteInt(File,"Password",udb_hash(inputtext));
                INI_WriteInt(File,"Cash",0);
                INI_WriteInt(File,"Admin",0);
                INI_WriteInt(File,"Kills",0);
                INI_WriteInt(File,"Deaths",0);
                INI_Close(File);
			}
        }

        case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_RED"You have entered an incorrect password.\n"COL_WHITE"Type your password below to login.","Login","Quit");
                }
                return 1;
            }
        }
    }
    
	new Float:x,Float:y,Float:z;
	if(dialogid==1 && response==1)
{
 switch(listitem)
 {
  case 0:
  {
   GetPlayerPos(playerid,x,y,z);
   CreateVehicle(432,x-3.0,y,z,0.0,1,1,300);
  }
  case 1:
  {
   GetPlayerPos(playerid,x,y,z);
   CreateVehicle(407,x-3.0,y,z,0.0,1,3,300);
  }
  case 2:
  {
   GetPlayerPos(playerid,x,y,z);
   CreateVehicle(411,x-3.0,y,z,0.0,1,0,300);
  }
  case 3:
  {
   GetPlayerPos(playerid,x,y,z);
   CreateVehicle(451,x-3.0,y,z,0.0,0,1,300);
  }
  case 4:
  {
   GetPlayerPos(playerid,x,y,z);
   CreateVehicle(406,x-3.0,y,z,0.0,1,1,300);
  }
 }
}
    return 1;
}
I know i need something between them but i dunno what
Reply
#2

pawn Код:
switch(dialogid)
{
    case DIALOG_REGISTER:
    {
        // Script here...
    }
    case DIALOG_LOGIN:
    {
        // Script here
    }
    case 1: // This is the same as if(dialogid == 1)
    {
        // Script here
    }
}
Reply
#3

Can you do it for me? -.- I just do it wrong.. alot errors etc..
and make "case 1:" to "case DIALOG_VEHICLE:" please if you do
Reply
#4

Now your'e on your own.

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch( dialogid )
    {
        case DIALOG_REGISTER:
        {
            if(!response) return Kick(playerid);
            if(response)
            {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
                GivePlayerMoney(playerid, 100000);
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"data");
                INI_WriteInt(File,"Password",udb_hash(inputtext));
                INI_WriteInt(File,"Cash",0);
                INI_WriteInt(File,"Admin",0);
                INI_WriteInt(File,"Kills",0);
                INI_WriteInt(File,"Deaths",0);
                INI_Close(File);
            }
        }

        case DIALOG_LOGIN:
        {
            if( !response ) return Kick ( playerid );
            if( response )
            {
                if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_RED"You have entered an incorrect password.\n"COL_WHITE"Type your password below to login.","Login","Quit");
                }
                return 1;
            }
        }

        new Float:x,Float:y,Float:z;
        case DIALOG_VEHICLE:
        {
            if(response)
            {
                switch(listitem)
                {
                    case 0: // The first selection (vehicle)
                    {
                    }
                    case 1: // The second selection (vehicle)
                    {
                    }
                    // .....
                }
            }
            if(!response)
            {
            }
        }
    }
    return 1;
}
EDIT: When you show the vehicle dialog it has to be like this:

pawn Код:
ShowPlayerDialog(playerid, DIALOG_VEHICLE, ..........); // not 1, but DIALOG_VEHICLE
Reply
#5

looks better, now its only error on the first 2 lines..
Код:
(621)        new Float:x,Float:y,Float:z;
(622)        case DIALOG_VEHICLE:
Код:
F:\Servers\SAMP\gamemodes\Esco.pwn(621) : error 002: only a single statement (or expression) can follow each "case"
F:\Servers\SAMP\gamemodes\Esco.pwn(621) : warning 221: label name "Float" shadows tag name
F:\Servers\SAMP\gamemodes\Esco.pwn(621) : error 017: undefined symbol "x"
F:\Servers\SAMP\gamemodes\Esco.pwn(621) : warning 215: expression has no effect
F:\Servers\SAMP\gamemodes\Esco.pwn(622) : error 014: invalid statement; not in switch
F:\Servers\SAMP\gamemodes\Esco.pwn(622) : warning 215: expression has no effect
F:\Servers\SAMP\gamemodes\Esco.pwn(622) : error 001: expected token: ";", but found ":"
F:\Servers\SAMP\gamemodes\Esco.pwn(622) : error 029: invalid expression, assumed zero
F:\Servers\SAMP\gamemodes\Esco.pwn(622) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


6 Errors.
Reply
#6

do not create 'new' in a switch
Reply
#7

Quote:
Originally Posted by EvgeN 1137
Посмотреть сообщение
do not create 'new' in a switch
Код:
        case DIALOG_VEHICLE:
        {
            new Float:x,Float:y,Float:z;
            if(response)
I saw that was weird
I think this code works then right?
Reply
#8

It seems that switch doesn't let to script a lot in cases. Use

pawn Код:
if(listitem == 0)
{
}
instead of

pawn Код:
switch(listitem)
{
    case 0:
    {
    }
    case 1:
    {
    }
}

It should work.
Reply
#9

uhm, i dident understand that...
But this works now:
pawn Код:
//OnPlayerCommandText
    if(strcmp(cmdtext,"/veh",true)==0)
{
    ShowPlayerDialog(playerid, DIALOG_VEHICLE, DIALOG_STYLE_LIST, "Vehicles","Infernus\nTurismo\nSultan\nMonster Truck\nSavanna\nNRG","Spawn","Exit");
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch( dialogid )
    {
        case DIALOG_REGISTER:
        {
            if (!response) return Kick(playerid);
            if(response)
            {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
                GivePlayerMoney(playerid, 100000);
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"data");
                INI_WriteInt(File,"Password",udb_hash(inputtext));
                INI_WriteInt(File,"Cash",0);
                INI_WriteInt(File,"Admin",0);
                INI_WriteInt(File,"Kills",0);
                INI_WriteInt(File,"Deaths",0);
                INI_Close(File);
            }
        }

        case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_RED"You have entered an incorrect password.\n"COL_WHITE"Type your password below to login.","Login","Quit");
                }
                return 1;
            }
        }

        case DIALOG_VEHICLE:
        {
            new Float:x,Float:y,Float:z;
            if(response)
            {
                switch(listitem)
                {
                    case 0:
                    {
                        GetPlayerPos(playerid,x,y,z);
                        CreateVehicle(411,x-3.0,y,z,0.0,1,1,300);
                    }
                    case 1:
                    {
                        GetPlayerPos(playerid,x,y,z);
                        CreateVehicle(451,x-3.0,y,z,0.0,1,3,300);
                    }
                    case 2:
                    {
                        GetPlayerPos(playerid,x,y,z);
                        CreateVehicle(560,x-3.0,y,z,0.0,1,0,300);
                    }
                    case 3:
                    {
                        GetPlayerPos(playerid,x,y,z);
                        CreateVehicle(557,x-3.0,y,z,0.0,0,1,300);
                    }
                    case 4:
                    {
                        GetPlayerPos(playerid,x,y,z);
                        CreateVehicle(567,x-3.0,y,z,0.0,1,1,300);
                    }
                    case 5:
                    {
                        GetPlayerPos(playerid,x,y,z);
                        CreateVehicle(522,x-3.0,y,z,0.0,1,1,300);
                    }
                }
            }
            if(!response)
            {
            }
        }
       
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)