Problem with dialog.
#1

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;
}
Reply
#2

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..
Reply
#3

Fixed! Thank you! What do you changed here?
Reply
#4

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!");
                    }
                }
            }
Reply
#5

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.
Reply
#6

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..
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)