SA-MP Forums Archive
Dialog Help.. +rep - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Dialog Help.. +rep (/showthread.php?tid=480663)



Dialog Help.. +rep - Eliminator - 12.12.2013

PHP код:
public OnPlayerCommandText(playeridcmdtext[])
{
    if(!
strcmp(cmdtext"/weapons"true))
{
    
ShowPlayerDialog(playerid9923DIALOG_STYLE_LIST"Select Your Weapon""Desert Eagle ($4090)\nPistol ($3000)\nSawnof Shotgun ($6000)\nSniper Rifle ($8000)\nGrenade ($1000)""Purchase""Cancel");
    return 
1;
}
    return 
0;
}
public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
if(
response)// They pressed the first button.
    
{
    switch(
dialogid)// If you only have one dialog, then this isn't required, but it's neater for when you implement more dialogs.
        
{
        case 
9923:// Our dialog!
            
{
               switch(
listitem)// Checking which listitem was selected
            
{
                case 
0:// The first item listed
                
{
                    if(
GetPlayerMoney(playerid) < 4090) return SendClientMessage(playerid0xFFFFFF"You don't have enough cash.");
                    
GivePlayerMoney(playerid, -4090);
                    
GivePlayerWeapon(playerid,24);
                }
                case 
1// The second item listed
                
{
                    if(
GetPlayerMoney(playerid) < 3000) return SendClientMessage(playerid0xFFFFFF"You don't have enough cash.");
                    
GivePlayerMoney(playerid, -3000);
                    
GivePlayerWeapon(playerid,22);
                }
                case 
2// The third item listed
                
{
                    if(
GetPlayerMoney(playerid) < 6000) return SendClientMessage(playerid0xFFFFFF"You don't have enough cash.");
                    
GivePlayerMoney(playerid, -6000);
                    
GivePlayerWeapon(playerid,26);
                }
                case 
3// The 4th item listed
                
{
                    if(
GetPlayerMoney(playerid) < 8000) return SendClientMessage(playerid0xFFFFFF"You don't have enough cash.");
                    
GivePlayerMoney(playerid, -8000);
                    
GivePlayerWeapon(playerid,34);
                }
                case 
4// The 5th item listed
                
{
                    if(
GetPlayerMoney(playerid) < 1000) return SendClientMessage(playerid0xFFFFFF"You don't have enough cash.");
                    
GivePlayerMoney(playerid, -1000);
                    
GivePlayerWeapon(playerid,16,1);
                }
            }
            }
    }
    }
    return 
1;
}
    return 
1;

Well That's my script.. But i don't know what's wrong with it ? i type /weapons the dialog opens.. i select something... don't respond and closes..


Re: Dialog Help.. +rep - Voxel - 12.12.2013

Change the cases to:
pawn Код:
if(listitem == 0)// The first item listed
                {
                    if(GetPlayerMoney(playerid) < 4090) return SendClientMessage(playerid, 0xFFFFFF, "You don't have enough cash.");
                    GivePlayerMoney(playerid, -4090);
                    GivePlayerWeapon(playerid,24);
                }
if(listitem == 1) etc etc


AW: Re: Dialog Help.. +rep - BigETI - 12.12.2013

This code can't be compiled, since "public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])" is inside "OnDialogResponse()", just remove it.

Quote:
Originally Posted by Voxel
Посмотреть сообщение
Change the cases to:
pawn Код:
if(listitem == 0)// The first item listed
                {
                    if(GetPlayerMoney(playerid) < 4090) return SendClientMessage(playerid, 0xFFFFFF, "You don't have enough cash.");
                    GivePlayerMoney(playerid, -4090);
                    GivePlayerWeapon(playerid,24);
                }
if(listitem == 1) etc etc
Does not help either and slows down code, if many cases have to be checked.


Re: Dialog Help.. +rep - StuartD - 12.12.2013

Try This:

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext, "/weapons", true))
    {
        ShowPlayerDialog(playerid, 9923, DIALOG_STYLE_LIST, "Select Your Weapon", "Desert Eagle ($4090)\nPistol ($3000)\nSawnof Shotgun ($6000)\nSniper Rifle ($8000)\nGrenade ($1000)", "Purchase", "Cancel");
        return 1;
    }
    return 0;
}
   
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(response)// They pressed the first button.
    {
        switch(dialogid)// If you only have one dialog, then this isn't required, but it's neater for when you implement more dialogs.
        {
            case 9923:// Our dialog!
            {
               switch(listitem)// Checking which listitem was selected
                {
                    case 0:// The first item listed
                    {
                        if(GetPlayerMoney(playerid) < 4090) return SendClientMessage(playerid, 0xFFFFFF, "You don't have enough cash.");
                        GivePlayerMoney(playerid, -4090);
                        GivePlayerWeapon(playerid,24);
                    }
                    case 1: // The second item listed
                    {
                        if(GetPlayerMoney(playerid) < 3000) return SendClientMessage(playerid, 0xFFFFFF, "You don't have enough cash.");
                        GivePlayerMoney(playerid, -3000);
                        GivePlayerWeapon(playerid,22);
                    }
                    case 2: // The third item listed
                    {
                        if(GetPlayerMoney(playerid) < 6000) return SendClientMessage(playerid, 0xFFFFFF, "You don't have enough cash.");
                        GivePlayerMoney(playerid, -6000);
                        GivePlayerWeapon(playerid,26);
                    }
                    case 3: // The 4th item listed
                    {
                        if(GetPlayerMoney(playerid) < 8000) return SendClientMessage(playerid, 0xFFFFFF, "You don't have enough cash.");
                        GivePlayerMoney(playerid, -8000);
                        GivePlayerWeapon(playerid,34);
                    }
                    case 4: // The 5th item listed
                    {
                        if(GetPlayerMoney(playerid) < 1000) return SendClientMessage(playerid, 0xFFFFFF, "You don't have enough cash.");
                        GivePlayerMoney(playerid, -1000);
                        GivePlayerWeapon(playerid,16,1);
                    }
                }
            }
        }
    }
    return 0;
}



Re: Dialog Help.. +rep - Eliminator - 13.12.2013

Thanks GuyS! +Rep Added!


Re: AW: Re: Dialog Help.. +rep - Voxel - 13.12.2013

Quote:
Originally Posted by BigETI
Посмотреть сообщение
Does not help either and slows down code, if many cases have to be checked.
Ah ok thanks!

Sorry for bumping.


Re: Dialog Help.. +rep - AmigaBlizzard - 13.12.2013

Filterscripts should ALWAYS have "return 0;" at the end of OnDialogResponse.

Why?
The filterscripts are executed in the order you state in the server.cfg file.
At the end, your gamemode is processed.

If your first filterscript has "return 1;" in that callback, the server thinks you want to end the responses on dialogs there, so it won't process the other filterscripts for OnDialogResponse.

Having "return 0;" in the first filterscript in OnDialogResponse, actually means the proper dialog-id wasn't found there and the server should continu to search for the proper dialog-id in the next filterscript.