Here's an example top for SQLVault: Extended.
It is necessary to use extended because you need to save the players' names and whatever you are sorting them by (here will be frags).
Basic plugin structure to use vault:
Spoiler
Code:
#include < amxmodx >#include < fakemeta >#include < sqlvault_ex >#define MAX_PLAYERS 32new SQLVault:g_hVault;
new KEY_KILLS[] = "kills";
new KEY_NAME[] = "name";
new g_szSteamID[ MAX_PLAYERS + 1][35];
new g_iKills[ MAX_PLAYERS + 1];
public plugin_init(){// Register forward for name changing
register_forward( FM_ClientUserInfoChanged, "FwdClientInfoChanged");
// Open the vault
g_hVault = sqlv_open_local("top_example", false); // No auto-init so we can init for Extended
sqlv_init_ex( g_hVault );
}public plugin_end(){// Close the vault when the plugin is exiting
sqlv_close( g_hVault );
}public client_authorized( iPlayer ){// Cache player's Steam ID and load their killsget_user_authid( iPlayer, g_szSteamID[ iPlayer ], charsmax( g_szSteamID[]));
g_iKills[ iPlayer ] = sqlv_get_num_ex( g_hVault, g_szSteamID[ iPlayer ], KEY_KILLS );
}public client_disconnect( iPlayer ){// Only save player's kills if they were loadedif( g_szSteamID[ iPlayer ][0]){
sqlv_set_num_ex( g_hVault, g_szSteamID[ iPlayer ], KEY_KILLS, g_iKills[ iPlayer ]);
// Empty out Steam ID so kills cannot be saved until they are loaded again
g_szSteamID[ iPlayer ][0] = EOS;
}}public FwdClientInfoChanged( iPlayer ){// Don't do any name checking if player was not loaded for the vaultif( !g_szSteamID[ iPlayer ][0]){return FMRES_IGNORED;
}// Code from ConnorMcLeod:// If you don't have a pev_netname and you have a "name" setinfo value, then this is the first name you send to the server// Otherwise, you should check for name changing.new szOldName[32], szNewName[32];
pev( iPlayer, pev_netname, szOldName, charsmax( szOldName ));
get_user_info( iPlayer, "name", szNewName, charsmax( szNewName ));
if( !szOldName[0] && szNewName[0]
|| szOldName[0] && is_user_alive( iPlayer ) && !equal( szOldName, szNewName )){// Store new name in the vault
sqlv_set_data_ex( g_hVault, g_szSteamID[ iPlayer ], KEY_NAME, szNewName );
}return FMRES_IGNORED;
}
Now, let's add the top to it:
Spoiler
Code:
#define MAX_TOP 10public plugin_init(){// Register top commandsregister_clcmd("say /top" , "CmdTop");
register_clcmd("say /top10", "CmdTop");
register_clcmd("say /top15", "CmdTop");
}public CmdTop( iPlayer ){// Cache the database connection since we are calling sqlv_* functions more than once
sqlv_connect( g_hVault );
// Make sure we are only choosing the kills for sorting and we are sorting highest to lowestnew szWhere[32];
formatex( szWhere, charsmax( szWhere ), "`key2` = '%s'", KEY_KILLS );
new eTopData[ MAX_TOP ][ SQLVaultEntryEx ];
new iNumTop = sqlv_read_set_ex( g_hVault, eTopData, sizeof( eTopData ), _, szWhere, "`data` DESC");
// Loop through all top for formatting the MOTDstatic szMOTD[2048], szName[125];
new iLen = copy( szMOTD, charsmax( szMOTD ), "<table><tr><th>#.</th><th>Name</th><th>Kills</th></tr>");
for(new i = 0; i < iNumTop; i++ ){// Grab the name that is associated with this Steam ID// Note: The Steam ID is always key1 when we are saving/loading in this plugin
sqlv_get_data_ex( g_hVault, eTopData[ i ][ SQLVEx_Key1 ], KEY_NAME, szName, charsmax( szName ));
// Fix the name for HTML charactersreplace_all( szName, charsmax( szName ), "&", "&");
replace_all( szName, charsmax( szName ), "<", "<");
replace_all( szName, charsmax( szName ), ">", ">");
// Display the top// Note: Vault entries always give data back as strings
iLen += formatex( szMOTD[ iLen ], charsmax( szMOTD ) - iLen, "<tr><td>%d.</td><td>%s</td><td>%s</td></tr>", ( i + 1), szName, eTopData[ i ][ SQLVEx_Data ]);
}copy( szMOTD[ iLen ], charsmax( szMOTD ) - iLen, "</table>");
show_motd( iPlayer, szMOTD, "Top Players");
// We are done with the vault's cached connection, so disconnect now
sqlv_disconnect( g_hVault );
}
All together:
Spoiler
Code:
#include < amxmodx >#include < fakemeta >#include < sqlvault_ex >#define MAX_PLAYERS 32#define MAX_TOP 10new SQLVault:g_hVault;
new KEY_KILLS[] = "kills";
new KEY_NAME[] = "name";
new g_szSteamID[ MAX_PLAYERS + 1][35];
new g_iKills[ MAX_PLAYERS + 1];
public plugin_init(){// Register forward for name changing
register_forward( FM_ClientUserInfoChanged, "FwdClientInfoChanged");
// Register top commandsregister_clcmd("say /top" , "CmdTop");
register_clcmd("say /top10", "CmdTop");
register_clcmd("say /top15", "CmdTop");
// Open the vault
g_hVault = sqlv_open_local("top_example", false); // No auto-init so we can init for Extended
sqlv_init_ex( g_hVault );
}public plugin_end(){// Close the vault when the plugin is exiting
sqlv_close( g_hVault );
}public client_authorized( iPlayer ){// Cache player's Steam ID and load their killsget_user_authid( iPlayer, g_szSteamID[ iPlayer ], charsmax( g_szSteamID[]));
g_iKills[ iPlayer ] = sqlv_get_num_ex( g_hVault, g_szSteamID[ iPlayer ], KEY_KILLS );
}public client_disconnect( iPlayer ){// Only save player's kills if they were loadedif( g_szSteamID[ iPlayer ][0]){
sqlv_set_num_ex( g_hVault, g_szSteamID[ iPlayer ], KEY_KILLS, g_iKills[ iPlayer ]);
// Empty out Steam ID so kills cannot be saved until they are loaded again
g_szSteamID[ iPlayer ][0] = EOS;
}}public FwdClientInfoChanged( iPlayer ){// Don't do any name checking if player was not loaded for the vaultif( !g_szSteamID[ iPlayer ][0]){return FMRES_IGNORED;
}// Code from ConnorMcLeod:// If you don't have a pev_netname and you have a "name" setinfo value, then this is the first name you send to the server// Otherwise, you should check for name changing.new szOldName[32], szNewName[32];
pev( iPlayer, pev_netname, szOldName, charsmax( szOldName ));
get_user_info( iPlayer, "name", szNewName, charsmax( szNewName ));
if( !szOldName[0] && szNewName[0]
|| szOldName[0] && is_user_alive( iPlayer ) && !equal( szOldName, szNewName )){// Store new name in the vault
sqlv_set_data_ex( g_hVault, g_szSteamID[ iPlayer ], KEY_NAME, szNewName );
}return FMRES_IGNORED;
}public CmdTop( iPlayer ){// Cache the database connection since we are calling sqlv_* functions more than once
sqlv_connect( g_hVault );
// Make sure we are only choosing the kills for sorting and we are sorting highest to lowestnew szWhere[32];
formatex( szWhere, charsmax( szWhere ), "`key2` = '%s'", KEY_KILLS );
new eTopData[ MAX_TOP ][ SQLVaultEntryEx ];
new iNumTop = sqlv_read_set_ex( g_hVault, eTopData, sizeof( eTopData ), _, szWhere, "`data` DESC");
// Loop through all top for formatting the MOTDstatic szMOTD[2048], szName[125];
new iLen = copy( szMOTD, charsmax( szMOTD ), "<table><tr><th>#.</th><th>Name</th><th>Kills</th></tr>");
for(new i = 0; i < iNumTop; i++ ){// Grab the name that is associated with this Steam ID// Note: The Steam ID is always key1 when we are saving/loading in this plugin
sqlv_get_data_ex( g_hVault, eTopData[ i ][ SQLVEx_Key1 ], KEY_NAME, szName, charsmax( szName ));
// Fix the name for HTML charactersreplace_all( szName, charsmax( szName ), "&", "&");
replace_all( szName, charsmax( szName ), "<", "<");
replace_all( szName, charsmax( szName ), ">", ">");
// Display the top// Note: Vault entries always give data back as strings
iLen += formatex( szMOTD[ iLen ], charsmax( szMOTD ) - iLen, "<tr><td>%d.</td><td>%s</td><td>%s</td></tr>", ( i + 1), szName, eTopData[ i ][ SQLVEx_Data ]);
}copy( szMOTD[ iLen ], charsmax( szMOTD ) - iLen, "</table>");
show_motd( iPlayer, szMOTD, "Top Players");
// We are done with the vault's cached connection, so disconnect now
sqlv_disconnect( g_hVault );
}
Player names dont show , It only shows when a player changes his name.
PHP Code:
new eTopData[ MAX_TOP ][ SQLVaultEntryEx ];
^Gives stack error
Quote:
Originally Posted by Exolent[jNr]
That is a very large variable. If you see the enum in the include file, the struct for vault entries contains large arrays.
To fix this, make the variable static so it isn't created and destroyed each time, thus always staying in the stack and not causing errors when out of memory.
Player names dont show , It only shows when a player changes his name.
PHP Code:
new eTopData[ MAX_TOP ][ SQLVaultEntryEx ];
^Gives stack error
Quote:
Originally Posted by Exolent[jNr]
That is a very large variable. If you see the enum in the include file, the struct for vault entries contains large arrays.
To fix this, make the variable static so it isn't created and destroyed each time, thus always staying in the stack and not causing errors when out of memory.
I tried the top15 above , if i get 11 kills and another player has 2 kills , my rank comes below his.
If i have 15 kills and another player has 2 kills , his rank still comes above mine , its like only 1 is getting counted out of 1 5
I tried the top15 above , if i get 11 kills and another player has 2 kills , my rank comes below his.
If i have 15 kills and another player has 2 kills , his rank still comes above mine , its like only 1 is getting counted out of 1 5
For some reason, when using non-local databases, this creates a local database instead using SQLite. I give it all the information for an external database, but it seems to ignore that and make a local one instead.
new g_szName[MAX_PLAYERS+1][32] new g_iLastPlayedTime[MAX_PLAYERS+1]
public plugin_init() { register_plugin("Time", "0.1", "ConnorMcLeod") register_dictionary("time.txt")
g_iVault = nvault_open("played_time") }
public plugin_end() nvault_close( g_iVault )
public client_authorized( id ) { new szTime[32] get_user_name(id, g_szName[id], charsmax(g_szName[])) nvault_get(g_iVault, g_szName[id], szTime, charsmax(szTime)) g_iLastPlayedTime[id] = str_to_num(szTime) }
get_user_total_playtime( id ) { return g_iLastPlayedTime[id] + get_user_time(id) }
public client_disconnect( id ) { new szTime[32] formatex(szTime, charsmax(szTime), "%d", get_user_total_playtime( id )) nvault_set(g_iVault, g_szName[id], szTime) }
I want to get data from played_time.vault in valut folder and this data needs to transfer to site, but how ? I don't want to change save method. I just want to save by nvault, but this data show in site.
I cant compile any plugin that use sqlvault!
Welcome to the AMX Mod X 1.76-300 Compiler.
Copyright (c) 1997-2006 ITB CompuPhase, AMX Mod X Team
D:\kompiler\include\sqlvault.inc(81) : error 017: undefined symbol "TrieCreate"
D:\kompiler\include\sqlvault.inc(81) : warning 213: tag mismatch
D:\kompiler\include\sqlvault.inc(83) : error 017: undefined symbol "TrieSetCell"
D:\kompiler\include\sqlvault.inc(84) : error 017: undefined symbol "TrieSetString"
D:\kompiler\include\sqlvault.inc(92) : error 017: undefined symbol "TrieDestroy"
D:\kompiler\include\sqlvault.inc(207) : error 017: undefined symbol "TrieGetCell"
D:\kompiler\include\sqlvault.inc(211) : error 017: undefined symbol "TrieGetCell"
D:\kompiler\include\sqlvault.inc(216) : error 017: undefined symbol "TrieDestroy"
D:\kompiler\include\sqlvault.inc(331) : error 017: undefined symbol "TrieGetCell"
D:\kompiler\include\sqlvault.inc(340) : error 017: undefined symbol "TrieGetCell"
D:\kompiler\include\sqlvault.inc(355) : error 017: undefined symbol "TrieGetString"
D:\kompiler\include\sqlvault.inc(355) : error 088: number of arguments does not match definition
D:\kompiler\include\sqlvault_ex.inc(47) : error 017: undefined symbol "TrieGetCell"
D:\kompiler\include\sqlvault_ex.inc(56) : error 017: undefined symbol "TrieGetCell"
D:\kompiler\include\sqlvault_ex.inc(71) : error 017: undefined symbol "TrieGetString"
D:\kompiler\include\sqlvault_ex.inc(71) : error 088: number of arguments does not match definition
D:\kompiler\include\sqlvault_ex.inc(12 : error 017: undefined symbol "TrieGetCell"
D:\kompiler\include\sqlvault_ex.inc(137) : error 017: undefined symbol "TrieGetCell"
D:\kompiler\include\sqlvault_ex.inc(152) : error 017: undefined symbol "TrieGetString"
D:\kompiler\include\sqlvault_ex.inc(152) : error 088: number of arguments does not match definition
D:\kompiler\include\sqlvault_ex.inc(279) : error 017: undefined symbol "TrieGetCell"
D:\kompiler\include\sqlvault_ex.inc(28 : error 017: undefined symbol "TrieGetCell"
D:\kompiler\include\sqlvault_ex.inc(303) : error 017: undefined symbol "TrieGetString"
D:\kompiler\include\sqlvault_ex.inc(303) : error 088: number of arguments does not match definition