Raised This Month: $ Target: $400
 0% 

[REQ] SQL Saving Type Edit


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
JoooN
BANNED
Join Date: Jul 2013
Location: Ban List :P
Old 07-28-2013 , 02:38   [REQ] SQL Saving Type Edit
Reply With Quote #1

So as title says, I need to change a plugin's SQL Save Type to another plugin's save type (for example I wanna switch from a plugin to another, a plugin saves by column, but the other one saves by putting all of the information in 1 table (different read and save type) so I want to change a plugin's saving type (note that saving type not saving method ) to another plugin's saving type.
Ok so here, I have too many users played time saved with this plugin:
PHP Code:
#include <amxmodx> 
#include <amxmisc> 
#include <sqlx> 

#define PLUGIN "Played Time" 
#define VERSION "0.1" 
#define AUTHOR "authour-unknown" 

#define host "127.0.0.1" 
#define user "DB USER" 
#define pass "DB PASS" 
#define db "time //DB NAME" 

new Handle:sqlg_query[512

new 
PlayedTime[33

new 
showpt

public 
plugin_init()  

    
register_plugin(PLUGINVERSIONAUTHOR ); 
     
    
register_clcmd("say""handle_say"); 
    
register_concmd("amx_playedtime""admin_showptime"ADMIN_RCON," <#Player Name> - Details about playedtime."); 
     
    
showpt register_cvar("amx_pt_mod","1"); 
     


public 
plugin_cfg(){ 
    
sql SQL_MakeDbTuple(host,user,pass,db
    
formatex(g_query,511,"CREATE TABLE IF NOT EXISTS `played_time` (name VARCHAR(32), playedtime INT, date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP)"
    
SQL_ThreadQuery(sql,"query",g_query


public 
handle_say(id)  

    static 
said[12
    
read_argv(1said11
     
    if(
equali(said"/mytime")) 
    { 
        static 
ctime[64], timep
         
        
timep get_user_time(id1) / 60
        
get_time("%H:%M:%S"ctime63); 
         
        switch(
get_pcvar_num(showpt)) 
        { 
            case 
0: return PLUGIN_HANDLED
                 
            case 

            { 
                
client_print(idprint_chat"[Played-Time] You have been playing on the server for: %d minute%s."timeptimep == "" "s");  
                
client_print(idprint_chat"[Played-Time] Your total played time on the server: %d minute%s."timep+PlayedTime[id], timep+PlayedTime[id] == "" "s"); 
            } 
            case 

            { 
                
set_hudmessage(25550500.340.5006.04.00.10.2, -1); 
                
show_hudmessage(id"[Elite-Gaming] You have been playing on the server for: %d minute%s.^n[AMXX]Current time: %s"timeptimep == "" "s"ctime); 
            } 
        } 
        return 
PLUGIN_HANDLED
    } 
    else if(
equal(said,"/top15_time")){ 
        new 
data[1];data[0]=id 
         
        formatex
(g_query,511,"SELECT * FROM played_time ORDER BY playedtime DESC LIMIT 15"
        
SQL_ThreadQuery(sql,"show_top15",g_query,data,1
         
    } 
    return 
PLUGIN_CONTINUE


public 
admin_showptime(id,level,cid)  

    if(!
cmd_access(idlevelcid2)) 
        return 
PLUGIN_HANDLED
     
    static 
arg[32]; 
    
read_argv(1arg31); 
     
    new 
player cmd_target(idarg2); 
     
    if(!
player
        return 
PLUGIN_HANDLED
     
    static 
name[32]; 
    
get_user_name(playername31); 
     
    static 
timepctime[64]; 
     
    
timep get_user_time(player1) / 60
    
get_time("%H:%M:%S"ctime63); 
     
    
console_print(id"-----------------------(#PlayedTime#)-----------------------"); 
    
console_print(id"[Played-Time] %s have been playing on the server for %d minute%s.",nametimeptimep == "" "s"); 
    
console_print(id"[Played-Time] %s's total played time on the server %d minute%s.",nametimep+PlayedTime[player], timep == "" "s"); // new 
    
console_print(id"-----------------------------------------------------------------"); 
     
    return 
PLUGIN_HANDLED


public 
client_disconnect(id){ 
    new 
name[32
     
    
get_user_name(id,name,31)     
    
replace_all(name,32,"'",""
    
replace_all(name,32,"^"","") 
     
    PlayedTime[id] = get_playedtime(id) 
     
    formatex(g_query,511,"
UPDATE played_time SET playedtime='%d' WHERE name='%s'",PlayedTime[id],name) 
    SQL_ThreadQuery(sql,"
query",g_query) 
     
    PlayedTime[id] = 0 


public client_putinserver(id){ 
    PlayedTime[id] = get_playedtime(id) 
    log_amx("
--> Got %d",PlayedTime[id]) 


public plugin_end(){ 
    SQL_FreeHandle(sql) 



get_playedtime(id){ 
    new err,error[128] 
     
    new Handle:connect = SQL_Connect(sql,err,error,127) 
     
    if(err){ 
        log_amx("
--> MySQL Connection Failed - [%d][%s]",err,error) 
        set_fail_state("
mysql connection failed") 
    } 
     
    new name[32],Handle:query,pt 
    get_user_name(id,name,31) 
    replace_all(name,32,"'","") 
    replace_all(name,32,"^"","") 
     
    query = SQL_PrepareQuery(connect,"SELECT playedtime FROM played_time WHERE name='
%s'",name) 
    SQL_Execute(query) 
     
    if(!SQL_MoreResults(query)){ 
        formatex(g_query,511,"INSERT INTO played_time (name,playedtime) VALUES('
%s','%d')",name,get_user_time(id,1)/60) 
        SQL_ThreadQuery(sql,"query",g_query) 
         
        pt = (get_user_time(id,1)/60) 
    }else{ 
        pt = SQL_ReadResult(query,0)+(get_user_time(id,1)/60) 
    } 
     
    log_amx("--> Get %d minutes for %s",pt,name) 
     
    SQL_FreeHandle(connect) 
    SQL_FreeHandle(query) 
     
    return pt 


public show_top15(FailState, Handle:Query, Error[], Errcode,Data[], DataSize){ 
    static name[32] 
     
    new id=Data[0] 
    new good,motd[1024],len,place 
     
    if(!SQL_MoreResults(Query)){ 
        client_print(id,print_chat,"[PT] No entryes") 
        return PLUGIN_HANDLED 
    } 
     
    len = format(motd, 1023,"<body bgcolor=#000000><font color=#FFB000><pre>") 
    len += format(motd[len], 1023-len,"%s %-22.22s %3s^n", "#", "Name", "Time") 
     
    while(SQL_MoreResults(Query)){ 
        place++ 
         
        SQL_ReadResult(Query,0,name, 32) 
        good = SQL_ReadResult(Query,1) 
         
        replace_all(name, 32,"<","") 
        replace_all(name, 32,">","") 
         
        len += format(motd[len], 1023-len,"%d %-22.22s %d minute%s^n",place,name,good,good == 1 ? "" : "s") 
         
        SQL_NextRow(Query) 
    } 
     
    len += format(motd[len], 1023-len,"</body></font></pre>") 
    show_motd(id, motd,"Top 15 Players By Time") 
     
    return PLUGIN_CONTINUE 


public query(FailState, Handle:Query, Error[], Errcode){ 


Now I wanna switch from this plugin to played time: extended ->
PHP Code:
#include <amxmodx>
#include <amxmisc>

new const VERSION[] = "0.1"

enum
{
    
SQL 1,
    
VAULT
}

// 1 = SQL
// 2 = nVault
#define SAVETYPE 1

#if SAVETYPE == SQL
    #include <sqlx>
    
new Handle:g_hSql
    
new gsz_Query[256]
        
    
enum
    
{
        
HOST,
        
USER,
        
PASS,
        
DB
    
}
#else
    #include <nvault_util>
    
new const SPECIAL_CHAR[2] = "-"
    
new gVault
#endif

/* ************ EDIT STARTS HERE ************ */
#define MAX_TIME_LENGTH        25

#if SAVETYPE == SQL
// IF using sql, edit these..
new const gsz_SQLINFO[][] = {
    { 
"127.0.0.1" },        // HOST
    
"root" },        // USER
    
"" },    // User's password
    
"amxx" }        // Database Name
}
#endif

new gsz_MyTimeStrings[][] = {
    
"/mytime",
    
"mytime",
    
"my_time",
    
"/mytime",
    
"my_total_time",
    
"mytotaltime"
}

#define COLORED_MESSAGES
/* ************ EDIT ENDS HERE ************** */

#if defined COLORED_MESSAGES
    #include <colorchat>
#endif

new g_iPlayedTime[33], g_iDonateTo[33]
new 
g_pDonateg_pConnectMessages

public plugin_init()
{
    
register_plugin("Played Time: Extended"VERSION"Khalid :)")
    
    
register_clcmd("say /donate""Cmd_Donate")
    
register_concmd("Type""DonateAmount")
    
    
g_pDonate register_cvar("pte_allow_donate""1")
    
g_pConnectMessages register_cvar("pte_show_connect_messages""1")
    
    new 
szCommand[40]
    for(new 
isizeof(gsz_MyTimeStrings); i++)
    {
        
formatex(szCommandcharsmax(szCommand), "say %s"gsz_MyTimeStrings[i])
        
register_clcmd(szCommand"ShowUserTime")
        
formatex(szCommandcharsmax(szCommand), "say_team %s"gsz_MyTimeStrings[i])
        
register_clcmd(szCommand"ShowUserTime")
    }

    
register_clcmd("say""HookSaid")
    
register_clcmd("say_team""HookSaid")
    
    
register_concmd("amx_show_player_time""show_players_times"ADMIN_KICK)

    
#if SAVETYPE == SQL
    
CheckSqlConnection()
    
#else
    
gVault nvault_open("played_time")
    
#endif
}

public 
plugin_natives()
{
    
register_library("played_time")
    
    
register_native("get_user_played_time""native_get_user_played_time"1)
    
register_native("set_user_played_time""native_set_user_played_time"1)
    
register_native("pt_get_save_type""native_get_save_type"1)
}

public 
show_players_times(idlevelcid)
{
    if(!
cmd_access(idlevelcid1))
        return 
PLUGIN_HANDLED
    
    
new szName[32], iPlayer
    
if(read_argc() == 1)
    {
        
console_print(id"Showing players times of all connected players")
        new 
iPlayers[32], iNumiPlayerszName[32]
        
get_players(iPlayersiNum"h")
    
        for(new 
iiNumi++)
        {
            
iPlayer iPlayers[i]
            
get_user_name(iPlayerszName31)
        
            
console_print(id"%d. %s %22.22d"1szName, (g_iPlayedTime[iPlayer] + get_user_time(iPlayer)) / 60)
        }
    }
    
    else
    {
        new 
szArg[32]
        
read_argv(1szArgcharsmax(szArg))
        
        if(
szArg[0] == '@')
        {
            new 
iPlayers[32], iNum
            
if( equali(szArg"@TERRORIST") || equali(szArg"@T") || equal(szArg"@TERR") )
            {
                
console_print(id"Showing players times for team Terrorist")
                
get_players(iPlayersiNum"eh""TERRORIST")
            }
                
            else if( 
equali(szArg"@COUNTERTERRORIST") || equali(szArg"@CT") || equali(szArg"@COUNTER") )
            {
                
console_print(id"Showing players times for team Counter-Terrorist")
                
get_players(iPlayersiNum"eh""CT")
            }
                
            else    return 
console_print(id"That's not a correct team")
            
            for(new 
iiNumi++)
            {
                
iPlayer iPlayers[i]
                
get_user_name(iPlayerszName31)
                
console_print(id"%d. %s %22.22d"1szName, (g_iPlayedTime[iPlayer] + get_user_time(iPlayer)) / 60)
            }
        }
        
        else
        {
            
iPlayer cmd_target(idszArgCMDTARGET_OBEY_IMMUNITY)
            if(!
iPlayer)
            {
                
console_print(id"Player could not be targetted.")
                return 
PLUGIN_HANDLED
            
}
            
            
get_user_name(iPlayerszNamecharsmax(szName))
            
console_print(id"%s total played time is %d"szNameg_iPlayedTime[iPlayer])
        }
    }
    
    return 
PLUGIN_HANDLED
}
        
public 
ShowUserTime(id)
{
    new 
iTime get_user_time(id)
    new 
iTotalTime = (g_iPlayedTime[id] + iTime) / 60
    
    iTime 
/= 60
    
    
#if defined COLORED_MESSAGES
    
ColorChat(idGREEN"[PTE] You have been playing for ^3%d ^4minute%s"iTimeiTime "" "s")
    
ColorChat(idGREEN"[PTE] Your total played time is ^3%d ^4minute%s"iTotalTimeiTime == "" "s")
    
#else
    
client_print(idprint_chat"[PTE] You have been playing for %d minute%s"iTimeiTime == "" "s")
    
client_print(idprint_chat"[PTE] Your total played time is %d minute%s"iTotalTimeiTime == "" "s")
    
#endif    
    
return PLUGIN_HANDLED
}

public 
client_infochanged(id)
{
    new 
szOldName[34], szNewName[32]
    
get_user_name(idszOldNamecharsmax(szOldName))
    
get_user_info(id"name"szNewNamecharsmax(szNewName))
    
    if(!
equal(szOldNameszNewName))
    {
        
#if SAVETYPE == SQL
        
replace_all(szNewNamecharsmax(szNewName), "'""")
        
replace_all(szNewNamecharsmax(szNewName), "^"", "")
        
        formatex(gsz_Query, charsmax(gsz_Query), "
UPDATE `played_timeSET name '%s' WHERE name '%s'", szNewName, szOldName)
        SQL_ThreadQuery(g_hSql, "
Query_Handler", gsz_Query)
        #else
        new szAuthId[33]; get_user_authid(id, szAuthId, 32)
        formatex(szOldName, charsmax(szOldName), "
%s%s", szAuthId, SPECIAL_CHAR)
        nvault_remove(gVault, szAuthId)
        nvault_set(gVault, szOldName, szNewName)
        #endif
    }
}

public client_putinserver(id)
{
    if( is_user_hltv(id)  || is_user_bot(id) )
        return;

    g_iPlayedTime[id] = get_user_totaltime(id)
    
    if(get_pcvar_num(g_pConnectMessages))
    {
        new szName[32]; get_user_name(id, szName, charsmax(szName))
        new iTime = g_iPlayedTime[id] / 60
        
        #if defined COLORED_MESSAGES
        ColorChat(0, GREEN, "
[PTEPlayer ^3%^4Connected with a total time of ^3%^4minute%s", szName, iTime, iTime == 1 ? "" : "s")
        #else
        client_print(0, print_chat, "
[PTEPlayer %s Connected with a total time of %d minute%s", szName, iTime, iTime == 1 ? "" : "s")
        #endif
    }
}

public client_disconnect(id)
{
    // CZ bots steam id is the same (BOT)
    // Prevent them from saving time
    if( is_user_hltv(id)  || is_user_bot(id) )
        return;
    
    Save(id)
}

Save(id)
{
    new szAuthId[35]; get_user_authid(id, szAuthId, charsmax(szAuthId))
    #if SAVETYPE == SQL
        formatex(gsz_Query, charsmax(gsz_Query), "
UPDATE `played_timeSET time = %d WHERE steamid '%s'", g_iPlayedTime[id] + get_user_time(id), szAuthId)
        SQL_ThreadQuery(g_hSql, "
Query_Handler", gsz_Query)
    #else
        new szTime[MAX_TIME_LENGTH]; num_to_str(g_iPlayedTime[id] + get_user_time(id), szTime, charsmax(szTime))
        nvault_remove(gVault, szAuthId)
        nvault_set(gVault, szAuthId, szTime)
    #endif
    
    g_iPlayedTime[id] = 0
}

public Cmd_Donate(id)
{
    if(!get_pcvar_num(g_pDonate))
    {
        #if defined COLORED_MESSAGES
        ColorChat(id, GREEN, "
[PTEDonating is disabled at the moment.")
        #else
        client_print(id, print_chat, "
[PTEDonating is disabled at the moment.")
        #endif
        return PLUGIN_HANDLED
    }
    
    new iPlayers[32], iNum, iPlayer
    get_players(iPlayers, iNum, "
h")
    
    new szTitle[70]
    formatex(szTitle, charsmax(szTitle), "
\rDonate Menu^n\yYour total time is: \w%\yminute%s^n\rBy Khalid :)^n", g_iPlayedTime[id], g_iPlayedTime[id] == 1 ? "" : "s" )
    new iMenu = menu_create(szTitle, "
DonateMenuHandler")
    new szName[32], szInfo[4]
    
    for(new i; i < iNum; i++)
    {
        iPlayer = iPlayers[i]
        
        if(iPlayer != id)
        {
            get_user_name(iPlayer, szName, charsmax(szName))
            num_to_str(iPlayer, szInfo, 3)
            menu_additem(iMenu, szName, szInfo)
        }
    }
    
    menu_display(id, iMenu)
    return PLUGIN_HANDLED
}

public DonateMenuHandler(id, menu, item)
{
    if(!get_pcvar_num(g_pDonate))
    {
        #if defined COLORED_MESSAGES
        ColorChat(id, GREEN, "
[PTEDonating is disabled at the moment.")
        #else
        client_print(id, print_chat, "
[PTEDonating is disabled at the moment.")
        #endif
        return;
    }
    
    if(item < 0)
        return;
    
    new id2, callback, iAccess, szInfo[4]
    menu_item_getinfo(menu, item,iAccess, szInfo, 3, .callback = callback)
    
    id2 = str_to_num(szInfo)
    menu_destroy(menu)
    
    if(!is_user_connected(id2))
    {
        #if defined COLORED_MESSAGES
        ColorChat(id, GREEN, "
[PTEYou can't donate to a disconnected player..")
        #else
        client_print(id, print_chat, "[PTE] You can'
t donate to a disconnected player..")
        #endif
        return;
    }
    
    g_iDonateTo[id] = id2
    new szName[32]; get_user_name(id2, szName, 31)
    
    client_cmd(id, "
messagemode ^"Type the amount that you want to donate^"")
    #if defined COLORED_MESSAGES
    ColorChat(id, GREEN, "
*** Type the amount that you want to donate to ^3%s", szName)
    #else
    client_print(id, print_chat, "
*** Type the amount that you want to donate to %s", szName)
    #endif
}

public DonateAmount(id)
{
    if(!get_pcvar_num(g_pDonate))
    {
        #if defined COLORED_MESSAGES
        ColorChat(id, GREEN, "
[PTEDonating is disabled at the moment.")
        #else
        client_print(id, print_chat, "
[PTEDonating is disabled at the moment.")
        #endif
        return PLUGIN_HANDLED
    }

    
    new id2 = g_iDonateTo[id]
    if(!id2 || !is_user_connected(id2))
        return PLUGIN_HANDLED
    
    new szAmount[50], iAmount
    read_argv(read_argc() - 1, szAmount, charsmax(szAmount))
    
    //replace(szAmount, charsmax(szAmount), "
the", "")
    new iTime = g_iPlayedTime[id]
    
    if( is_str_num(szAmount) )
    {
        iAmount = (str_to_num(szAmount) * 60)
        if(iAmount < 0)
        {
            client_print(id, print_center, "
You can't donate that")
            return PLUGIN_HANDLED
        }
        
        if(iAmount > iTime)
            iAmount = iTime
    }
    
    else if(szAmount[0] == '
*' && szAmount[1] == EOS)
        iAmount = iTime
        
    else
    {
        client_print(id, print_center, "You can'
t donate that")
        return PLUGIN_HANDLED
    }
    
    if( g_iPlayedTime[id] - iAmount < 0 )
        iAmount -= g_iPlayedTime[id]
    
    g_iPlayedTime[id] -= iAmount
    g_iPlayedTime[id2] += iAmount
    
    new szName[32], szName2[32]
    get_user_name(id, szName, 31); get_user_name(id2, szName2, 31)
    
    #if defined COLORED_MESSAGES
    ColorChat(0, GREEN, "
[PTEPlayer ^3%^4donated to ^3%^1%^4minutes", szName, szName2, iAmount / 60)
    #else
    client_print(0, print_chat, "
[PTEPlayed %s donated to %%d minutes", szName, szName2, iAmount / 60)
    #endif
    
    return PLUGIN_HANDLED
}

public HookSaid(id)
{
    new szSaid[25]
    read_argv(1, szSaid, charsmax(szSaid))
    
    if( containi(szSaid, "
/top") != -1 && containi(szSaid, "_time") != -1 )
    {
        replace(szSaid, charsmax(szSaid), "
/top", ""); replace(szSaid, charsmax(szSaid), "_time", "")
        
        if(!is_str_num(szSaid))        // If it has more other words than /top*_time
            return PLUGIN_CONTINUE    // stop plugin and continue to show the words
            
        new iNum = str_to_num(szSaid)
        Top(id, iNum)
    }
    
    return PLUGIN_CONTINUE
}

#if SAVETYPE == SQL
CheckSqlConnection()
{
    g_hSql = SQL_MakeDbTuple(gsz_SQLINFO[HOST], gsz_SQLINFO[USER], gsz_SQLINFO[PASS], gsz_SQLINFO[DB])
    SQL_ThreadQuery(g_hSql, "
Query_Handler", "CREATE TABLE IF NOT EXISTS `played_time` (steamid VARCHAR(33), name VARCHAR(32), time INT)")
}
#endif

Top(id, NUM)
{
    if(NUM < 0)
        NUM *= -1
    
    new iSize
    #if SAVETYPE == SQL
    new iErrorCode, szError[50]
    new Handle:iConnection = SQL_Connect(g_hSql, iErrorCode, szError, charsmax(szError))
    new Handle:iQuery = SQL_PrepareQuery(iConnection, "
SELECT COUNT(*) FROM `played_time`")
    
    if(!SQL_Execute(iQuery))
        log_amx(szError)
    
    if(!SQL_MoreResults(iQuery))
    {
        #if defined COLORED_MESSAGES
        ColorChat(id, GREEN, "
[PTENo etnries yet")
        #else
        client_print(id, print_chat, "
[PTENo entries yet")
        #endif
        return;
    }
    
    iSize = SQL_ReadResult(iQuery, 0)
    
    SQL_FreeHandle(iConnection); SQL_FreeHandle(iQuery)
    #else
    new Vault2 = nvault_util_open("
played_time")
    iSize = nvault_util_count(Vault2)
    
    if(!iSize)
    {
        #if defined COLORED_MESSAGES
        ColorChat(id, GREEN, "
[PTENo etnries yet")
        #else
        client_print(id, print_chat, "
[PTENo entries yet")
        #endif
        nvault_util_close(Vault2)
        return;
    }
    
    nvault_util_close(Vault2)
    
    #endif
    
    if( NUM > iSize )
        NUM = iSize
    
    #if SAVETYPE == SQL
    new data[3]
    data[0] = id
    data[1] = NUM
    formatex(gsz_Query, charsmax(gsz_Query), "
SELECT FROM played_time ORDER BY time DESC LIMIT %d", NUM)
    SQL_ThreadQuery(g_hSql, "
FormatTop", gsz_Query, data, 1)
    #else
    FormatTop(id, NUM, iSize)
    #endif
}

#if SAVETYPE == SQL
public FormatTop(FailState, Handle:Query, Error[], Errcode, Data[], DataSize)
{
    if(FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED)
    {
        log_amx("
[SQL ERRORError on query: %s", Error)
        return;
    }
    
    new szMotd[1024], iLen, szName[32], iPlace, iTime
    iLen = formatex(szMotd, charsmax(szMotd), "
<body bgcolor=#000000><font color=#FFB00><pre>")
    
iLen += format(szMotd[iLen], charsmax(szMotd) - iLen,"%s %-22.22s %3s^n""#""Name""Time in minutes")
    
    while(
SQL_MoreResults(Query))
    {
        
SQL_ReadResult(Query1szNamecharsmax(szName))
        
iTime SQL_ReadResult(Query2)

        
replace_all(szNamecharsmax(szName), "<""&lt;")
        
replace_all(szNamecharsmax(szName), ">""&gt;")

        
iLen += formatex(szMotd[iLen], charsmax(szMotd) - iLen"%d %-22.22s %d^n", ++iPlaceszNameiTime 60)
        
SQL_NextRow(Query)
    }
    
    
iLen += formatex(szMotd[iLen], charsmax(szMotd) - iLen"</pre></font></body>")
    
    new 
szTitle[25]
    
formatex(szTitlecharsmax(szTitle), "Time Top%d"Data[1])
    
show_motd(Data[0], szMotdszTitle)
}
#else
public FormatTop(idiNum, const iSize)    // TOP Motd.... TY Exolent!
{    
    
enum _:VaultData
    
{
        
VD_Key[33],
        
VD_Value,
        
VD_szName[33]
    };
    
    new 
Vault2 nvault_util_open("played_time")
    
// create our array to hold entries and keep track of its size
    
new Array:entries ArrayCreate(VaultData);
    new 
sizeEntries
    
    
// count entries in vault and prepare variables
    
new data[VaultData], value[MAX_TIME_LENGTH], data2[VaultData]
    
// iterate through all entries
    
for(new 0postimestampiSizei++)
    {
        
// grab entry data from current position
        
pos nvault_util_read(Vault2posdata[VD_Key], charsmax(data[VD_Key]), valuecharsmax(value), timestamp);
        
        
/*for(new i; i < sizeof(data[VD_Key]); i++)
            if(!data[VD_Key][i])
                data[VD_Key][i] = EOS*/
    
        
if(contain(data[VD_Key], "-") != -1)
            continue;
        
        else
        {
            
formatex(data[VD_szName], charsmax(data[VD_szName]), "%s%s"data[VD_Key], SPECIAL_CHAR)
            
nvault_get(gVaultdata[VD_szName], data[VD_szName], charsmax(data[VD_szName]))
        }

        
// turn value string into integer
        
data[VD_Value] = str_to_num(value);
        
        
// if this is the first entry
        
if(sizeEntries == 0)
        {
            
// go ahead and add it
            
ArrayPushArray(entriesdata);
            
sizeEntries++;
            continue;
        }
        
        else
        {
            
// loop through other entries to see where this one should be placed (sorted from HIGH->LOW)
            
for(timestamp 0timestamp <= sizeEntriestimestamp++)
            {
                
// if we looped through all entries without finding a place
                
if(timestamp == sizeEntries)
                {
                    
// this entry value is too low to fit before any others
                    // if we have room at the end of the array
                    
if(sizeEntries iNum)
                    {
                        
// add it to the end
                        
ArrayPushArray(entriesdata);
                        
sizeEntries++;
                    }
                    
                    
// don't continue with code below
                    
break;
                }

                
                
// grab current entry to compare it with
                
ArrayGetArray(entriestimestampdata2);
                
                
// if this new entry should be placed before the compared entry
                
if(data[VD_Value] >= data2[VD_Value])
                {
                    
// insert before
                    
ArrayInsertArrayBefore(entriestimestampdata);
                    
                    
// if we aren't maxxed out
                    
if(sizeEntries iNum)
                    {
                        
// increase entry size
                        
sizeEntries++;
                    } 
                    else 
                    {
                        
// delete the last entry to keep the size at maximum
                        
ArrayDeleteItem(entriessizeEntries);
                    }
                    
                    break;
                }
            }
        }
    }
    
    new 
szMotd[1024], iLenlen charsmax(szMotd)
    
iLen formatex(szMotdlen"<body bgcolor=#000000><font color=#FFB00><pre>")
    
iLen += formatex(szMotd[iLen], len iLen"%s. %-22.22s %s^n""#""Name""Time in minutes")
    
    new 
i
    
for(0sizeEntriesi++)
    {
        
// grab current entry
        
ArrayGetArray(entriesidata);
        
        
// truncate entry key for output
        
data[VD_Key][32] = 0;
        
data[VD_szName][32] = 0
        
        replace_all
(data[VD_szName], charsmax(data[VD_szName]), "<""&lt;")
        
replace_all(data[VD_szName], charsmax(data[VD_szName]), ">""&gt;")
        
        
// display data
        
iLen += formatex(szMotd[iLen], len iLen"%d. %-22.22s %d^n", (i+1), data[VD_szName], data[VD_Value] / 60)
    }
    
    
// destroy the entry array from cache
    
ArrayDestroy(entries);
    
nvault_util_close(Vault2)
    
    
iLen += formatex(szMotd[iLen], len iLen"</pre></font></body>")
    new 
szTitle[50]; formatex(szTitlecharsmax(szTitle), "Time Top%d"i)
    
show_motd(idszMotdszTitle)
    
}
#endif

get_user_totaltime(id)
{
    new 
iNumszSavedName[32]
    new 
szName[32]; get_user_name(idszName31)
    new 
szAuthId[33]; get_user_authid(idszAuthIdcharsmax(szAuthId))
    
#if SAVETYPE == SQL
    
new iErrorCodeszError[50]
    new 
Handle:hConnection SQL_Connect(g_hSqliErrorCodeszErrorcharsmax(szError))
    new 
Handle:hQuery SQL_PrepareQuery(hConnection"SELECT * FROM `played_time` WHERE steamid='%s'"szAuthId)
    
    
SQL_Execute(hQuery)

    if(!
SQL_MoreResults(hQuery))
    {
        
formatex(gsz_Querycharsmax(gsz_Query), "INSERT INTO `played_time` VALUES ('%s', '%s', %d)"szAuthIdszName0)
        
SQL_ThreadQuery(g_hSql"Query_Handler"gsz_Query)
        
        
SQL_FreeHandle(hConnection); SQL_FreeHandle(hQuery)
        return 
iNum
    
}
    
    
SQL_ReadResult(hQuery2szSavedName31)
    
replace_all(szSavedNamecharsmax(szSavedName), "'""")
    
replace_all(szSavedNamecharsmax(szSavedName), "^"", "")
    
    if(!equal(szName, szSavedName))
        SQL_ThreadQuery(g_hSql, "
Query_Handler", "UPDATE `played_timeSET name '%s' WHERE name '%s'")
    
    iNum = SQL_ReadResult(hQuery, 2)
    SQL_FreeHandle(hConnection); SQL_FreeHandle(hQuery)
    
    #else
    if( !( iNum =  nvault_get(gVault, szAuthId) ) )
    {
        nvault_set(gVault, szAuthId, "
0")
        format(szAuthId, charsmax(szAuthId), "
%s%s", szAuthId, SPECIAL_CHAR)
        nvault_set(gVault, szAuthId, szName)
        return 0
    }
    
    format(szAuthId, charsmax(szAuthId), "
%s%s", szAuthId, SPECIAL_CHAR)
    nvault_get(gVault, szAuthId, szSavedName)
    if(!equal(szName, szSavedName))
    {
        nvault_remove(gVault, szAuthId)
        nvault_set(gVault, szAuthId, szName)
    }
    #endif
    
    return iNum
}

#if SAVETYPE == SQL
public Query_Handler(FailState, Handle:Query, Error[], Errcode, Data[], DataSize)
{
    if(FailState < 0)
        return log_amx("
%s", FailState == TQUERY_CONNECT_FAILED ? "Could not connect to SQL database." : "Query failed")
   
    if(Errcode)
        return log_amx("
Error on query: %s",Error)
    
    return -1    // Any number so we can get off the warning ...
}
#endif

// NATIVES
public native_get_user_played_time(const id)
{
    if(!is_user_connected(id) || is_user_hltv(id) || !id)
        return -1

    return g_iPlayedTime[id]
}
    
public native_set_user_played_time(const id, iNewTime)
{
    if(!is_user_connected(id) || is_user_hltv(id) || !id)
        return 1
    
    g_iPlayedTime[id] = iNewTime
    return 1
}

public native_get_save_type()
    return SAVETYPE

public plugin_end()
{
    #if SAVETYPE == SQL
    SQL_FreeHandle(g_hSql)
    #else
    nvault_close(gVault)
    #endif

But the problem is the saving type (not method) is not like each other, so the first plugin (that im using it now), it is saving and reading by column, but this one is saving and reading with another type, so I want to edit this plugin (played time extended) to read (and save) played times from SQL so I can switch from the first one to the second time (mine to played time extended).
Any help would be appreciated
Thanks
JoooN is offline
sami_spt
Veteran Member
Join Date: Sep 2012
Location: I<3 pussy cats
Old 07-28-2013 , 02:43   Re: [REQ] SQL Saving Type Edit
Reply With Quote #2

explain more .. what do u want?!


Why not use the extended plugin and done!
sami_spt is offline
JoooN
BANNED
Join Date: Jul 2013
Location: Ban List :P
Old 07-28-2013 , 03:30   Re: [REQ] SQL Saving Type Edit
Reply With Quote #3

Quote:
Originally Posted by sami_spt View Post
explain more .. what do u want?!


Why not use the extended plugin and done!
I was explaining more than 3 lines you can read it carefully to see what i'm saying..
Quote:
Originally Posted by JoooN View Post
But the problem is the saving type (not method) is not like each other, so the first plugin (that im using it now), it is saving and reading by column, but this one is saving and reading with another type, so I want to edit this plugin (played time extended) to read (and save) played times from SQL so I can switch from the first one to the second time (mine to played time extended).
Any help would be appreciated
Thanks
I can't change the plugin because I have too many accounts saved with the first plugin.
There are too many played times of users saved with the first plugin, so I wanna change the played time extended save type to the first plugin's .
Hope you understand that i'm not idiot describing this much cuz ofcourse I know I can switch and it is done but cuz many people played on my server and it is saved using the first plugin, so I wanna change pte save type to that one (I have too many users played time saved with the first plugin..)
EDIT: See this line:
Quote:
Originally Posted by JoooN View Post
Ok so here, I have too many users played time saved with this plugin:

Last edited by JoooN; 07-28-2013 at 03:33.
JoooN is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 07-28-2013 , 09:50   Re: [REQ] SQL Saving Type Edit
Reply With Quote #4

What do you mean by "saving type"? As far as I can tell, they are both saving my name (which is stupid since SteamID should be used)
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
sami_spt
Veteran Member
Join Date: Sep 2012
Location: I<3 pussy cats
Old 07-28-2013 , 12:11   Re: [REQ] SQL Saving Type Edit
Reply With Quote #5

1- TRUE! both plugins can save by nicknames.

2- If you want it to work, you need to play with database tables and stuff.
You need to edit the 2nd plugin's tables and database info to make it match with the 1st plugin's info and tables.
You might get errors, you might get problems, you might loose some played time players, but i dont care.. its your wish
sami_spt is offline
JoooN
BANNED
Join Date: Jul 2013
Location: Ban List :P
Old 07-28-2013 , 14:15   Re: [REQ] SQL Saving Type Edit
Reply With Quote #6

By saving type, I mean how it arranges the played time, imagine when you go to your sql database, you see this (with a plugin)
Mycsname. 1000(played time mins)
Mysecondcsname 2000
But another one arranges like this:
Mycsname. 1000 mysecondcsname 2000
So I wanna change the played time extended arrange type to the first one and I don't care either steamid or name. Hope you get me what I'm saying. I need someone to change to played time extended saving and reading arrangment so it can read from what I saved before with my first plugin..
So if you didn't get me tell me I will explain with pictures.
JoooN is offline
Old 07-28-2013, 15:18
sami_spt
This message has been deleted by sami_spt. Reason: wait.. reposting
sami_spt
Veteran Member
Join Date: Sep 2012
Location: I<3 pussy cats
Old 07-28-2013 , 15:21   Re: [REQ] SQL Saving Type Edit
Reply With Quote #7

show us a screenshot of what you are meaning..

does it show what u said in phpmyadmin?
sami_spt is offline
JoooN
BANNED
Join Date: Jul 2013
Location: Ban List :P
Old 07-28-2013 , 23:34   Re: [REQ] SQL Saving Type Edit
Reply With Quote #8

Quote:
Originally Posted by sami_spt View Post
show us a screenshot of what you are meaning..

does it show what u said in phpmyadmin?
Yes I mean PHPMyAdmin
Now, here see the first picture (I covered names)
So first played time plugin (the not extended one) saves and reads played times like that
But now (I cant upload it's picture because it is failing.. idk why) imagine instead of saving like that:
PHP Code:
user1  1000
user2    100000
user3     50000 
But the extended one saves like this:
PHP Code:
user1 1000 user2 3000 user3 5000 
So I wanna change how extended one reads and saves like that and change it so it will read like the first plugin:
PHP Code:
user1  1000
user2    100000
user3     50000 
But it cant read from that type so I want someone to edit that part and convert it like the first plugin (not extended one) so I can switch from this plugin to extended one (cuz I need it's features like donate, etc..)
EDIT: And yes, please make the extended one save by nickname cuz my server system is different cuz if a player comes with another name but with the same SteamID, people will be confused so how he has (let's say) 1000 minutes..
Attached Thumbnails
Click image for larger version

Name:	php.jpg
Views:	121
Size:	90.7 KB
ID:	123384  

Last edited by JoooN; 07-28-2013 at 23:38.
JoooN is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:15.


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