Quote:
Originally Posted by styles
Hehe, its a cool idea, give him a shot. Unapprove it later if he shows that he can't handel it. But if he can, hell give him a shot, You don't know if you don't give him a try ;)
|
Really? How about no?
Code:
new norandom[32]
get_cvar_string("sv_norandom",norandom,32)
if (!equal(norandom,"1"))
{
register_cvar("sv_norandom","")
}
What's this? Why not just use pcvars?
Code:
else return PLUGIN_HANDLED
Uhh... why not just combine the RandomMap() function call into the if statement, which also justifies putting brackets in it? Also, why did you return PLUGIN_HANDLED? Why did you even return PLUGIN_CONTINUE? If you HAD to do this, the fastest way (typing-wise) would probably be to just use "return".
Code:
public RandomMap() {
Okay, you got me here. Why is it public? Is it called anywhere outside of the plugin? Is it a forward? No? Drop the "public" keyword.
Code:
new configsdir[256],file[256],mapname[256],junk
get_configsdir(configsdir,256)
format(file,256,"%s/maps.ini",configsdir)
I not only don't get why you don't just do this:
Code:
add(configsdir,255,"/maps.ini")
But I don't get why you missed a simple thing like the risk of a buffer overflow. You don't declare an array as 256 then use 256 as the max length, it's 255 to allow for the null terminator.
Code:
if (!file_exists(file)) format(file,256,"mapcycle.txt")
else if (!file_exists(file))
{
server_print("[AMXX] WARNING! Could not find %s/maps.ini or mapcycle.txt in order to randomise startup map!",configsdir)
return PLUGIN_HANDLED
}
Why return PLUGIN_HANDLED? There's no point, the return value doesn't do anything. On top of that, you should use log_amx for people who don't have direct access to the console. It might also be a good idea to use copy instead of format, since there are no variables.
Code:
new size = file_size(file,1)
new rand = random_num(0,size)
read_file(file,rand,mapname,256,junk)
Nothing really
too wrong here, but if I were to do it, I would have declared the variables like this to save space:
Code:
new size = file_size(file,1), rand = random_num(0,size)
It's also probably better to use the "random" function, since you don't have to push an additional parameter onto the stack. The usage would be something like "random(size)"
Code:
set_cvar_string("sv_norandom","1")
server_print("[AMXX] Randomising map...")
server_cmd("changelevel %s",mapname)
This may confuse server owners who think they should set this. Not really any way around it that I can think of, but also you should either use log_amx or just remove the server_print section entirely.
Code:
return PLUGIN_CONTINUE
Useless, if you avoided the return that I mentioned earlier, you wouldn't need this.
In conclusion, this is staying here.
__________________