PDA

View Full Version : mysql server problem


TroX21
06/05/2019, 09:03 PM
yo guys . ive tried to make a lottery system in the past few hours but the problem is that i save the variable in mysql all ok. The thing is that i have to relog to see my money . Anyone knows how can i save it and at the same time have it *instantly* on the server?

CODE :


for(new i, j = cache_get_row_count (); i < j; i++) {
cache_get_field_content(i, "name", szResult); format(name, 256, szResult);
cache_get_field_content(i, "Money", moneyss);
new money = strval(moneyss)+50000;
x++;
new szQuery2[256];
mysql_format(SQL, szQuery2, sizeof(szQuery2), "UPDATE `users` SET `Money`='%d' WHERE `name`='%s'", money, name);
mysql_tquery(SQL,szQuery2, "", "");

format(string, sizeof(string), "{FFFFFF}The winner is: {FF0000}%s", name);
MsjL(COLOR_WHITE, string);
}


*i dont receive any error the only problem is that i have to relog to have my money

KeyOfKey
06/05/2019, 09:25 PM
You have to save it in the enum.

You have the users table, so i guess you have the "player" enum too. Something like:

Player[playerid][Money]

or just like GivePlayerMoney.

TroX21
06/05/2019, 09:36 PM
https://pastebin.com/ZiKDT08E

the problem is i cant use playerid ... i tried with getplayerid same thing ... not working

SiaReyes
07/05/2019, 05:12 AM
for(new i, j = cache_get_row_count (); i < j; i++)
{
cache_get_field_content(i, "name", szResult); format(name, 256, szResult);
cache_get_field_content(i, "Money", moneyss);
new money = strval(moneyss)+50000;
x++;
new szQuery2[256];
mysql_format(SQL, szQuery2, sizeof(szQuery2), "UPDATE `users` SET `Money`='%d' WHERE `name`='%s'", money, name);
mysql_tquery(SQL,szQuery2, "", "");

// --- if player is conncted!
new pID = GetPlayerIdFromName(name);
PlayerInfo[pID][pMoney] = money;
//-------------

format(string, sizeof(string), "{FFFFFF}The winner: {FF0000}%s", name);
MsjL(COLOR_WHITE, string);
}

stock GetPlayerIdFromName(playername[])
{
foreach(new i: Player)
{
new playername2[MAX_PLAYER_NAME];
GetPlayerName(i, playername2, sizeof(playername2));
if(strcmp(playername2, playername, true, strlen(playername)) == 0)
{
return i;
}
}
return INVALID_PLAYER_ID;
}