AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   MySql (https://forums.alliedmods.net/showthread.php?t=135983)

rafenn 08-21-2010 13:50

MySql
 
Hi!
MySQL not allowed to edit the registry in order to add the following points:
Code:

PlayerLevel[id]
punkty[id]
punktyhp[id]       
punktyar[id]
punktykam[id]
punktyniew[id]
punktywzm[did]
punktybuty[id]
punktyres[id]
punktygr[id]
punktypistol[id]
punktybron[id]
punktybonusexp[id]
punktyok[id]
punktynies[id]
punktykosa[id]

This is my cod of SQL
Code:

public MySql_Init()
{
    // we tell the API that this is the information we want to connect to,
    // just not yet. basically it's like storing it in global variables
    g_SqlTuple = SQL_MakeDbTuple(Host,User,Pass,Db)
 
    // ok, we're ready to connect
    new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error))
    if(SqlConnection == Empty_Handle)
        // stop the plugin with an error message
        set_fail_state(g_Error)
     
    new Handle:Queries
    // we must now prepare some random queries
    Queries = SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS EXPMODv2 (steamid varchar(32),exp INT(11))")

    if(!SQL_Execute(Queries))
    {
        // if there were any problems the plugin will set itself to bad load.
        SQL_QueryError(Queries,g_Error,charsmax(g_Error))
        set_fail_state(g_Error)
     
    }
   
    // Free the querie
    SQL_FreeHandle(Queries)
 
    // you free everything with SQL_FreeHandle
    SQL_FreeHandle(SqlConnection) 
}
public plugin_end()
{
    // free the tuple - note that this does not close the connection,
    // since it wasn't connected in the first place
    SQL_FreeHandle(g_SqlTuple)

public Load_MySql(id)
{
    new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error))
   
    if(g_SqlTuple == Empty_Handle)
        set_fail_state(g_Error)
       
    new szSteamId[32], szTemp[512]
    get_user_authid(id, szSteamId, charsmax(szSteamId))
   
    new Data[1]
    Data[0] = id
   
    //we will now select from the table `tutorial` where the steamid match
    format(szTemp,charsmax(szTemp),"SELECT * FROM `EXPMODv2` WHERE (`EXPMODv2`.`steamid` = '%s')", szSteamId)
    SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)
   
    SQL_FreeHandle(SqlConnection)
}

public register_client(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(FailState == TQUERY_CONNECT_FAILED)
    {
        log_amx("Load - Could not connect to SQL database.  [%d] %s", Errcode, Error)
    }
    else if(FailState == TQUERY_QUERY_FAILED)
    {
        log_amx("Load Query failed. [%d] %s", Errcode, Error)
    }

    new id
    id = Data[0]
   
    if(SQL_NumResults(Query) < 1)
    {
        //.if there are no results found
       
        new szSteamId[32]
        get_user_authid(id, szSteamId, charsmax(szSteamId)) // get user's steamid
       
        //  if its still pending we can't do anything with it
        if (equal(szSteamId,"ID_PENDING"))
            return PLUGIN_HANDLED
           
        new szTemp[512]
       
        new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error))
        if(g_SqlTuple == Empty_Handle)
            // stop the plugin with an error message
            set_fail_state(g_Error)
       
        // now we will insturt the values into our table.
        format(szTemp,charsmax(szTemp),"INSERT INTO `EXPMODv2` ( `steamid` , `exp`)VALUES ('%s','0');",szSteamId)
        SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
       
        // and of course, free the connection
        SQL_FreeHandle(SqlConnection)
    }
    else
    {
        // if there are results found
        PlayerXP[id]        = SQL_ReadResult(Query, 1)
    }
   
    return PLUGIN_HANDLED
}

public Save_MySql(id)
{
    // ok, we're ready to connect
    new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,511)
    if(g_SqlTuple == Empty_Handle)
        // stop the plugin with an error message
        set_fail_state(g_Error)
 
    new szSteamId[32], szName[32], szTemp[512]
    get_user_authid(id, szSteamId, charsmax(szSteamId))
    get_user_name(id, szName, charsmax(szName))
   
    // Here we will update the user hes information in the database where the steamid matches.
    format(szTemp,charsmax(szTemp),"UPDATE `EXPMODv2` SET `exp` = '%i' WHERE `EXPMODv2`.`steamid` = '%s';",PlayerXP[id], szSteamId)
    SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
 
    // and of course, free the connection
    SQL_FreeHandle(SqlConnection)
}

public IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    SQL_FreeHandle(Query)
   
    return PLUGIN_HANDLED
}

This is needed just to my XP MOD


All times are GMT -4. The time now is 21:59.

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