i'm trying to put the coordinates of 2 points in a map (and some other stuff) into a cfg file, with the maps name as the cfg file... (and i'm trying to put it into the tf/maps/cfg/ folder)
my problem comes from not completely understanding the BuildPath, FileExists, DeleteFile and OpenFile and the api doesnt shed much light into how to actually use them... (or give an example)
anyway my code:
PHP Code:
// old map config deleted when admin is adding map config
deletefile()
{
new String:mapname[32];
GetCurrentMap(mapname,31);
new String:rpath[PLATFORM_MAX_PATH];
BuildPath(Path_SM, rpath, PLATFORM_MAX_PATH, "maps/cfg/%s.cfg", mapname);
//Format(path,61,"/maps/cfg/%s.cfg",mapname);
if (FileExists(rpath))
{
DeleteFile(rpath);
}
setfile();
}
// New map config is written when admin is adding map config
setfile()
{
new String:mapname[32];
GetCurrentMap(mapname,31);
//if(!FileExists(path, false))
//{
new String:rpath[PLATFORM_MAX_PATH];
BuildPath(Path_SM,rpath,PLATFORM_MAX_PATH,"/maps/cfg/%s.cfg", mapname);
new Handle:fileHandle2=OpenFile(rpath,"w");
CloseHandle(fileHandle2);
//}
new String:mapfilestart[76];
new String:x_cstart[32];
new String:y_cstart[32];
new String:z_cstart[32];
new String:x_cgoal[32];
new String:y_cgoal[32];
new String:z_cgoal[32];
//new String:sv_cgoalteams[32];
new String:sv_cdifficulty[32];
new String:mapfileend[76];
//GetConVarString(sv_gteam,sv_cgoalteams,31);
Format(mapfilestart , 75, "//START OF SKILLSRANK MAPFILE OF MAP %s", mapname);
Format(x_cstart,31,"x_start %f",GetConVarFloat(x_start));
Format(y_cstart,31,"y_start %f",GetConVarFloat(y_start));
Format(z_cstart,31,"z_start %f",GetConVarFloat(z_start));
Format(x_cgoal,31,"x_goal %f",GetConVarFloat(x_goal));
Format(y_cgoal,31,"y_goal %f",GetConVarFloat(y_goal));
Format(z_cgoal,31,"z_goal %f",GetConVarFloat(z_goal));
//Format(sv_cgoalteams,31,"sv_goalteams %s",sv_cgoalteams);
Format(sv_cdifficulty,31,"sv_difficulty %d",GetConVarInt(sv_diff));
Format(mapfileend,75,"// END OF SKILLSRANK MAPFILE OF MAP %s",mapname);
new String:rpath2[PLATFORM_MAX_PATH];
BuildPath(Path_SM,rpath2,PLATFORM_MAX_PATH,"/maps/cfg/%s.cfg", mapname);
new Handle:fileHandle=OpenFile(rpath2,"a"); // Opens addons/sourcemod/blank.txt to append text to it
WriteFileLine(fileHandle,"mapfilestart");
WriteFileLine(fileHandle,x_cstart);
WriteFileLine(fileHandle,y_cstart);
WriteFileLine(fileHandle,z_cstart);
WriteFileLine(fileHandle,x_cgoal);
WriteFileLine(fileHandle,y_cgoal);
WriteFileLine(fileHandle,z_cgoal);
//WriteFileLine(fileHandle,sv_cgoalteams);
WriteFileLine(fileHandle,sv_cdifficulty);
WriteFileLine(fileHandle,mapfileend);
CloseHandle(fileHandle);
}
so basically, after some stuff is done, this is called, first the old file gets deleted, then the new file created and filled with info...
anyone know if this should work? and if not how it might could work?
or could someone simply explain how to use the BuildPath, OpenFile and DeleteFile
the main problem is really with BuildPath, the first parameter, as i don't know any other then this value which is valid
PS: i'm trying this for tf2, if it makes any difference...
edit: some more info that might help:
when i run the whole shablam that this is part of, everything runs fine until it gets to the CloseHandle(fileHandle2);
as per server log:
L 03/31/2009 - 22:08:41: [SM] Native "CloseHandle" reported: Handle 0 is invalid (error 4)
L 03/31/2009 - 22:08:41: [SM] Displaying call stack trace for plugin "speedrunning.smx":
L 03/31/2009 - 22:08:41: [SM] [0] Line 1959, F:\downloads\sourcemod-1.2.0\addons\sourcemod\scripting\speedrunning .sp::setfile()
L 03/31/2009 - 22:08:41: [SM] [1] Line 1946, F:\downloads\sourcemod-1.2.0\addons\sourcemod\scripting\speedrunning .sp::deletefile()
L 03/31/2009 - 22:08:41: [SM] [2] Line 1535, F:\downloads\sourcemod-1.2.0\addons\sourcemod\scripting\speedrunning .sp::modelMenuHandler()
am i not supposed to close the handle?