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

get_custom_dir Info..


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DoubleTap
Veteran Member
Join Date: Mar 2004
Location: Harker Heights, TX
Old 03-30-2004 , 13:01   get_custom_dir Info..
Reply With Quote #1

Okay, in order to make the plugins I have posted fully compliant I am trying to learn a bit of this stuff. Not being a coder I cannot relate how this should be done properly.

This is what I assume is the bad info that needs to be complaint:
new filepath[64] = {"addons/amxx/custom/map_configs/"}

I look at xeroblood's Swear Filter plugin and search get_custom_dir because I know he has a folder elsewhere for configs... I get this info:
get_customdir( g_szCustomDir, 31 )
get_configsdir( g_szConfigDir, 31 )
server_cmd( "exec %s/swear/swear_config.cfg;", g_szCustomDir )


Using logic my guess my code should look like this:
get_customdir( g_szCustomDir, 64 )
get_configsdir( g_szConfigDir, 64 )
server_cmd( "exec %s/map_configs/%s%s.cfg;", g_szCustomDir )


The problem with that for me (again using logic because I dont know what my 64 and his 31 means) is the next series of code seems to use:

Quote:
public load_config(){
new currentmap[32], filename[128]
get_mapname(currentmap,31)
new len = format(filename,127,"%s%s.cfg",filepath,curre ntmap)
if (file_exists(filename))
set_task(6.1,"delayed_load",0,filename,len+1)
}

public delayed_load(filename[])
server_cmd("exec %s",filename)

public addcmd(id,level,cid) {
if (!cmd_access(id,level,cid,1)) {
return PLUGIN_HANDLED
}

new arg[128]
read_args(arg,127)
In a nutshell I guess, because after reading what I put here I am ever more confused... I never see in the code where g_szCustomDir established the custom folder for the get_customdir...

Vic/DT

Be gentle... you know the ditty about old dogs and new tricks...
__________________
DoubleTap is offline
Send a message via ICQ to DoubleTap
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 03-30-2004 , 13:38  
Reply With Quote #2

normally, you can hardcode paths like this
Code:
new myPath[] = "addons/amxx/custom/file.ini"
you don't have to specify the elements count (the number in the brackets) because the compiler will find it out.

get_customdir has two parameters: The result will be stored into the first one. But you (and especially the compiler) can't know how long the result will be, so you need to specify the element count.
Let's say you would write this (if the native supported it):
Code:
new configsDir[64]; get_configsdir(configsDir);
The native doesn't know the size of the configsDir variable. If the size of the path is smaller than 64 bytes, it's no problem. But when it gets larger (for example 128 bytes), the native will copy it into the variable, and will corrupt anything that comes behind the variable in the memory. So the native has a second parameter which specifies the maximal length. This parameter only prevents data / stack corruptions. So you use the native like this
Code:
new configsDir[64]; get_configsdir(configsDir, 63);
Note that the number has to be arraysize - 1 (or smaller, but not bigger ;] ) because of the terminating null character.

Code:
server_cmd( "exec %s/swear/swear_config.cfg;", g_szCustomDir )
This is correct. The server_cmd native first goes through the string and replaces the %s by the first parameter. So the string that will be executed will eb "exec addons/amxx/custom/swear/swear_config.cfg;".

Code:
server_cmd( "exec %s/map_configs/%s%s.cfg;", g_szCustomDir )
This could cause a crash. The native will go through the string, and will find a %s, and willreplace it by the first parameter. But it will find another %s and will try to replace it by a non existing parameter...

I hope I haven't confused you
__________________
hello, i am pm
PM is offline
BigBaller
Veteran Member
Join Date: Mar 2004
Location: Everett, WA
Old 03-30-2004 , 13:45  
Reply With Quote #3

Quote:
Using logic my guess my code should look like this:
get_customdir( g_szCustomDir, 64 )
get_configsdir( g_szConfigDir, 64 )
server_cmd( "exec %s/map_configs/%s%s.cfg;", g_szCustomDir )
I think something like that is wrong only becuase I noticed when using %s that you need all the varibles at the end

try something like

Code:
Using logic my guess my code should look like this: get_customdir( g_szCustomDir, 64 ) get_configsdir( g_szConfigDir, 64 ) server_cmd( "exec %s/map_configs/%s%s.cfg;", g_szCustomDir,something,someting)

AS something means map name or w/e cuz I know the plugin you are talking about.
__________________

BigBaller is offline
DoubleTap
Veteran Member
Join Date: Mar 2004
Location: Harker Heights, TX
Old 03-30-2004 , 18:11  
Reply With Quote #4

You guys made my head hurt... if I get a beer this early in the afternoon my wife will have my azz... I assumed the number variables were fielsize to a point, that minus one stuff I could see but had no clue before... now, I am just confused but getting this in my head a bit...

Reading both messages I believe my line should now be:

get_customdir( g_szCustomDir, 64 )
get_configsdir( g_szConfigDir, 64 )
server_cmd( "exec %s/map_configs/%s%s.cfg;", g_szCustomDir,filepath,currentmap)


Vic/DT

Am I in the ballpark ?
__________________
DoubleTap is offline
Send a message via ICQ to DoubleTap
BigBaller
Veteran Member
Join Date: Mar 2004
Location: Everett, WA
Old 03-30-2004 , 23:21  
Reply With Quote #5

Yes DT that looks correct.
__________________

BigBaller is offline
DoubleTap
Veteran Member
Join Date: Mar 2004
Location: Harker Heights, TX
Old 03-30-2004 , 23:48  
Reply With Quote #6

Ack... it ONLY gave me new errors man...
Quote:
Small compiler 2.1.0 Copyright (c) 1997-2002, ITB CompuPhase

custom_map_configs.sma(37) : error 021: symbol already defined: "get_customdir"
custom_map_configs.sma(39) : error 021: symbol already defined: "server_cmd"
custom_map_configs.sma(44) : error 017: undefined symbol "filepath"
custom_map_configs.sma(69) : error 017: undefined symbol "filepath"
custom_map_configs.sma(91) : error 017: undefined symbol "filepath"

5 Errors.
Press any key to continue . . .
I replaced the one line with the three lines... I will look again tomorrow to see the broke lines... they "MAY" line up with things talked about already and I can figure it out... if I have enough coffee

Vic/DT
__________________
DoubleTap is offline
Send a message via ICQ to DoubleTap
BigBaller
Veteran Member
Join Date: Mar 2004
Location: Everett, WA
Old 03-31-2004 , 00:04  
Reply With Quote #7

ill give that plugin a shot later, I know what you are trying to do.
__________________

BigBaller is offline
BigBaller
Veteran Member
Join Date: Mar 2004
Location: Everett, WA
Old 03-31-2004 , 00:55  
Reply With Quote #8

OK DT I think I have your fix, I was unable to test it because my server crashed and the host is gay still hasnt turned my server back on (dont ask me its a long story yadda yadda)

Try this coding.

Code:
/* AMX Mod X script. * * Custom Map Configs 0.9.1 *  Set map-specific variables and commands * * by JustinHoMi ([email protected]) *  <a href="http://www.modkillers.com" target="_blank" rel="nofollow noopener">http://www.modkillers.com</a> *  #modkillers in irc.gamesnet.net * * Place your custom configs in the designated folder *  (addons/amxx/custom/map_configs by default) * Configs should be in the format "mapname.cfg" * Insert any cvar or cmd to be executed at map change * * There are two commands that can be run by admin with * ADMIN_CFG access in game: *   amx_customcfg <command> - Adds command to current map's config file *   amx_customcfgdelete - Deletes the custom cfg file for current map * * Changelog: *  0.9.1 - BigBaller added support for get_customdir( and also log_amx support *  0.9 - JGHG added two new commands, runnable by server console *  or a client with ADMIN_CFG access: * *   amx_customcfg <command> - Adds command to current map's config file *   amx_customcfgdelete - Deletes the custom cfg file for current map * *  0.61 - Changes load delay to 6s (to work better with SQL ServerCfg) *  0.6 - Execs configs rather than loading file *        - Delays execution for 5s after map changes *  0.5 - Initial release * */ #include <amxmodx> #include <amxmisc> new filepath[64] public load_config(){     new currentmap[32], filename[128]     get_mapname(currentmap,31)     get_customdir(filepath, 63)     format(filepath, 63, "%s/map_configs/", filepath)     new len = format(filename,127,"%s%s.cfg",filepath,currentmap)     if (file_exists(filename))         set_task(6.1,"delayed_load",0,filename,len+1) } public delayed_load(filename[])     server_cmd("exec %s",filename) public addcmd(id,level,cid) {     if (!cmd_access(id,level,cid,1)) {         return PLUGIN_HANDLED     }     new arg[128]     read_args(arg,127)     // Whole command line to be added is now in array 'arg'.     // If length is 0, no command was typed. Quit.     if (strlen(arg) < 1) {         console_print(id,"[AMXX] You didn't specify a command to add. Usage: amx_customcfg <command>")         return PLUGIN_HANDLED     }     new currentmap[32], filename[128]     get_mapname(currentmap,31)     format(filename,127,"%s%s.cfg",filepath,currentmap)     // In case last line is not empty, add an empty line first.     write_file(filename,"")     if (!write_file(filename,arg)) {         console_print(id,"[AMXX] Failed to add '%s' to '%s.cfg'!",arg,currentmap)         log_amx("CustomMapConfigs - Failed to add '%s' to '%s.cfg'!",arg,currentmap)     }     else {         console_print(id,"[AMXX] Added '%s' to '%s.cfg'.",arg,currentmap)         log_amx("CustomMapConfigs - Added '%s' to '%s.cfg'.",arg,currentmap)     }     return PLUGIN_HANDLED } public clear(id,level,cid) {     if (!cmd_access(id,level,cid,1)) {         return PLUGIN_HANDLED     }     new currentmap[32], filename[128]     get_mapname(currentmap,31)     get_customdir(filepath, 63)     format(filepath, 63, "%s/map_configs/", filepath)     format(filename,127,"%s%s.cfg",filepath,currentmap)     if (file_exists(filename)) {         if (delete_file(filename))             console_print(id,"[AMXX] Successfully deleted '%s.cfg'.",currentmap)         else             console_print(id,"[AMXX] Failed to delete '%s.cfg'!",currentmap)     }     else         console_print(id,"[AMXX] '%s.cfg' does not exist!",currentmap)         log_amx("CustomMapConfigs - Failed to delete '%s.cfg'. File does not exist!",currentmap)     return PLUGIN_HANDLED } public plugin_init(){     register_plugin("Custom Map Configs","0.9.1","JustinHoMi")     register_concmd("amx_customcfg","addcmd",ADMIN_CFG,"<command> : add command to this map's custom config file")     register_concmd("amx_customcfgdelete","clear",ADMIN_CFG,": deletes the custom config file for this map")     load_config() }
__________________

BigBaller is offline
DoubleTap
Veteran Member
Join Date: Mar 2004
Location: Harker Heights, TX
Old 03-31-2004 , 16:50  
Reply With Quote #9

I am going to run with it now... replacing my code with this... thanks again BB...

Vic/DT

I am going to go back in and look at what changed... that was making me crazy
__________________
DoubleTap is offline
Send a message via ICQ to DoubleTap
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 10:14.


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