AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   How to store information in a database. (https://forums.alliedmods.net/showthread.php?t=270513)

FrostSurf 08-22-2015 18:24

How to store information in a database.
 
This plugin only stores information until map change. Am i able to make it store the information in my MySQL database so it saves it forever ?

Code:

public OnMapStart()
{
        for (new i = 0; i < MAX_LEVEL-1; i++)
        {
                for (new client = 1; client < MAXPLAYERS; client++)
                {
                        g_MapLevelBestTime[i][client] = 0.0;
                }
        }
}

public OnClientStartTouchLevel(client, level, lastlevel)
{
        PrintTimeDiff(client, level, lastlevel);
}

public OnClientStartTouchBonusLevel(client, level, lastlevel)
{
        PrintTimeDiff(client, level, lastlevel);
}

stock PrintTimeDiff(client, level, lastlevel)
{
        if(level == lastlevel+1)
        {
                new bool:enabled = false;
                new Float:time;
                new jumps;
                new fpsmax;
                new String:buffer[32];
               
                Timer_GetClientTimer(client, enabled, time, jumps, fpsmax);
               
                if(enabled)
                {
                        if(g_MapLevelBestTime[level][client] == 0.0)
                        {
                                Timer_SecondsToTime(time, buffer, sizeof(buffer), 2);
                                #if defined LEGACY_COLORS
                                CPrintToChat(client,"{red}[{green}Timer{red}]{green} Checkpoint {red}[{green}-00:00.00{red}]");
                                #else
                                #endif
                                g_MapLevelBestTime[level][client] = time;
                        }
                        else if(g_MapLevelBestTime[level][client] > time)
                        {
                                Timer_SecondsToTime(g_MapLevelBestTime[level][client]-time, buffer, sizeof(buffer), 2);
                                #if defined LEGACY_COLORS
                                CPrintToChat(client, "{red}[{green}Timer{red}]{green} Checkpoint {red}[{green}-%s{red}]", buffer);
                                #else
                                #endif
                                g_MapLevelBestTime[level][client] = time;
                        }
                        else if(g_MapLevelBestTime[level][client] == time)
                        {
                                #if defined LEGACY_COLORS
                                CPrintToChat(client, "{red}[{green}Timer{red}]{green} Checkpoint {red}[+00:00.00]");
                                #else
                                #endif
                        }
                        else if(g_MapLevelBestTime[level][client] < time)
                        {
                                Timer_SecondsToTime(time-g_MapLevelBestTime[level][client], buffer, sizeof(buffer), 2);
                                #if defined LEGACY_COLORS
                                CPrintToChat(client, "{red}[{green}Timer{red}]{green} Checkpoint {red}[+%s]", buffer);
                                #else
                                #endif
                        }
                }
        }
}


FrostSurf 08-22-2015 18:38

Re: How to store information in a database.
 
I already have a MySQL database ready and other components of this timer are using mysql, i dont know if that helps any.

SoulSharD 08-22-2015 18:47

Re: How to store information in a database.
 
https://wiki.alliedmods.net/SQL_%28S...d_Scripting%29

Ta da!

FrostSurf 08-22-2015 18:50

Re: How to store information in a database.
 
Quote:

Originally Posted by SoulSharD (Post 2336016)

Doh! Thanks i will take a read at that.

headline 08-22-2015 22:06

Re: How to store information in a database.
 
Quote:

Originally Posted by FrostSurf (Post 2336019)
Doh! Thanks i will take a read at that.

Be sure to use Threaded everything on SQL


All times are GMT -4. The time now is 06:54.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.