Raised This Month: $51 Target: $400
 12% 

making/editing and deleting configs


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CrancK
Senior Member
Join Date: Jan 2009
Location: Netherlands
Old 03-31-2009 , 17:22   making/editing and deleting configs
Reply With Quote #1

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_SMrpathPLATFORM_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?

Last edited by CrancK; 03-31-2009 at 18:17.
CrancK is offline
CrancK
Senior Member
Join Date: Jan 2009
Location: Netherlands
Old 04-01-2009 , 06:06   Re: making/editing and deleting configs
Reply With Quote #2

nvm, found the problem...

when using buildpath, you can only make/read files in the sourcemod folder, and the folder must already have been made otherwise it'll return 0 to the handle, thus creating the error...


edit:

then again... i do have problems with executing the cfg file after it's created

code:
PHP Code:
// Exec sql.cfg //
public plugin_cfg()
{
    new 
String:mapname[64]; GetCurrentMap(mapname63);
    new 
String:rpath2[PLATFORM_MAX_PATH];
    
BuildPath(Path_SM,rpath2,PLATFORM_MAX_PATH,"/configs/maps/%s.cfg"mapname);
    
ServerCommand("exec %s"rpath2);

or should i simply do

PHP Code:
new String:mapname[64]; GetCurrentMap(mapname63);
ServerCommand("exec addons/sourcemod/configs/maps/%s.cfg"mapname); 
and the "error" in the server log :
exec: couldn't exec addons/sourcemod

edit2:
i've also tried the second way and it gives this in server log:
exec: couldn't exec addons/sourcemod/configs/maps/jump_rush.cfg

(config was created properly)

Last edited by CrancK; 04-01-2009 at 10:56.
CrancK is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 04-01-2009 , 20:32   Re: making/editing and deleting configs
Reply With Quote #3

exec starts in the /cfg folder, so you can't execute config files in the SM folder. BuildPath is only needed for the SM folder, so simply get rid of it and put the files in /cfg/maps or something.
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.
DJ Tsunami 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 21:39.


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