Raised This Month: $ Target: $400
 0% 

Writing to file help


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Desikac
Senior Member
Join Date: Apr 2010
Location: Serbia
Old 03-30-2011 , 17:39   Writing to file help
Reply With Quote #1

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]

TimerStopid //player finished the map
{
    
g_bStartedid ] = false;
    
    if ( 
g_bHasTimerid ] )
    {
        new 
name[32]
        
get_user_name(idname,31)
        
client_printidprint_chat"Zavrsio si mapu za %d:%s%d"g_iMinutesid ], g_iSecondsid ] < 10 "0" ""g_iSecondsid ] );
        
g_bHasTimerid ] = false;
        
format(text[id], 73"<br>%s -------- %d:%s%d"nameg_iMinutesid ], g_iSecondsid ] < 10 "0" ""g_iSecondsid ])
        
set_task(5.0"hook"id)
        
        
        new 
iFilePos;
            new 
szLineItem64 ];
    
            new 
iFileHandle fopen"Vremena.txt" "r+t" );

            
iFilePos 0;

            while ( !
feofiFileHandle ) )
            {
                
fgetsiFileHandle szLineItem charsmaxszLineItem ) );

                
iFilePos++;
        
                if(
containszLineItem name) != -)
                {
                    
write_file("Vremena.txt"text[id] , iFilePos );
                    
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


Last edited by Desikac; 03-30-2011 at 17:50.
Desikac is offline
Send a message via MSN to Desikac Send a message via Skype™ to Desikac
 


Thread Tools
Display Modes

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 14:29.


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