|
AMXX Moderator: Others
Join Date: Sep 2007
Location: Street
|

06-03-2010
, 02:02
Need help for a top15 code (specially on sorting part)
|
#1
|
Hi,
Well, nothing... i am doing a surf plugin, but i had some problems and doubts of top15 part... specially on the sorting, i saw a lot of plugin with top15 system but... didn't understand at all, the part of sorting the records (best time first, then second, etc...)
I am using a method with the native SortStrings, and i am posting here becouse i don't know if is a good method... and if you correct me others things about the top15 code, would be good to.
The code is not completed, but well... here is it:
PHP Code:
SaveRecord(id, const name[], Float:Time, weapon) { if(fBestTime[id] != 0.0) { if(Time >= fBestTime[id]) return; } //get_mapname(mapName, 31); new topPath[192]; GetFile(topPath, TOP_15); if(!dir_exists(topPath) ) mkdir(topPath); format(topPath, 191, "%s/%s_%s.cfg", topPath, ProRecord[id] ? "pro" : "nub", mapName); if(!file_exists(topPath) ) fclose(fopen(topPath, "wt") ); static szSteam[32], szDate[32]; get_user_authid(id, szSteam, 31); get_time("%m/%d/%Y", szDate, 31); static szData[256]; if(!fBestTime[id]) { formatex(szData, 127, "^"%f^" ^"%s^" ^"%s^" ^"%s^" ^"%d^" ^"%s^" ^"%s^" ^n", Time, szSteam, name, WeaponsName[weapon], gGocheckCount[id], "country", szDate); write_file(topPath, szData); return; } if(Time < fBestTime[id]) { static oldTime[12], getSteam[32], iLine = 0, iLen = 0; while(read_file(topPath, iLine, szData, 255, iLen) ) { if(szData[0] == ';' || szData[1] == '/' && szData[1] == '/' || !iLen) continue; parse(szData, oldTime, 11, getSteam, 31); if(equal(getSteam, szSteam) ) { formatex(szData, 255, "^"%f^" ^"%s^" ^"%s^" ^"%s^" ^"%d^" ^"%s^" ^"%s^" ^n", Time, szSteam, name, WeaponsName[weapon], gGocheckCount[id], "country", szDate); write_file(topPath, szData, iLine); break; } iLine++; } } if(file_size(topPath, 1) > 1) SortTop15(topPath); return; }
SortTop15(const FileName[]) { static szLine[256], iLine, iLen, increment; while(read_file(FileName, iLine++, szLine, 255, iLen) ) { if(!strlen(szLine) ) continue; copy(SaveTop15[increment], 255, szLine); increment++; } SortStrings(SaveTop15, 15, Sort_Descending); delete_file(FileName); for(new i = 0; i < increment; i++) { formatex(szLine, 255, "%s", SaveTop15[i]); write_file(FileName, szLine); } }
LoadRecord(id) { new topPath[192]; GetFile(topPath, TOP_15); format(topPath, 191, "%s/pro_%s.cfg", topPath, mapName); if(!file_exists(topPath) ) return; static szLine[256], szSteam[32], getSteam[32], getTime[14]; get_user_authid(id, szSteam, 31); static iLine, iLen; while(read_file(topPath, iLine++, szLine, 255, iLen) ) { parse(szLine, getTime, 13, getSteam, 31); if(equal(szSteam, getSteam) ) { fBestTime[id] = str_to_float(getTime); BestTime[id] = floatround(fBestTime[id]); return; } } format(topPath, 191, "%s/nub_%s.cfg", topPath, mapName); while(read_file(topPath, iLine++, szLine, 255, iLen) ) { parse(szLine, getTime, 13, getSteam, 31); if(equal(szSteam, getSteam) ) { fBestTime[id] = str_to_float(getTime); BestTime[id] = floatround(fBestTime[id]); return; } } return; }
Sry, my english isn't very good.
Thanks
__________________
Approved Plugins - Steam Profile
Public non-terminated projects:
All Admins Menu, HLTV parameters, Subnick,
Second Password (cool style), InfoZone,
Binary C4 plant/defuse, and more...
Private projects:
NoSpec (+menu), NV Surf Management,
PM Adanved System, KZ longjump2, and more...
Last edited by Alucard^; 06-03-2010 at 02:04.
|
|