Code:
//thanks to superheromod for exp loading.
public LoadLevels() {
new file[128];
get_configsdir(file, 127);
formatex(file, 127, "%s/avp/avp.ini", file);
if(!file_exists(file)) create_levels_ini();
new readLine = 0;
new data[1024], tag[20], lengthRead;
new numLevels[6], loadCount = -1;
new XP[1024];
new LeftXP[32];
while((readLine = read_file(gSHFile, readLine, data, 1023, lengthRead)) != 0) {
if(equal(data[0], ";")) continue;
if(equali(data[0], "MAXLEVELS", 9)) {
parse(data, tag, 19, numLevels, 5)
} else if((equali(data[0],"EXP_NEEDED",8)) {
copy(XP, 1023, data)
}
}
if(strlen(numLevels) == 0) {
avp_log("ERROR: No MAXLEVELS data was found, aborting avp.ini loading");
avp_log("ERROR: Unable to find MAXLEVELS data, creating default avp.ini");
create_levels_ini();
}
else if(strlen(XP) == 0) {
avp_log("ERROR: No EXP_NEEDED data was found, aborting avp.ini loading");
avp_log("ERROR: Unable to find EXP_NEEDED data, creating default avp.ini");
create_levels_ini();
}
avp_log("NOTICE: avp.ini Loading was successful, checking data.");
gNumLevels = str_to_num(numLevels);
//This prevents variables from getting overflown
if(gNumLevels > MAXLEVELS) {
avp_log("ERROR: MAXLEVELS as defined in avp.ini is larger than MAXLEVELS in plugin!");
avp_log("ERROR: MAXLEVELS as defined in avp.ini too large, reducing to MAXLEVELS defined in plugin.");
gNumLevels = SH_MAXLEVELS
}
//Get the data tag out of the way
strbrkqt(XP, LeftXP, 31, XP, 1023);
while(strlen(XP) > 0 && loadCount < gNumLevels ) {
loadCount++
strbrkqt(XP, LeftXP, 31, XP, 1023)
gXPLevel[loadCount] = str_to_num(LeftXP);
if (loadCount > 0 && gXPLevel[loadCount] < gXPLevel[loadCount - 1]) {
avp_log("ERROR: Level %d is less XP than the level before it (%d < %d), adjusting MAXLEVELS to %d", loadCount, gXPLevel[loadCount], gXPLevel[loadCount - 1], loadCount - 1);
gNumLevels = loadCount - 1;
break;
}
avp_log("NOTICE: XP Loaded - MAXLEVELS: %d - EXP_NEEDED: %d",loadCount,gXPLevel[loadCount]);
}
if(loadCount < gNumLevels) {
avp_log("ERROR: Ran out of levels to load, check your avp.ini for errors. Adjusting MAXLEVELS to %d", loadCount);
gNumLevels = loadCount;
}
}
publiccreate_levels_ini() {
new file[128];
get_configsdir(file, 127);
formatex(file, 127, "%s/avp/avp.ini", file);
if(file_exists(file)) delete_file(file)
write_file(file,";AvP Levels", 0);
write_file(file,";MAXLEVELS is the amount of levels you can acheive", 1);
write_file(file,";EXP_NEEDED is the amount of exp needed for each level", 2);
write_file(file,";please separate each level with a space.", 3);
write_file(file,";", 4);
write_file(file,";NOTE: level ^"0^" has 0 exp needed automatically,", 5);
write_file(file,";the first amount of exp you write will be level ^"1^"", 6);
write_file(file,";", 7);
write_file(file,";Place your level definitions here:", 8);
write_file(file,"MAXLEVELS 10", 9);
write_file(file,"EXP_NEEDED 100 200 400 800 1600 3200 6400 12800 25600 51200", 10);
/* This is what the file will look like:
;AvP Levels
;EXP_NEEDED is the amount of exp needed for each level
;please separate each level with a space.
;
;NOTE: level "0" has 0 exp needed automatically,
;the first amount of exp you write will be level "1"
;
;Place your level definitions here:
MAXLEVELS 10
EXP_NEEDED 100, 200, 400, 800, 1600, 3200, 6400, 12800, 25600, 51200
*/
}