SA-MP Forums Archive
Getting Saved Server Data (MySQL) - 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: Getting Saved Server Data (MySQL) (/showthread.php?tid=534244)



Getting Saved Server Data (MySQL) - austin070 - 28.08.2014

pawn Код:
new IntRate;
new TaxRate;

stock GetInformation(info[], value)
{
    new query[128];
    format(query, sizeof(query),"SELECT * FROM `information` WHERE `info` = '%s'", info);
    mysql_query(query);
    mysql_store_result();

    while(mysql_fetch_row_format(query,"|"))
    {
        new tablevalue[16];
        mysql_fetch_field_row(tablevalue, "value"); value = strval(tablevalue);
    }
    mysql_free_result();
   
    return value;
}

public OnGameModeInit()
{
    GetInformation("interest", IntRate);
    GetInformation("tax", TaxRate);
       
        return 1;
}

//debug command
CMD:rates(playerid, params[])
{

    new string[128];
    format(string, 128, "Interest: %d%s", IntRate, "%%");
    SendClientMessage(playerid, COLOR_WHITE, string);
    format(string, 128, "Tax: %d%s", TaxRate, "%%");
    SendClientMessage(playerid, COLOR_WHITE, string);
   
    return 1;
}
It's returning 0 for both rates. What's wrong?


Re: Getting Saved Server Data (MySQL) - SchurmanCQC - 28.08.2014

You've gotta do this in OnGameModeInit:

pawn Код:
IntRate = GetInformation("interest");
TaxRate = GetInformation("tax");
You also have to remove the value parameter for GetInformation, and create a new var called value inside of it.

Your code would look like this:

pawn Код:
new IntRate;
new TaxRate;

stock GetInformation(info[])
{
    new query[128], value;
    format(query, sizeof(query),"SELECT * FROM `information` WHERE `info` = '%s'", info);
    mysql_query(query);
    mysql_store_result();

    while(mysql_fetch_row_format(query,"|"))
    {
        new tablevalue[16];
        mysql_fetch_field_row(tablevalue, "value"); value = strval(tablevalue);
    }
    mysql_free_result();
   
    return value;
}

public OnGameModeInit()
{
    IntRate = GetInformation("interest");
    TaxRate = GetInformation("tax");
    return 1;
}

//debug command
CMD:rates(playerid, params[])
{
    new string[128];
    format(string, 128, "Interest: %d%%", IntRate);
    SendClientMessage(playerid, COLOR_WHITE, string);
    format(string, 128, "Tax: %d%%", TaxRate);
    SendClientMessage(playerid, COLOR_WHITE, string);
    return 1;
}



Re: Getting Saved Server Data (MySQL) - austin070 - 28.08.2014

Thank you.


Re: Getting Saved Server Data (MySQL) - austin070 - 28.08.2014

EDIT: Moved to new topic