Raised This Month: $ Target: $400
 0% 

Random Map on Server Startup


Post New Thread Reply   
 
Thread Tools Display Modes
vvg125
AMX Mod X Beta Tester
Join Date: Dec 2006
Location: Queens (Douglaston), New
Old 03-09-2007 , 17:20   Re: Random Map on Server Startup
Reply With Quote #11

Every plugin can break or have a bug. Just because it's simple doesn't guarantee anything.
__________________
vvg125 is offline
Send a message via AIM to vvg125 Send a message via MSN to vvg125 Send a message via Yahoo to vvg125
DataMatrix
Senior Member
Join Date: Aug 2005
Location: UK, Liverpool
Old 03-12-2007 , 02:57   Re: Random Map on Server Startup
Reply With Quote #12

v1.12 released
DataMatrix is offline
Send a message via MSN to DataMatrix
Styles
Veteran Member
Join Date: Jul 2004
Location: California
Old 03-19-2007 , 17:57   Re: Random Map on Server Startup
Reply With Quote #13

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 ;)
Styles is offline
Send a message via AIM to Styles
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 03-19-2007 , 18:54   Re: Random Map on Server Startup
Reply With Quote #14

Quote:
Originally Posted by styles View Post
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.
__________________

Last edited by Hawk552; 03-19-2007 at 18:55. Reason: fixed typo
Hawk552 is offline
Send a message via AIM to Hawk552
DataMatrix
Senior Member
Join Date: Aug 2005
Location: UK, Liverpool
Old 03-21-2007 , 16:26   Re: Random Map on Server Startup
Reply With Quote #15

Uhh, if I remove
Code:
return PLUGIN_HANDLED
the code continues and the map changes regardless of the if statements.

You must end the current function with return if you don't want any other code to be executed. But meh, I like PHP better, I always thought of return PLUGIN_HANDLED as the equivalent to die();

Besides, do you see any other map randomisers? Well I don't, so if you can do better, please do, and who cares about an overflow, as soon as the map changes the damn plugin disables itself.
DataMatrix is offline
Send a message via MSN to DataMatrix
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 03-21-2007 , 20:38   Re: Random Map on Server Startup
Reply With Quote #16

Quote:
Originally Posted by DataMatrix View Post
Uhh, if I remove Code:
return PLUGIN_HANDLED

the code continues and the map changes regardless of the if statements.

You must end the current function with return if you don't want any other code to be executed. But meh, I like PHP better, I always thought of return PLUGIN_HANDLED as the equivalent to die();

Besides, do you see any other map randomisers? Well I don't, so if you can do better, please do, and who cares about an overflow, as soon as the map changes the damn plugin disables itself.
I don't think I've ever seen anyone here as dense as you. Instead of admitting your mistakes and fixing them, you shrug them off and blame me for your failure to code a 20 line plugin effectively.

You don't need the return statement because it can be rewritten:
Code:
    if (!equal(norandom,"1"))     {         register_cvar("sv_norandom","")     }     else return PLUGIN_HANDLED         RandomMap()         return PLUGIN_CONTINUE

->

Code:
if(!equali(norandom,"1") {     register_cvar("sv_norandom","")     RandomMap() }

If you don't want to fix the overflow, that's fine with me. This won't stand a prayer in hell of being approved, though.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
DataMatrix
Senior Member
Join Date: Aug 2005
Location: UK, Liverpool
Old 03-22-2007 , 15:19   Re: Random Map on Server Startup
Reply With Quote #17

v1.2.0 released.
DataMatrix is offline
Send a message via MSN to DataMatrix
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 03-22-2007 , 17:44   Re: Random Map on Server Startup
Reply With Quote #18

Also, I didn't notice at first but you can do:

Code:
if(get_cvar_num("sv_norandom") != 2)

Instead of your crazy stuff.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
DataMatrix
Senior Member
Join Date: Aug 2005
Location: UK, Liverpool
Old 03-23-2007 , 03:45   Re: Random Map on Server Startup
Reply With Quote #19

Quote:
Originally Posted by Hawk552 View Post
Also, I didn't notice at first but you can do:

Code:
if(get_cvar_num("sv_norandom") != 2)

Instead of your crazy stuff.
Done.

v1.2.1 released.
DataMatrix is offline
Send a message via MSN to DataMatrix
DataMatrix
Senior Member
Join Date: Aug 2005
Location: UK, Liverpool
Old 03-27-2007 , 13:16   Re: Random Map on Server Startup
Reply With Quote #20

v1.2.5 released.

PS: Hawk552, what is the difference with pcvars and cvars?
DataMatrix is offline
Send a message via MSN to DataMatrix
Reply


Thread Tools
Display Modes

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 08:36.


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