Uncertain as to why this dialog causes lag..
#1

COMMAND TO OPEN.

pawn Код:
CMD:buyparts(playerid,params[])
{
    if(LoggedIn[playerid] == 0) return SendClientMessage(playerid, COLOUR_GREY, "You must be logged in to use this command.");
        new string[64];
        if(IsPlayerInRangeOfPoint(playerid, 5.0, -2230.5210,2560.3955,1.8223))
         {
            format(string, sizeof(string), "Illegal Gun Part Purchasing.");
            ShowPlayerDialog(playerid, DIALOG_GUNPARTS, DIALOG_STYLE_LIST, string, "Small Grip ($300)\nMedium Grip ($500)\nLarge Grip($750)\nRandom Grip Package (3) ($1,500)\nSmall Frame ($1,000)\nMedium Frame ($1,500)\nLarge Frame ($2,000)\nRandom Frame Package (3)($3,000)\nSmall Barrel ($500)\nMedium Barrel ($750)\nLarge Barrel($1,000)\nRandom Barrel Package (3) ($2,000)", "Select", "Cancel");
        }
    return 1;
}
DIALOG
pawn Код:
else if(dialogid == DIALOG_GUNPARTS)
            {
                new str[128];
                if(response == 0)
                {
                    return 1;
                }
                switch(listitem)
                {
                    case 0:
                    {
     
                        PlayerMoney[playerid] = GetPlayerMoney(playerid);
                        if(PlayerMoney[playerid] < 300)return SendClientMessage(playerid, COLOUR_GREY, "You do not have this much money.");
                        GivePlayerMoney(playerid, -300);
                        PlayerSQLID[playerid] = MySQL_GetValue(PlayerSQLID[playerid], "id", "accounts");
                        SGrip[playerid] ++;
                        MySQL_SetInteger(PlayerSQLID[playerid], "SGrip", SGrip[playerid], "accounts");
                        format(str, sizeof(str), "You have purchased a Small Grip, you now have a total of %d.", SGrip[playerid]);
                        SendClientMessage(playerid, COLOUR_WHITE, str);
                    }
                    case 1:
                    {
               
                        if(PlayerMoney[playerid] < 500)return SendClientMessage(playerid, COLOUR_GREY, "You do not have this much money.");
                        GivePlayerMoney(playerid, -500);
                        PlayerSQLID[playerid] = MySQL_GetValue(PlayerSQLID[playerid], "id", "accounts");
                        MGrip[playerid] ++;
                        MySQL_SetInteger(PlayerSQLID[playerid], "MGrip", MGrip[playerid], "accounts");
                        format(str, sizeof(str), "You have purchased a Medium Grip, you now have a total of %d.", MGrip[playerid]);
                        SendClientMessage(playerid, COLOUR_WHITE, str);
                    }
                    case 2:
                    {
             
                        if(PlayerMoney[playerid] < 750)return SendClientMessage(playerid, COLOUR_GREY, "You do not have this much money.");
                        GivePlayerMoney(playerid, -750);
                        PlayerSQLID[playerid] = MySQL_GetValue(PlayerSQLID[playerid], "id", "accounts");
                        LGrip[playerid] ++;
                        MySQL_SetInteger(PlayerSQLID[playerid], "LGrip", LGrip[playerid], "accounts");
                        format(str, sizeof(str), "You have purchased a Large Grip, you now have a total of %d.", LGrip[playerid]);
                        SendClientMessage(playerid, COLOUR_WHITE, str);

                    }
                    case 3://Random Package.
                    {
                        if(PlayerMoney[playerid] < 1500)return SendClientMessage(playerid, COLOUR_GREY, "You do not have this much money.");
                        GivePlayerMoney(playerid, -1500);
                        PlayerSQLID[playerid] = MySQL_GetValue(PlayerSQLID[playerid], "id", "accounts");
                        new rand[3];
                        new randStr[3][25];
           

                        for(new i = 0; i < sizeof rand; i++)
                        {
                            rand[i] = random(3);
                            switch(rand[i])
                            {
                            case 0:
                                {
                                    format(randStr[i], 25, "Small Grip");
                                    SGrip[playerid] ++;
                                    MySQL_SetInteger(PlayerSQLID[playerid], "SGrip", SGrip[playerid], "accounts");

                                }
                            case 1:
                                {
                                    format(randStr[i], 25, "Medium Grip");
                                    MGrip[playerid] ++;
                                    MySQL_SetInteger(PlayerSQLID[playerid], "MGrip", MGrip[playerid], "accounts");
                                }
                            case 2:
                                {
                                    format(randStr[i], 25, "Large Grip");
                                    LGrip[playerid] ++;
                                    MySQL_SetInteger(PlayerSQLID[playerid], "LGrip", LGrip[playerid], "accounts");
                                }//case 2
                            }//switch
                        }//fornew
                            format(str, sizeof(str),"You got a {33AA33}%s{FFFFFF}, a {33AA33}%s {FFFFFF}and a {33AA33}%s {FFFFFF}from the package.", randStr[0], randStr[1], randStr[2]);
                            SendClientMessage(playerid, COLOUR_WHITE, str);
                    }//actual case
                    case 4:
                    {
           
                        if(PlayerMoney[playerid] < 1000)return SendClientMessage(playerid, COLOUR_GREY, "You do not have this much money.");
                        GivePlayerMoney(playerid, - 1000);
                        PlayerSQLID[playerid] = MySQL_GetValue(PlayerSQLID[playerid], "id", "accounts");
                        SFrame[playerid] ++;
                        MySQL_SetInteger(PlayerSQLID[playerid], "SFrame", SFrame[playerid], "accounts");
                        format(str, sizeof(str), "You have purchased a Small Frame, you now have a total of %d.", SFrame[playerid]);
                        SendClientMessage(playerid, COLOUR_WHITE, str);
                    }
                    case 5:
                    {
         
                        if(PlayerMoney[playerid] < 1500)return SendClientMessage(playerid, COLOUR_GREY, "You do not have this much money.");
                        GivePlayerMoney(playerid, -1500);
                        PlayerSQLID[playerid] = MySQL_GetValue(PlayerSQLID[playerid], "id", "accounts");
                        MFrame[playerid] ++;
                        MySQL_SetInteger(PlayerSQLID[playerid], "MFrame", MFrame[playerid], "accounts");
                        format(str, sizeof(str), "You have purchased a Medium Frame, you now have a total of %d.", MFrame[playerid]);
                        SendClientMessage(playerid, COLOUR_WHITE, str);
                    }
                    case 6:
                    {
             
                        if(PlayerMoney[playerid] < 2000)return SendClientMessage(playerid, COLOUR_GREY, "You do not have this much money.");
                        GivePlayerMoney(playerid, -2000);
                        PlayerSQLID[playerid] = MySQL_GetValue(PlayerSQLID[playerid], "id", "accounts");
                        LFrame[playerid] ++;
                        MySQL_SetInteger(PlayerSQLID[playerid], "LFrame", LFrame[playerid], "accounts");
                        format(str, sizeof(str), "You have purchased a Large Frame, you now have a total of %d.", LFrame[playerid]);
                        SendClientMessage(playerid, COLOUR_WHITE, str);

                    }
                    case 7://Random Package.
                    {
                        if(PlayerMoney[playerid] < 3000)return SendClientMessage(playerid, COLOUR_GREY, "You do not have this much money.");
                        GivePlayerMoney(playerid, -3000);
                        PlayerSQLID[playerid] = MySQL_GetValue(PlayerSQLID[playerid], "id", "accounts");
           
                        new rand1[3];
                        new randStr1[3][25];

                        for(new i = 0; i < sizeof rand1; i++)
                        {
                            rand1[i] = random(3);
                            switch(rand1[i])
                            {
                            case 0:
                                {
                                    format(randStr1[i], 25, "Small Frame");
                                    SFrame[playerid] ++;
                                    MySQL_SetInteger(PlayerSQLID[playerid], "SFrame", SFrame[playerid], "accounts");

                                }
                            case 1:
                                {
                                    format(randStr1[i], 25, "Medium Frame");
                                    MFrame[playerid] ++;
                                    MySQL_SetInteger(PlayerSQLID[playerid], "MFrame", MFrame[playerid], "accounts");
                                }
                            case 2:
                                {
                                    format(randStr1[i], 25, "Large Frame");
                                    LFrame[playerid] ++;
                                    MySQL_SetInteger(PlayerSQLID[playerid], "LFrame", LFrame[playerid], "accounts");
                                }//case 2
                            }//switch
                        }//switch
                            format(str, sizeof(str),"You got a {33AA33}%s{FFFFFF}, a {33AA33}%s {FFFFFF}and a {33AA33}%s {FFFFFF}from the package.", randStr1[0], randStr1[1], randStr1[2]);
                            SendClientMessage(playerid, COLOUR_WHITE, str);
                    }//case
                case 8:
                    {
     
                        if(PlayerMoney[playerid] < 500)return SendClientMessage(playerid, COLOUR_GREY, "You do not have this much money.");
                        GivePlayerMoney(playerid, -500);
                        PlayerSQLID[playerid] = MySQL_GetValue(PlayerSQLID[playerid], "id", "accounts");
                        SBarrel[playerid] ++;
                        MySQL_SetInteger(PlayerSQLID[playerid], "SBarrel", SBarrel[playerid], "accounts");
                        format(str, sizeof(str), "You have purchased a Small Barrel, you now have a total of %d.", SBarrel[playerid]);
                        SendClientMessage(playerid, COLOUR_WHITE, str);
                    }
                    case 9:
                    {
         
                        if(PlayerMoney[playerid] < 750)return SendClientMessage(playerid, COLOUR_GREY, "You do not have this much money.");
                        GivePlayerMoney(playerid, -750);
                        PlayerSQLID[playerid] = MySQL_GetValue(PlayerSQLID[playerid], "id", "accounts");
                        MBarrel[playerid] ++;
                        MySQL_SetInteger(PlayerSQLID[playerid], "MBarrel", MBarrel[playerid], "accounts");
                        format(str, sizeof(str), "You have purchased a Medium Barrel, you now have a total of %d.", MBarrel[playerid]);
                        SendClientMessage(playerid, COLOUR_WHITE, str);
                    }
                    case 10:
                    {
     
                        if(PlayerMoney[playerid] < 1000)return SendClientMessage(playerid, COLOUR_GREY, "You do not have this much money.");
                        GivePlayerMoney(playerid, -1000);
                        PlayerSQLID[playerid] = MySQL_GetValue(PlayerSQLID[playerid], "id", "accounts");
                        LBarrel[playerid] ++;
                        MySQL_SetInteger(PlayerSQLID[playerid], "LBarrel", LBarrel[playerid], "accounts");
                        format(str, sizeof(str), "You have purchased a Large Barrel, you now have a total of %d.", LBarrel[playerid]);
                        SendClientMessage(playerid, COLOUR_WHITE, str);

                    }
                    case 11://Random Package.
                    {
                        if(PlayerMoney[playerid] < 2000)return SendClientMessage(playerid, COLOUR_GREY, "You do not have this much money.");
                        GivePlayerMoney(playerid, -2000);
                        PlayerSQLID[playerid] = MySQL_GetValue(PlayerSQLID[playerid], "id", "accounts");
                        new rand2[3];
                        new randStr2[3][25];
       

                        for(new i = 0; i < sizeof rand2; i++)
                        {
                            rand2[i] = random(3);
                            switch(rand2[i])
                            {
                            case 0:
                                {
                                    format(randStr2[i], 25, "Small Barrel");
                                    SBarrel[playerid] ++;
                                    MySQL_SetInteger(PlayerSQLID[playerid], "SBarrel", SBarrel[playerid], "accounts");

                                }
                            case 1:
                                {
                                    format(randStr2[i], 25, "Medium Barrel");
                                    MBarrel[playerid] ++;
                                    MySQL_SetInteger(PlayerSQLID[playerid], "MBarrel", MBarrel[playerid], "accounts");
                                }
                            case 2:
                                {
                                    format(randStr2[i], 25, "Large Barrel");
                                    LBarrel[playerid] ++;
                                    MySQL_SetInteger(PlayerSQLID[playerid], "LBarrel", LBarrel[playerid], "accounts");
                                }//case 2
                            }//switch

                        }//for
                            format(str, sizeof(str),"You got a {33AA33}%s{FFFFFF}, a {33AA33}%s {FFFFFF}and a {33AA33}%s {FFFFFF}from the package.", randStr2[0], randStr2[1], randStr2[2]);
                            SendClientMessage(playerid, COLOUR_WHITE, str);
                    }//case
                }//switch
            }//dialog
All that happens is that when you type /buyparts there is about a 1-3 second delay before the dialog appears...It affects the server clocks seconds, not sure why...Any advice would be perfect. It does work,might I add.
Reply
#2

If the issue occurs before showing the dialog, then the problem is at the command itself. (not @OnPlayerDialog)

A few tips:

1) Instead of checking if player is logged in in EVERY command (according to script) {I used to do that myself :/}, use the callback that gets call whenever a player types in a command.
[in case having ZCMD as your command processor]
pawn Код:
public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
    if(!LoggedIn[playerid]) return SendClientMessage(playerid, COLOUR_GREY, "You must be logged in to use this command.");
    return 1;
}
2) I'm not sure why you're formatting a string that takes no parameters at all? (or I'm wrong and without that it'll result in an error which the line is too long?)

3) The issue might be due to the long text in the body of the dialog? - Use strcat
pawn Код:
CMD:buyparts(playerid,params[])
{
    if(IsPlayerInRangeOfPoint(playerid, 5.0, -2230.5210, 2560.3955, 1.8223))
    {
        new dialog[300];
        strcat(dialog, "Small Grip ($300)\nMedium Grip ($500)\nLarge Grip($750)\nRandom Grip Package (3) ($1,500)\nSmall Frame ($1,000)\n");
        strcat(dialog, "Medium Frame ($1,500)\nLarge Frame ($2,000)\nRandom Frame Package (3)($3,000)\nSmall Barrel ($500)\nMedium Barrel ($750)\n");
        strcat(dialog, "Large Barrel($1,000)\nRandom Barrel Package (3) ($2,000)");
        ShowPlayerDialog(playerid, DIALOG_GUNPARTS, DIALOG_STYLE_LIST, "Illegal Gun Part Purchasing.", dialog, "Select", "Cancel");
    }
    return 1;
}
Reply
#3

Thank you very much for the tips, that's a very good point might I add - about the logged in part.

Basically, when I type /buyparts it's a 1-3 second delay before it actually opens.

I'll try the way you mentioned with strcat,

Thank you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)