Uncertain as to why this dialog causes lag.. -
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.
Re: Uncertain as to why this dialog causes lag.. -
If the issue occurs before showing the dialog, then the problem is at the command itself. (not @OnPlayerDialog)
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.
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
Re: Uncertain as to why this dialog causes lag.. -
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.