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
}