Czy dało by radę przerobić 2 poniższe pluginy (zapis i odczyt) z nvault na sql ?
Z góry wielkie dzięki
Plugin zapisu:
#include <amxmodx>
#include <nvault>
#define PLUGIN "Save Player's playing time"
#define VERSION "1.0"
#define AUTHOR "#Vaverix."
new czas_gry[33];
new g_vault;
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR);
register_clcmd("say /gametime","pokaz_czas_gry");
register_clcmd("say /playingtime","pokaz_czas_gry");
register_clcmd("say /czasgry","pokaz_czas_gry");
g_vault = nvault_open("SPPT");
if (g_vault == INVALID_HANDLE)
set_fail_state( "Nie udalo sie otworzyc pliku nvault!");
}
public client_connect(id)
{
wczytaj_czas_gry(id);
set_task(60.0, "pokaz_czas_gry", id,_,_,"b");
}
public client_disconnect(id)
{
zapisz_czas_gry(id);
czas_gry[id] = 0;
if(task_exists(id))
remove_task(id);
}
public wczytaj_czas_gry(id)
{
new name[35],vaultkey[64],vaultdata[256];
get_user_name(id,name,34);
format(vaultkey,63,"%s-gametime",name);
nvault_get(g_vault,vaultkey,vaultdata,255);
czas_gry[id] = str_to_num(vaultdata);
return PLUGIN_CONTINUE;
}
public zapisz_czas_gry(id)
{
new name[35],vaultkey[64],vaultdata[256];
get_user_name(id,name,34);
czas_gry[id] += get_user_time(id, 1);
format(vaultkey,63,"%s-gametime",name);
format(vaultdata, 255, "%d", czas_gry[id]);
nvault_set(g_vault,vaultkey,vaultdata)
czas_gry[id] = str_to_num(vaultdata);
return PLUGIN_CONTINUE;
}
public pokaz_czas_gry(id)
{
new sekundy = (czas_gry[id] + get_user_time(id, 1)), minuty, godziny;
while(sekundy >= 60)
{
sekundy -= 60;
minuty++;
}
while(minuty >= 60)
{
minuty -= 60;
godziny++;
}
client_print(id,print_chat,"Grasz juz %ih %imin %is na tym serwerze!", godziny, minuty, sekundy);
return PLUGIN_HANDLED;
}
public plugin_end()
nvault_close(g_vault);
I odczyt do tabeli top15:
#include <amxmodx>
#include <amxmisc>
#include <nvault_util>
#define PLUGIN "Top 15 Czasow"
#define VERSION "1.0"
#define AUTHOR "R3X"
new gszVault[] = "SPPT";
new Array:gTop15Time;
new Array:gTop15Nick;
new giLastBuild = 0;
new gcvarLifeTime;
new gszMotd[1024];
const giMax = sizeof gszMotd;
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR);
register_clcmd("say /czasy", "cmdTop15");
gTop15Time = ArrayCreate();
gTop15Nick = ArrayCreate(32);
gcvarLifeTime = register_cvar("amx_top15time_life", "3");
}
public cmdTop15(id){
if((get_gametime() - giLastBuild) > get_pcvar_num(gcvarLifeTime)){
buildTop15() || client_print(id, print_chat, "* Brak pliku z czasami");
}
show_motd(id, gszMotd, "Top15 Czasow Online");
return PLUGIN_HANDLED;
}
getFormatedTime(iTime, szTime[], size){
new hours = iTime/3600;
new days = hours/24;
if(days == 0)
formatex(szTime, size, "%02d:%02d:%02d", hours, iTime%3600/60, iTime%60);
else
formatex(szTime, size, "%ddni %02d:%02d:%02d", days, hours%24, iTime%3600/60, iTime%60);
}
buildTop15(){
ArrayClear(gTop15Time);
ArrayClear(gTop15Nick);
new iVault= nvault_util_open( gszVault );
if(!iVault)
return 0;
nvault_util_readall( iVault , "nvault_util_readall_fwd" );
nvault_util_close( iVault );
new iSize = ArraySize(gTop15Time);
new iLen = 0;
iLen += formatex(gszMotd[iLen], giMax-iLen, "<style>pre{margin: 1px;border-bottom:1px dashed grey}</style>");
iLen += formatex(gszMotd[iLen], giMax-iLen, "Gracze najdluzej przebywajacy na serwerze (gg:mm:ss)");
if(iSize == 0){
iLen += formatex(gszMotd[iLen], giMax-iLen, "<br><font color=red>brak</font>");
}else{
iLen += formatex(gszMotd[iLen], giMax-iLen, "<ol>");
new szName[32], iPlayTime, szPlayTime[32];
for(new i=0;i<iSize;i++){
ArrayGetString(gTop15Nick, i, szName, 31);
iPlayTime = ArrayGetCell(gTop15Time, i);
getFormatedTime(iPlayTime, szPlayTime, 31)
iLen += formatex(gszMotd[iLen], giMax-iLen, "<li><pre>%32s - %s</pre></li>", szName, szPlayTime);
}
iLen += formatex(gszMotd[iLen], giMax-iLen, "</ol>");
}
return 1;
}
get_user_nvaultname(const szKey[], szName[], size){
copy(szName, size, szKey);
new iLen = strlen(szKey);
if(iLen > 9){
szName[iLen-9] = '^0';
}
}
public nvault_util_readall_fwd( iCurrent , iTotal , const szKey[] , const szVal[]){
new szName[32];
new iPlayTime = str_to_num(szVal);
new iSize = ArraySize(gTop15Time);
if(iSize == 0){
ArrayPushCell(gTop15Time, iPlayTime);
get_user_nvaultname(szKey, szName, 31);
ArrayPushString(gTop15Nick, szName);
}else{
for(new i=0;i<iSize;i++){
if(iPlayTime > _:ArrayGetCell(gTop15Time, i)){
ArrayInsertCellBefore(gTop15Time, i, iPlayTime);
get_user_nvaultname(szKey, szName, 31);
ArrayInsertStringBefore(gTop15Nick, i, szName);
if(iSize >= 15){
ArrayDeleteItem(gTop15Time, 15);
ArrayDeleteItem(gTop15Nick, 15);
}
return;
}
}
if(iSize < 15){
ArrayPushCell(gTop15Time, iPlayTime);
get_user_nvaultname(szKey, szName, 31);
ArrayPushString(gTop15Nick, szName);
}
}
}