AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Mapcycle generator (place maps randomly lines) (https://forums.alliedmods.net/showthread.php?t=94016)

Rirre 06-05-2009 13:40

Mapcycle generator (place maps randomly lines)
 
1 Attachment(s)
Hi there,

I have a couple of servers and i have a map generator plugin to place maps from maps/ folder into maps.ini and mapcycle.txt, but i want it to place all maps randomly in mapcycle.txt file.
Since if all maps is in same line in all server mapcycle.txt
so do all servers use same map on mapchange.
Every server choose the map from the top and go down.
I hope you understood what I said.
randomly placed in mapcycle.txt should be enough to explain how i want it.

Arkshine 06-05-2009 14:02

Re: Mapcycle generator (place maps randomly lines)
 
I found a old and basic plugin which does that :

Code:
        stock ShakeMapcyle()     {         new const MapcycleFile[] = "mapcycle.txt";         new Map[ 64 ];         new h = fopen( MapcycleFile, "rb" );                 new Array:SavedMaps = ArrayCreate( 64 );                 while( !feof( h ) )         {             fgets( h, Map, charsmax( Map ) );             trim( Map );             if ( Map[0] )  { ArrayPushString( SavedMaps, Map ); }         }                 fclose( h );         delete_file( MapcycleFile );                 new Cnt;         new MapCnt;         new Rand;         new Rand2;                 Cnt = iMapCnt = ArraySize( SavedMaps );         while( Cnt )         {             Rand  = random( MapCnt );             Rand2 = random( MapCnt );             if( Rand != Rand2 )             {                 ArraySwap( SavedMaps, Rand, Rand2 );                 Cnt--;             }         }                 h = fopen( MapcycleFile, "wb" );                 for( new i; i < MapCnt; ++i )         {               ArrayGetString( SavedMaps, i, Map, charsmax( Map ) );             fputs( h, Map );             fputc( h, '^n' );         }                         fclose( h );         ArrayDestroy( SavedMaps );     }

Put this function in plubin_cfg() for example.

Rirre 06-05-2009 14:07

Re: Mapcycle generator (place maps randomly lines)
 
Can you write it to a whole plugin with includes? thx :)

Arkshine 06-05-2009 14:11

Re: Mapcycle generator (place maps randomly lines)
 
Code:
        #include <amxmodx>         public plugin_init()     {         register_plugin( "Shake Mapcyle", "1.0.0", "Arkshine" );     }         public plugin_cfg()     {         ShakeMapcyle();     }         stock ShakeMapcyle()     {         new const MapcycleFile[] = "mapcycle.txt";         new Map[ 64 ];         new h = fopen( MapcycleFile, "rb" );                 new Array:SavedMaps = ArrayCreate( 64 );                 while( !feof( h ) )         {             fgets( h, Map, charsmax( Map ) );             trim( Map );             if ( Map[0] )  { ArrayPushString( SavedMaps, Map ); }         }                 fclose( h );         delete_file( MapcycleFile );                 new Cnt;         new MapCnt;         new Rand;         new Rand2;                 Cnt = MapCnt = ArraySize( SavedMaps );         while( Cnt )         {             Rand  = random( MapCnt );             Rand2 = random( MapCnt );             if( Rand != Rand2 )             {                 ArraySwap( SavedMaps, Rand, Rand2 );                 Cnt--;             }         }                 h = fopen( MapcycleFile, "wb" );                 for( new i; i < MapCnt; ++i )         {               ArrayGetString( SavedMaps, i, Map, charsmax( Map ) );             fputs( h, Map );             fputc( h, '^n' );         }                         fclose( h );         ArrayDestroy( SavedMaps );     }

It's basic but should be enough.

Rirre 06-05-2009 14:18

Re: Mapcycle generator (place maps randomly lines)
 
Thanks :D It works!


All times are GMT -4. The time now is 13:52.

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