Raised This Month: $ Target: $400
 0% 

Replacing a line (or a value in that line) in an ini file...


Post New Thread Reply   
 
Thread Tools Display Modes
MattOG
Senior Member
Join Date: May 2005
Old 01-28-2006 , 14:29  
Reply With Quote #11

Quote:
Originally Posted by Suicid3
look at my one name plugin...as soon as Suzuka fixes arrayx it will be changed but for now its just a file.
ok cheers...
__________________

+Karma If I helped
MattOG is offline
MattOG
Senior Member
Join Date: May 2005
Old 01-29-2006 , 06:39  
Reply With Quote #12

ok, i figured i'd write a smaller plugin to test the parsing of the file first. I've got the below, but for some reason am always shown the map isn't found. It shows the correct name, and the name is definetly in the file, so.... wtf have i done this time???

p.s. thx in advance ;)

::EDIT::
NVM I'm thick, it checked the first line, didn't find a match, so reported that, and ended the checking *doh!* removed the "else ......." and going ok so far....

Code:
#include <amxmodx> #include <amxmisc> new testpath[64] new testfile[101] public plugin_init() {     register_plugin("Testline","1.0","MattOG")     register_concmd("line","checkline",ADMIN_BAN,"Tells u the line number")         get_configsdir(testpath,63)     format(testfile,100,"%s/testfile.ini",testpath) } public checkline(id) {     if(!file_exists(testfile))     {         client_print(id,print_chat,"%s not found",testfile)         console_print(id,"%s not found",testfile)         return PLUGIN_HANDLED     }         new readdata[64],currentmap[33],map[33],linenum[7],len=0,line=0     get_mapname(currentmap,32)     while(read_file(testfile, line++, readdata, 63, len))     {         parse(readdata,map,32)         if (equali(map,currentmap))         {             num_to_str((line-1),linenum,6)             client_print(id,print_chat,"%s, %d",map,linenum)             console_print(id,"%s, %d",map,linenum)             return PLUGIN_CONTINUE         }         else         {             client_print(id,print_chat,"The map '%s' wasn't found",currentmap)             console_print(id,"The map '%s' wasn't found",currentmap)             return PLUGIN_CONTINUE         }     }     return PLUGIN_CONTINUE }

Quote:
Originally Posted by testfile.ini
de_chateau_cz
de_aztec_cz
cs_1337_assault
de_cbble_cz
cs_italy_cz
de_trainyard_cz
de_nuke
de_dust2_cz
cs_office_cz
de_dust_cz
cs_assault_sk_light
de_inferno_cz
de_nuke_cz
de_prodigy_cz
cs_militia_cz
__________________

+Karma If I helped
MattOG is offline
Marticus
Member
Join Date: Nov 2004
Old 01-29-2006 , 10:29  
Reply With Quote #13

I am glad that you worked it out and am also curious to see your final product. In fact, it would be a viable replacement for forum-based map voting systems because the polls don't really speak for the entire server community as not everyone uses the forums. Although opening up the rating system to everyone would be a bad thing because of the transient players, this might be useful with a plugin or function that logs and checks for the regularity in a player's visits. Then only those who have played the map n number of times or who have put in n number of hours on the server or n number of days, et cetera.

Anyway, these are just some ideas in case you are still brainstorming. You didn't really explain the purpose of the plugin, but I understand that is beyond the scope of this forum.
Marticus is offline
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 01-29-2006 , 13:03  
Reply With Quote #14

here is the fixed version of the code you gave earlier. as long as ratepath and ratefile are not global this will work.
Code:
public rategood(id,level,cid) {     if(!cmd_access(id,level,cid,1))                                                      //     {                                                                                    //Only needed if you only want         client_print(0,print_center,"[RATEMAP]:You don't have access to this command")    //admins to be able to rate maps.         return PLUGIN_HANDLED                                                         //     }         if(!g_rateon)     {         client_print(0,print_center,"[RATEMAP]: Map Rating Is Currently OFF")         return PLUGIN_HANDLED     }     if(g_hasrated[id]==true)     {         client_print(id,print_chat,"[RATEMAP]: You Have Already Voted For This Map")         return PLUGIN_HANDLED     }     new readdata[64], currentmap[32], map[31], len, i, good[6], bad[6], percent[6]        new newgood, Float:newpercent, total, bool:cont = true     new newline[133], maprating[3], ratefile[101] , ratepath[91]     g_hasrated[id] = true     get_mapname(currentmap,31)     get_configsdir(ratepath , 90)     format(ratefile,100,"%s/ratefile.ini",ratepath)     while(read_file(ratefile, i, readdata, 63, len))     {         parse(readdata,map,31,good,5,bad,5,percent,5)         //the if statment has to be in the while loop not outside it.         if (equal(map,currentmap))         {             maprating[0] = str_to_num(good)             maprating[1] = str_to_num(bad)             maprating[2] = str_to_num(percent)                     newgood = (maprating[0] + 1)             total = (newgood + maprating[1])             newpercent = ( float(newgood/total)*100)                 format(newline,132,"%s %d %d %d^n",currentmap,newgood,maprating[1],newpercent)             write_file(ratefile,newline,i)             cont = false  //so it wont add as new below.             break         }         i++     }     if(cont)  //map wasn't in file, this is first vote.     {         //Start all from scratch         maprating[0] = 0         maprating[1] = 0         maprating[2] = 0                 newgood = (maprating[0] + 1)         total = (newgood + maprating[1])         newpercent = (float(newgood/total)*100)                         format(newline,132,"%s %d %d %d^n",currentmap,newgood,maprating[1],newpercent)         write_file(ratefile,newline)     }     client_print(id,print_chat,"[RATEMAP]: THANK YOU, YOU RATED THIS MAP AS GOOD")     return PLUGIN_CONTINUE } public ratebad(id,level,cid) {     if(!cmd_access(id,level,cid,1))                                                      //     {                                                                                    //Only needed if you only want         client_print(0,print_center,"[RATEMAP]:You don't have access to this command")    //admins to be able to rate maps.         return PLUGIN_HANDLED                                                             //     }         if(!g_rateon)     {         client_print(0,print_center,"[RATEMAP]: Map Rating Is Currently OFF")         return PLUGIN_HANDLED     }         if(g_hasrated[id]==true)     {         client_print(id,print_chat,"[RATEMAP]: You Have Already Voted For This Map")         return PLUGIN_HANDLED     }     new readdata[64], currentmap[32], map[31], len, i, good[6], bad[6], percent[6]        new newbad, Float:newpercent, total, bool:cont = true     new newline[133], maprating[3], ratefile[101] , ratepath[91]     g_hasrated[id] = true     get_mapname(currentmap,31)     get_configsdir(ratepath , 90)     format(ratefile,100,"%s/ratefile.ini",ratepath)     while(read_file(ratefile, i, readdata, 63, len))     {         parse(readdata,map,31,good,5,bad,5,percent,5)         if (equal(map,currentmap))         {             maprating[0] = str_to_num(good)             maprating[1] = str_to_num(bad)             maprating[2] = str_to_num(percent)                         newbad = (maprating[1] + 1)             total = (maprating[0] + newbad)             newpercent = (float(maprating[0]/total)*100)                     format(newline,132,"%s %d %d %d^n",currentmap,maprating[0],newbad,newpercent)             write_file(ratefile,newline,i)             cont = false             break         }         i++     }     if(cont)  //map wasn't in file, this is first vote.     {         maprating[0] = 0         maprating[1] = 0         maprating[2] = 0                 newbad = (maprating[1] + 1)         total = (maprating[0] + newbad)         newpercent = (float(maprating[0]/total)*100)                 format(newline,132,"%s %d %d %d^n",currentmap,maprating[0],newbad,newpercent)         write_file(ratefile,newline)     }     client_print(id,print_chat,"[RATEMAP]: THANK YOU, YOU RATED THIS MAP AS BAD")     return PLUGIN_CONTINUE }
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
MattOG
Senior Member
Join Date: May 2005
Old 01-31-2006 , 07:25  
Reply With Quote #15

Quote:
Originally Posted by Suicid3
here is the fixed version of the code you gave earlier.
Cheers suicide, I had already re-writeen the other half of the plugin when you posted this mate, finished and working now..... Thanks anyways.
__________________

+Karma If I helped
MattOG is offline
Reply



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


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