SA-MP Forums Archive
Problem with dialog. - 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: Problem with dialog. (/showthread.php?tid=434513)



Problem with dialog. - lQs - 02.05.2013

Okay, i have really big problem with buying dialog. When i click 'cancel' button it have the same function like 'select' button, so when i try to close this dialog it buys a item. How to fix that? My code:

OnDialogResponse:

pawn Код:
if(dialogid == 40)
    {
        if(!response)
        {
        }
        switch(listitem)
        {
            case 0:
            {
                new string[128];
                if(server_GetCash(playerid) >= 5)
                {
                    SendClientMessage(playerid, COLOR_WHITE, "You've purchased a sprunk!");
                    server_GiveCash(playerid, -5);
                    PlayerInfo[playerid][pSprunk]= PlayerInfo[playerid][pSprunk]+1;
                    GameTextForPlayer(playerid, "~r~$-5", 1000,1);
                    format(string, sizeof(string), "* %s has bought a sprunk for $5.", GetName(playerid));
                    ProxDetector(10.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                }
                else
                {
                SendClientMessage(playerid, COLOR_RED, "Not enough money!");
                }
            }
CMD:buy

pawn Код:
CMD:buy(playerid, params[])
{
    if(IsPlayerInRangeOfPoint(playerid, 5, -27.6207,-89.9443,1003.5469))
    {
        ShowPlayerDialog(playerid, 40, DIALOG_STYLE_LIST, "General Store Items", "Sprunk - $5\nRope - $20\nFirst Aid Kit - $65\nBaseball Bat - $200\nFlowers - $25\nPacket of Cigars - $25", "Select", "Cancel");
    }
    return 1;
}



Re: Problem with dialog. - JackBurgani - 02.05.2013

pawn Код:
if(dialogid == 40)
    {
        if(!response)
        {
        } else {
        switch(listitem)
        {
            case 0:
            {
                new string[128];
                if(server_GetCash(playerid) >= 5)
                {
                    SendClientMessage(playerid, COLOR_WHITE, "You've purchased a sprunk!");
                    server_GiveCash(playerid, -5);
                    PlayerInfo[playerid][pSprunk]= PlayerInfo[playerid][pSprunk]+1;
                    GameTextForPlayer(playerid, "~r~$-5", 1000,1);
                    format(string, sizeof(string), "* %s has bought a sprunk for $5.", GetName(playerid));
                    ProxDetector(10.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                }
                else
                {
                SendClientMessage(playerid, COLOR_RED, "Not enough money!");
                }
            }
     }
This should work..

EDIT: Make sure to fix the identation

EDIT:
pawn Код:
if(dialogid == 40)
    {
        if(!response)
        {
               return 0;
        }
        switch(listitem)
        {
            case 0:
            {
                new string[128];
                if(server_GetCash(playerid) >= 5)
                {
                    SendClientMessage(playerid, COLOR_WHITE, "You've purchased a sprunk!");
                    server_GiveCash(playerid, -5);
                    PlayerInfo[playerid][pSprunk]= PlayerInfo[playerid][pSprunk]+1;
                    GameTextForPlayer(playerid, "~r~$-5", 1000,1);
                    format(string, sizeof(string), "* %s has bought a sprunk for $5.", GetName(playerid));
                    ProxDetector(10.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                }
                else
                {
                SendClientMessage(playerid, COLOR_RED, "Not enough money!");
                }
            }
I think this could work too..


Re: Problem with dialog. - lQs - 02.05.2013

Fixed! Thank you! What do you changed here?


Re: Problem with dialog. - Pottus - 03.05.2013

No need for useless return

pawn Код:
if(dialogid == 40)
    {
        if(response)
        {
            switch(listitem)
            {
                case 0:
                {
                    new string[128];
                    if(server_GetCash(playerid) >= 5)
                    {
                        SendClientMessage(playerid, COLOR_WHITE, "You've purchased a sprunk!");
                        server_GiveCash(playerid, -5);
                        PlayerInfo[playerid][pSprunk]= PlayerInfo[playerid][pSprunk]+1;
                        GameTextForPlayer(playerid, "~r~$-5", 1000,1);
                        format(string, sizeof(string), "* %s has bought a sprunk for $5.", GetName(playerid));
                        ProxDetector(10.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                    }
                    else
                    {
                    SendClientMessage(playerid, COLOR_RED, "Not enough money!");
                    }
                }
            }



Re: Problem with dialog. - JackBurgani - 03.05.2013

You had no code in your (!reponse) if statement so if someone hit cancel there was nothing telling it to stop and return, so it continued on with the code below it.


Re: Problem with dialog. - JackBurgani - 03.05.2013

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
No need for useless return

pawn Код:
if(dialogid == 40)
    {
        if(response)
        {
            switch(listitem)
            {
                case 0:
                {
                    new string[128];
                    if(server_GetCash(playerid) >= 5)
                    {
                        SendClientMessage(playerid, COLOR_WHITE, "You've purchased a sprunk!");
                        server_GiveCash(playerid, -5);
                        PlayerInfo[playerid][pSprunk]= PlayerInfo[playerid][pSprunk]+1;
                        GameTextForPlayer(playerid, "~r~$-5", 1000,1);
                        format(string, sizeof(string), "* %s has bought a sprunk for $5.", GetName(playerid));
                        ProxDetector(10.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                    }
                    else
                    {
                    SendClientMessage(playerid, COLOR_RED, "Not enough money!");
                    }
                }
            }
Potato patata..