PDA

View Full Version : Saving Age [MySQL]


Keyhead
31/10/2013, 04:53 PM
So, I have this on OnDialogResponse

if(dialogid == 150)
{
if(!response) return Kick(playerid);
else if(response)
{
if(strval(inputtext) > 75 || strval(inputtext) < 15)
{
ShowPlayerDialog(playerid, 150, DIALOG_STYLE_INPUT, "Age","Enter your age below","Ok","Cancel");
SendClientMessage(playerid, -1, "SERVER:Please enter a correct age!");
SendClientMessage(playerid, -1, "SERVER:It has to be between 15 and 75!");
}
if(!IsNumeric(inputtext))
{
ShowPlayerDialog(playerid, 150, DIALOG_STYLE_INPUT, "Age","Enter your age below","Ok","Cancel");
SendClientMessage(playerid, -1, "SERVER:Please enter a correct age!");
SendClientMessage(playerid, -1, "SERVER:It has to be between 15 and 75!");
}
else if(IsNumeric(inputtext))
{
Player[playerid][Age] = strval(inputtext);
}
}
}


It seems that the age isn't being set. When I call /stats. It's shows age as nothing. Plus, It doesn't save.


CMD:stats(playerid, params[])
{
new str[128];
format(str, 128, "Admin:[%d] - Money:[%d] - Deaths:[%d] - Level:[%d] - Age:[%d]", Player[playerid][Admin], GetPlayerMoney(playerid), Player[playerid][Deaths], Player[playerid][Level], Player[playerid][Age]);
ShowPlayerDialog(playerid, 100, DIALOG_STYLE_MSGBOX, "Stats", str, "Ok","Cancel");
return 1;
}



Player[playerid][Age] = cache_get_field_content_int(0, "age");


The line I use to save it to save it to the SQL.

mysql_format(SQL, query, sizeof(query), "UPDATE `players` SET `money` = '%d', `level` = '%d', `deaths` = '%d', `admin` = '%d', `skin` = '%d', `x` = '%f', `y` = '%f', `z` = '%f', `age` = '%d' WHERE `id` = '%d' LIMIT 1", GetPlayerMoney(playerid), Player[playerid][Level],Player[playerid][Deaths],Player[playerid][Admin],Player[playerid][Skin],x,y,z, Player[playerid][Age], Player[playerid][ID]);

Konstantinos
31/10/2013, 05:07 PM
If there's an error about invalid ages etc, use return 1 to preven the rest of the code being executed.
if(dialogid == 150)
{
if(!response) return Kick(playerid);
if(!IsNumeric(inputtext))
{
ShowPlayerDialog(playerid, 150, DIALOG_STYLE_INPUT, "Age","Enter your age below","Ok","Cancel");
SendClientMessage(playerid, -1, "SERVER:Please enter a correct age!");
SendClientMessage(playerid, -1, "SERVER:It has to be between 15 and 75!");
return 1;
}
else
{
new _age = strval(inputtext);
if(_age > 75 || _age < 15)
{
ShowPlayerDialog(playerid, 150, DIALOG_STYLE_INPUT, "Age","Enter your age below","Ok","Cancel");
SendClientMessage(playerid, -1, "SERVER:Please enter a correct age!");
SendClientMessage(playerid, -1, "SERVER:It has to be between 15 and 75!");
return 1;
}
Player[playerid][Age] = _age;
}
}


Debug the query as well:

mysql_format(SQL, query, sizeof(query), "UPDATE `players` SET `money` = '%d', `level` = '%d', `deaths` = '%d', `admin` = '%d', `skin` = '%d', `x` = '%f', `y` = '%f', `z` = '%f', `age` = '%d' WHERE `id` = '%d' LIMIT 1", GetPlayerMoney(playerid), Player[playerid][Level],Player[playerid][Deaths],Player[playerid][Admin],Player[playerid][Skin],x,y,z, Player[playerid][Age], Player[playerid][ID]);
print(query);


And post what it printed.

Jefff
31/10/2013, 05:10 PM
isnumeric is not needed here

if(dialogid == 150)
{
if(!response) Kick(playerid);
else if(!(14 < strval(inputtext) < 76))
{
ShowPlayerDialog(playerid, 150, DIALOG_STYLE_INPUT, "Age","Enter your age below","Ok","Cancel");
SendClientMessage(playerid, -1, "SERVER:Please enter a correct age!");
SendClientMessage(playerid, -1, "SERVER:It has to be between 15 and 75!");
}else
Player[playerid][Age] = strval(inputtext);

return 1;
}

Pottus
31/10/2013, 05:10 PM
if(dialogid == 150)
{
if(response)
{
if(strval(inputtext) > 75 || strval(inputtext) < 15)
{
ShowPlayerDialog(playerid, 150, DIALOG_STYLE_INPUT, "Age","Enter your age below","Ok","Cancel");
SendClientMessage(playerid, -1, "SERVER:Please enter a correct age!");
SendClientMessage(playerid, -1, "SERVER:It has to be between 15 and 75!");
}
else Player[playerid][Age] = strval(inputtext);
}
else Kick(playerid);
}

@Jefff - Avoid returns whenever possible :)

Keyhead
31/10/2013, 05:12 PM
Still didn't work mate.


UPDATE `players` SET `money` = '0', `level` = '0', `deaths` = '0', `admin` = '0', `skin` = '0', `x` = '2162.767334', `y` = '-1760.597778', `z` = '13.542108', `age` = '0' WHERE `id` = '8' LIMIT 1