Raised This Month: $ Target: $400
 0% 

Replacing line in file


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
djmd378
Senior Member
Join Date: Sep 2004
Old 05-14-2007 , 03:53   Re: Replacing line in file
Reply With Quote #8

Strange, with the chopped version, it doesn't give me that error anymore. Although It freezes the server when someone else uses the "write"command after someone already did it. But I fixed that. Also for some reason it ONLY replaces the first line.

Heres the code
Code:
#include <amxmodx> #include <amxmisc> new filename[256] new parsedsteamid[32], parsedname[32], parsednumber[32] new readdata[512] new a = 0, pos = 0 public plugin_init() {         register_plugin("test", "0.1", "test")         get_configsdir(filename,255)         format(filename,255,"%s/list.txt",filename)         register_clcmd("say replace", "filereplacetest", 0)         register_clcmd("say write", "filewritetest", 0)         delete_file(filename) } // Things from here on are my own stuff public filewritetest(id) {         new writedata[128]         new steamid[32],name[32]                 get_user_authid(id,steamid,31)         get_user_name(id,name,31)         if (file_exists(filename)) {                 while(read_file(filename, pos, readdata, 1023, a)) {                         parse(readdata,parsedsteamid,31,parsedname,31,parsednumber,31)                         if(equal(steamid,parsedsteamid)) {                                 formatex(writedata,127,"%s %s %s1^n", parsedsteamid, parsedname, parsednumber)                                 write_file(filename,writedata)                                 break                         }                         formatex(writedata,127,"%s %s 1^n",steamid,name)                         write_file(filename,writedata)                         break                 }                 return PLUGIN_HANDLED         }         formatex(writedata,127,"%s %s 1^n",steamid,name)         write_file(filename,writedata)         return PLUGIN_HANDLED } // Your stuff + some of mine stuff public filereplacetest(id) {         new line, len         while(read_file(filename, line++, readdata, 511, len) )         {                 parse(readdata,parsedsteamid,31,parsedname,31,parsednumber,31)                 if (contain(readdata, parsedsteamid) != -1 )                 {                          new msg[256]                         format(msg, 255, "%s %s %s1", parsedsteamid, parsedname, parsednumber)                         replace(readdata, 511, readdata, msg)                         write_file(filename, readdata, line - 1)                         client_print(0, print_chat, "Written")                         return PLUGIN_HANDLED                 }         }         return PLUGIN_HANDLED }
__________________
djmd378 is offline
 



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 10:38.


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