Loop - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Loop (
/showthread.php?tid=624145)
Loop -
StrikerZ - 11.12.2016
Hi, is it possible to loop all the player's to save the stats? I'm using mysql. And i'm talking about the UPDATE statement for all the players connected
Re: Loop -
AjaxM - 11.12.2016
Yes, of course you can.
Example code:
PHP код:
new query[99];
for(new i = 0; i < MAX_PLAYERS ; i ++)
{
mysql_format(mysql, query, sizeof(query), "UPDATE `Users` SET `Money` = %d WHERE `ID` = %d",
GetPlayerMoney(i),
mysql_tquery(mysql, query, "", "");
}
Re: Loop - iLearner - 11.12.2016
Use foreach.inc
Re: Loop -
Abagail - 11.12.2016
You should also add a check to make sure the player is logged in and registered, don't save them otherwise.
Re: Loop -
ReshiramZekrom - 11.12.2016
You can basically use the function added in the 0.3.7: GetPlayerPoolSize which gets the hightest player ID (this is useful to save memory).
And so:
PHP код:
for(new i = 0; i <= GetPlayerPoolSize(); i++)
{
if(IsPlayerConnected(i) && loggedvariable[i] == true)
{
//here put the code to save the variables on the db
}
}