Writing to file help
I've made a plugin that writes player's times to a file when they complete a KZ map and displays it to players who type /top15 or /top.
But when a player completes a map twice, his name and time appear twice in the list. I want to replace the old line with the new one when that happens.
Wrote this code, but it often does not write anything at all:
PHP Code:
new omg[3][32] new text[72][32]
TimerStop( id ) //player finished the map { g_bStarted[ id ] = false; if ( g_bHasTimer[ id ] ) { new name[32] get_user_name(id, name,31) client_print( id, print_chat, "Zavrsio si mapu za %d:%s%d", g_iMinutes[ id ], g_iSeconds[ id ] < 10 ? "0" : "", g_iSeconds[ id ] ); g_bHasTimer[ id ] = false; format(text[id], 73, "<br>%s -------- %d:%s%d", name, g_iMinutes[ id ], g_iSeconds[ id ] < 10 ? "0" : "", g_iSeconds[ id ]) set_task(5.0, "hook", id) new iFilePos; new szLineItem[ 64 ]; new iFileHandle = fopen( "Vremena.txt" , "r+t" );
iFilePos = 0;
while ( !feof( iFileHandle ) ) { fgets( iFileHandle , szLineItem , charsmax( szLineItem ) );
iFilePos++; if(contain( szLineItem , name) != -1 ) { write_file("Vremena.txt", text[id] , iFilePos - 1 ); format(omg[id], 2, "1") break; } } fclose(iFileHandle); set_task(2.0, "obrisi", id) } return PLUGIN_HANDLED }
public obrisi(id) { if(equal(omg[id], "1")) { //don't like booleans :) omg[id][0] = 0 text[id][0] = 0 return PLUGIN_HANDLED } write_file("Vremena.txt", text[id]) text[id][0] = 0
return PLUGIN_HANDLED }
|