Advertisement
RanAway

[ Pawn - advanced plugins ] advanced votemap

May 28th, 2022 (edited)
1,932
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 46.22 KB | None | 0 0
  1. /* not tested yet */
  2.  
  3. // todo
  4. // maybe add rounds as options instead of timeleft
  5. // maybe add second vote when 2 or more maps are tied up ( revote )
  6.  
  7. //--------------- Includes ---------------//
  8. #include < amxmodx >
  9. #include < smartstocks >
  10.  
  11. //-------------------- File's locations --------------------//
  12. #define mapini          fmt( "%s/maps.ini", GetDirPath( "amxx_configsdir" ) )           // maps's ini
  13. #define settingsini     fmt( "%s/vmsettings.ini", GetDirPath( "amxx_configsdir" ) )     // settings's ini
  14.  
  15. //-------------------- TaskIDs --------------------//
  16. enum ( += 1000 ) { MapTaskID = 1000, TimeLeftTaskID, CountdowntovoteTaskID, MenuTimeTaskID, TimetochangeTaskID }
  17.  
  18. //-------------------- Settings's functions --------------------//
  19. enum Settings
  20. {
  21.     PREFIX[ 32 ], LOG_FOLDER[ 128 ], ACCESS, TimeZone,
  22.     bool:AllowValveMaps,
  23.     MapsInMenu, MaxRecentMaps,
  24.  
  25.     //--------------- Timers ---------------//
  26.     DefaultTime, Countdownrtv, VoteCountdown, MenuCountdown, ExtendTime, NextmapTimeleft
  27. }
  28.  
  29. new BaseSettings[ Settings ]
  30.  
  31. //-------------------- map & vote functions --------------------//
  32. enum { Vote_NotRunning, Vote_Starting, Vote_Running, Vote_Nextmap }
  33. enum _:MapStats { mapname[ 64 ], mapdate[ 64 ], mapplayed[ 64 ], mappopularity[ 64 ], mapsize[ 64 ], bool:nominated }
  34. enum _:VoteStats { bool:adminhud, rtvcounter, nomcounter, Timeleft, Timeleftnextmap, Maptime, Mapcountdown, Countdown, MenuTimer, Allvotes, Nextmap[ 64 ] }
  35. enum _:MyStats { bool:RTV, bool:dontshowmenu, bool:revote, bool:nominate, mynom[ 64 ], bool:voted, selectedmap[ 64 ], mychoose }
  36.  
  37. new mapsystem[ 1000 ][ MapStats ], votesystem[ VoteStats ], playersystem[ 33 ][ MyStats ]
  38. new totalmaps, votestate, sortmenu[ 33 ], searchmap[ 33 ], menupage[ 33 ], mapvotes[ 33 ], bool:MenuShitFunction
  39.  
  40. //-------------------- commands --------------------//
  41. new startvotecmds[][] = { "startvote", "/startvote", "!startvote" }
  42. new stopvotecmds[][] = { "stopvote", "/stopvote", "!stopvote" }
  43. new randommapcmds[][] = { "/randommap", "!randommap" }
  44. new extendcmds[][] = { "/extend", "!extend" }
  45.  
  46. new currentmapcmds[][] = { "cm", "/cm", "currentmap", "/currentmap", "mt", "/mt", "maptime", "/maptime" }
  47. new thetimecmds[][] = { "tt", "/tt", "thetime", "/thetime" }
  48. new timeleftcmds[][] = { "tl", "/tl", "timeleft", "/timeleft", "nm", "/nm", "nextmap", "/nextmap" }
  49. new rockthevotecmds[][] = { "rtv", "/rtv", "rockthevote", "/rockthevote" }
  50. new unrockthevotecmds[][] = { "unrtv", "/unrtv", "unrockthevote", "/unrockthevote" }
  51. new mapsmenucmds[][] = { "/maps" }
  52. new nomcmds[][] = { "noms", "/noms", "nominate", "/nominate", "nominations", "/nominations" }
  53. new recentmapcmds[][] = { "rm", "/rm", "recentmaps", "/recentmaps" }
  54.  
  55. //--------------- Plugin init ---------------//
  56. public plugin_init()
  57. {
  58.     register_plugin( "advanced votemap", "v1.0", "RanAway" )
  59.  
  60.     //--------------- Commands ---------------//
  61.     register_clcmd( "say", "CmdSay" )
  62.     register_clcmd( "say_team", "CmdSay" )
  63.  
  64.     //-------------------- load functions --------------------//
  65.     loadsettings()                                                      // settings functions - load settings
  66.     loadmaps()                                                          // map functions - load maps
  67.     generatemaps()                                                      // map functions - generate maps
  68.     if( BaseSettings[ AllowValveMaps ] ) generatemaps( true )           // map functions - generate valve maps
  69.  
  70.     votestate = Vote_NotRunning
  71.     votesystem[ Timeleft ] = BaseSettings[ DefaultTime ]
  72.     votesystem[ Mapcountdown ] = BaseSettings[ Countdownrtv ]
  73.     votesystem[ Countdown ] = BaseSettings[ VoteCountdown ]
  74.     votesystem[ MenuTimer ] = BaseSettings[ MenuCountdown ]
  75.  
  76.     //--------------- Timers ---------------//
  77.     set_task( 1.0, "Timetovote", TimeLeftTaskID, .flags = "b" )         // vote functions - timeleft to vote
  78.     set_task( 1.0, "MapTime", MapTaskID, .flags = "b" )                 // map functions - count the current map time
  79.     set_task( 1.0, "mapaddtime", MapTaskID, .flags = "b" )              // map functions - add time
  80. }
  81.  
  82. //--------------- Disconnect ---------------//
  83. public client_disconnected( id )
  84. {
  85.     //--------------- Vote status ---------------//
  86.     if( !votestatus( id ) )
  87.     {
  88.         //--------------- if rocked the vote ---------------//
  89.         if( playersystem[ id ][ RTV ] ) votesystem[ rtvcounter ]--
  90.         //--------------- If nominated ---------------//
  91.         if( playersystem[ id ][ nominate ] )
  92.         {
  93.             for( new i = 0; i < totalmaps; i++ ) if( equali( mapsystem[ i ][ mapname ], playersystem[ id ][ mynom ] ) ) mapsystem[ i ][ nominated ] = false
  94.  
  95.             votesystem[ nomcounter ]--
  96.             ColorChat( 0, "^3%s^1 is no longer nominated.", playersystem[ id ][ mynom ] )
  97.         }
  98.  
  99.         arrayset( playersystem[ id ], 0, MyStats )
  100.     }
  101. }
  102.  
  103. //--------------- Map time ---------------//
  104. public MapTime() votesystem[ Maptime ]++
  105.  
  106. //--------------- Time to vote ---------------//
  107. public Timetovote()
  108. {
  109.     //--------------- Failsafe ---------------//
  110.     if( votesystem[ Timeleft ] <= 0 && task_exists( TimeLeftTaskID ) ) return remove_task( TimeLeftTaskID )
  111.  
  112.     if( --votesystem[ Timeleft ] <= 0 )
  113.     {
  114.         votesystem[ adminhud ] = false
  115.         StartVote()
  116.         ColorChat( 0, "The ^3votemap^1 has started." )
  117.     }
  118.  
  119.     return 0
  120. }
  121.  
  122. //--------------- maps & nominate menu ---------------//
  123. public mapsmenu( id )
  124. {
  125.     //--------------- Vote status & prevent heap low ---------------//
  126.     if( votestatus( id ) || !is_user_connected( id ) ) return 1
  127.  
  128.     new item[ 512 ], menu = menu_create( fmt( "\r[\w %s \r]\w map menu \y(\d%d\y)\w\R", BaseSettings[ PREFIX ], totalmaps ), "sub_mapsmenu" )
  129.  
  130.     //-------------------- Sorting --------------------//
  131.     SortCustom2D( mapsystem, totalmaps, "MapSorting", _, id )
  132.  
  133.     for( new i = 0, counter = -1; i < totalmaps; i++ )
  134.     {
  135.         //-------------------- searching | Currentmap --------------------//
  136.         if( ( searchmap[ id ] && containi( mapsystem[ i ][ mapname ], searchmap[ id ] ) == -1 ) || equali( mapsystem[ i ][ mapname ], CurrentMap() ) ) continue
  137.  
  138.         //-------------------- Sorting --------------------//
  139.         if( ++counter % 6 == 0 ) menu_additem( menu, fmt( "\ySort by: \d%s^n", sortmenu[ id ] == 0 ? "Nominations" : sortmenu[ id ] == 1 ? "Date Added" : sortmenu[ id ] == 2 ? "Last Played" : sortmenu[ id ] == 3 ? "Popularity" : "Size" ) )
  140.  
  141.         //-------------------- map name & nominate symbol --------------------//
  142.         formatex( item, charsmax( item ), "%s%s", mapsystem[ i ][ mapname ], mapsystem[ i ][ nominated ] ? "\y*" : "" )
  143.  
  144.         switch( sortmenu[ id ] )
  145.         {
  146.             //-------------------- map date --------------------//
  147.             case 1: add( item, charsmax( item ), fmt( " \d(%s)", Getformattime( "%H:%M - %d/%m/%y", str_to_num( mapsystem[ i ][ mapdate ] ) ) ) )
  148.             //-------------------- map played --------------------//
  149.             case 2: add( item, charsmax( item ), fmt( " \d(%s)", str_to_num( mapsystem[ i ][ mapplayed ] ) > 0 ? Getformattime( "%H:%M - %d/%m/%y", str_to_num( mapsystem[ i ][ mapplayed ] ) ) : "N/A" ) )
  150.             //-------------------- map popularity --------------------//
  151.             case 3: add( item, charsmax( item ), fmt( " \d(%s)", str_to_num( mapsystem[ i ][ mappopularity ] ) > 0 ? fmt( "%.1f hours", str_to_num( mapsystem[ i ][ mappopularity ] ) / 3600.0 ) : "N/A" ) )
  152.             //-------------------- map size --------------------//
  153.             case 4: add( item, charsmax( item ), fmt( " \d(%.2f %s)", mapsystem[ i ][ mapsize ] / 1048576.0, mapsystem[ i ][ mapsize ] / 1048576.0 >= 1.00 ? "MB" : "KB" ) )
  154.         }
  155.         MenuCallback( menu, item, _, ( mapsystem[ i ][ nominated ] && IsMapNominated( mapsystem[ i ][ mapname ] ) != id ) ? true : false, GetNumStr( i ) )
  156.     }
  157.  
  158.     //-------------------- Previous / Next --------------------//
  159.     menu_setprop( menu, MPROP_NEXTNAME, "next page" )
  160.     menu_setprop( menu, MPROP_BACKNAME, "previous page" )
  161.     menu_setprop( menu, MPROP_EXITNAME, "exit" )
  162.  
  163.     //-------------------- Search title --------------------//
  164.     if( searchmap[ id ] ) menu_setprop( menu, MPROP_TITLE, fmt( "\r[\w %s \r]\w found some maps \y(\d%d\y) \r|\w search active: \y(\d%s\y)\w\R", BaseSettings[ PREFIX ], menu_items( menu ) - menu_pages( menu ), searchmap[ id ] ) )
  165.  
  166.     menu_display( id, menu, menupage[ id ] < 0 ? 0 : menupage[ id ] > totalmaps / 6 ? totalmaps / 6 : menupage[ id ] )
  167.     return 1
  168. }
  169.  
  170. //-------------------- map functions - sorting --------------------//
  171. public MapSorting( const map1[], const map2[], const array[][], data[], id )
  172. {
  173.     //--------- Ascending nominated maps ----------//
  174.     if( map1[ nominated ] && !map2[ nominated ] ) return -1
  175.     else if( !map1[ nominated ] && map2[ nominated ] ) return 1
  176.  
  177.     switch( sortmenu[ id ] )
  178.     {
  179.         //--------- Ascending Alphabetical ----------//
  180.         case 0: return strcmp( map1[ mapname ], map2[ mapname ], true )
  181.         //--------- Ascending by added date ----------//
  182.         case 1: return str_to_num( map2[ mapdate ] ) - str_to_num( map1[ mapdate ] ) > 0 ? 1 : -1
  183.         //--------- Ascending by last time played ----------//
  184.         case 2: return str_to_num( map2[ mapplayed ] ) - str_to_num( map1[ mapplayed ] ) > 0 ? 1 : -1
  185.         //--------- Ascending by popularity ----------//
  186.         case 3: return str_to_num( map2[ mappopularity ] ) - str_to_num( map1[ mappopularity ] ) > 0 ? 1 : -1
  187.         //--------- Ascending by file size ----------//
  188.         case 4: return float( map2[ mapsize ] ) - float( map1[ mapsize ] ) > 0 ? 1 : -1
  189.         //--------- Failsafe ----------//
  190.         default: return server_print( "Warning: Unknown sorting option %d", sortmenu[ id ] )
  191.     }
  192.  
  193.     return 0
  194. }
  195.  
  196. public sub_mapsmenu( id, menu, item )
  197. {
  198.     if( item == MENU_EXIT ) return menu_destroy( menu )
  199.  
  200.     //--------------- Vote status ---------------//
  201.     if( votestatus( id ) ) return 1
  202.  
  203.     //-------------------- Make sure the key is right --------------------//
  204.     new aftersort = GetMenuKey( menu, item )
  205.  
  206.     //-------------------- Save the page --------------------//
  207.     player_menu_info( id, menu, menu, menupage[ id ] )
  208.  
  209.     //-------------------- sorting maps --------------------//
  210.     if( item % 7 == 0 )
  211.     {
  212.         if( sortmenu[ id ]++ >= 4 ) sortmenu[ id ] = 0
  213.     }
  214.     //-------------------- nominate the map --------------------//
  215.     else NominateMap( id, aftersort )
  216.  
  217.     return mapsmenu( id )
  218. }
  219.  
  220. //--------------- CmdSay ---------------//
  221. public CmdSay( id )
  222. {
  223.     //-------------------- get the message --------------------//
  224.     new message[ 192 ], cmd[ 64 ], arg[ 64 ], randommap[ 64 ]
  225.     read_argv( 1, message, charsmax( message ) ); parse( message, cmd, charsmax( cmd ), arg, charsmax( arg ) )
  226.  
  227.     //--------------- Show the current map + map time ---------------//
  228.     for( new i = 0; i < sizeof( currentmapcmds ); i++ ) if( equali( cmd, currentmapcmds[ i ] ) )
  229.         return ColorChat( id, "Current map: ^3%s^1. Map time: ^3%02d^1:^3%02d^1:^3%02d^1.", CurrentMap(), votesystem[ Maptime ]/3600, votesystem[ Maptime ]/60, votesystem[ Maptime ]%60 )
  230.  
  231.     //--------------- Show the time ---------------//
  232.     for( new i = 0; i < sizeof( thetimecmds ); i++ ) if( equali( cmd, thetimecmds[ i ] ) )
  233.         return ColorChat( id, "%s.", Getformattime( "Time: ^3%H^1:^3%M^1:^3%S^4 - ^1Date: ^3%d^1.^3%m^1.^3%Y^1", get_systime( BaseSettings[ TimeZone ] ) ) )
  234.  
  235.     //--------------- Show when the votemap will start ---------------//
  236.     for( new i = 0; i < sizeof( timeleftcmds ); i++ ) if( equali( cmd, timeleftcmds[ i ] ) )
  237.     {
  238.         //--------------- Vote status ---------------//
  239.         if( votestatus( id ) ) return 1
  240.  
  241.         return ColorChat( id, "The ^3votemap^1 will be start in ^3%02d^1:^3%02d^1 %s%s.", votesystem[ Timeleft ]/60, votesystem[ Timeleft ]%60, votesystem[ Timeleft ]/60 > 0 ? "minute" : "second", ( ( votesystem[ Timeleft ]%60 > 1 && votesystem[ Timeleft ]/60 < 1 ) || votesystem[ Timeleft ]/60 > 1 ) ? "s" : "" )
  242.     }
  243.  
  244.     //--------------- Rock the vote ---------------//
  245.     for( new i = 0; i < sizeof( rockthevotecmds ); i++ ) if( equali( cmd, rockthevotecmds[ i ] ) )
  246.     {
  247.         //--------------- Vote status ---------------//
  248.         if( votestatus( id ) ) return 1
  249.  
  250.         //--------------- Countdown before you can rock the vote ---------------//
  251.         if( votesystem[ Maptime ] < votesystem[ Mapcountdown ] ) return ColorChat( id, "You have to wait ^3%02d^1:^3%02d^1 %s%s for rock the vote.",
  252.         ( votesystem[ Mapcountdown ] - votesystem[ Maptime ] )/60, ( votesystem[ Mapcountdown ] - votesystem[ Maptime ] )%60,
  253.         ( votesystem[ Mapcountdown ] - votesystem[ Maptime ] )/60 > 0 ? "minute" : "second", ( ( ( votesystem[ Mapcountdown ] - votesystem[ Maptime ] )%60 > 1 && ( votesystem[ Mapcountdown ] - votesystem[ Maptime ] )/60 < 1 ) || ( votesystem[ Mapcountdown ] - votesystem[ Maptime ] )/60 > 1 ) ? "s" : "" )
  254.  
  255.         //--------------- if you already rocked the vote ---------------//
  256.         if( playersystem[ id ][ RTV ] ) return ColorChat( id, "You have already rocked the vote. ^3%d^1 players remaning.", VotesRemain() )
  257.  
  258.         if( VotesRemain() <= votesystem[ rtvcounter ] )
  259.         {
  260.             votesystem[ adminhud ] = false
  261.  
  262.             StartVote()
  263.             return ColorChat( 0, "^3%n^1 has rocked the vote, ^3votemap^1 has started.", id )
  264.         }
  265.  
  266.         votesystem[ rtvcounter ]++
  267.         playersystem[ id ][ RTV ] = true
  268.         return ColorChat( 0, "^3%n^1 has rocked the vote, ^3%d^1 players remaning.", id, VotesRemain() )
  269.     }
  270.  
  271.     //--------------- UnRock the vote ---------------//
  272.     for( new i = 0; i < sizeof( unrockthevotecmds ); i++ ) if( equali( cmd, unrockthevotecmds[ i ] ) )
  273.     {
  274.         //--------------- Vote status ---------------//
  275.         if( votestatus( id ) ) return 1
  276.  
  277.         //--------------- if you didnt rocked the vote yet ---------------//
  278.         if( !playersystem[ id ][ RTV ] ) return ColorChat( id, "You have not rocked the vote yet." )
  279.  
  280.         votesystem[ rtvcounter ]--
  281.         playersystem[ id ][ RTV ] = false
  282.         return ColorChat( 0, "^3%n^1 has unrocked the vote, ^3%d^1 players remaning.", id, VotesRemain() )
  283.     }
  284.  
  285.     //--------------- Show recent maps ---------------//
  286.     for( new i = 0; i < sizeof( recentmapcmds ); i++ ) if( equali( cmd, recentmapcmds[ i ] ) )
  287.     {
  288.         //--------- Initialize arrays ---------//
  289.         new HoldTimes[ 6 ]; arrayset( HoldTimes, 0, charsmax( HoldTimes ) )
  290.         new HoldMaps[ 6 ][ 64 ]; arrayset2D( HoldMaps, 6, 64, EOS )
  291.  
  292.         //--------- Find recent maps ---------//
  293.         for( new map = 0; map < totalmaps; map++ )
  294.         {
  295.             //--------- Make sure to not count the current map ---------//
  296.             if( equali( mapsystem[ map ][ mapname ], CurrentMap() ) ) continue
  297.  
  298.             new playedTime = str_to_num( mapsystem[ map ][ mapplayed ] )
  299.             for( new j = 0; j < 6; j++ )
  300.             {
  301.                 //--------- Insert map into sorted list ---------//
  302.                 if( playedTime > HoldTimes[ j ] )
  303.                 {
  304.                     //--------- Shift maps down to make space ---------//
  305.                     for( new k = 5; k > j; k-- )
  306.                     {
  307.                         HoldTimes[ k ] = HoldTimes[ k - 1 ]
  308.                         copy( HoldMaps[ k ], charsmax( HoldMaps[] ), HoldMaps[ k - 1 ] )
  309.                     }
  310.  
  311.                     HoldTimes[ j ] = playedTime
  312.                     copy( HoldMaps[ j ], charsmax( HoldMaps[] ), mapsystem[ map ][ mapname ] )
  313.                     break
  314.                 }
  315.             }
  316.         }
  317.  
  318.         //--------- Check if there are any recent maps ---------//
  319.         if( HoldMaps[ 0 ][ 0 ] == EOS ) return ColorChat( id, "No maps have been played yet." )
  320.  
  321.         //--------- Build message to display ---------//
  322.         new msg[ 256 ], recentmaps = 0, countmaps = 0
  323.         for( new j = 0; j < BaseSettings[ MaxRecentMaps ]; j++ )
  324.         {
  325.             if( HoldMaps[ j ][ 0 ] == EOS ) continue
  326.  
  327.             recentmaps += formatex( msg[ recentmaps ], charsmax( msg ) - recentmaps, "%s%s", countmaps == 0 ? "" : ", ", HoldMaps[ j ] )
  328.             countmaps++
  329.         }
  330.  
  331.         if( countmaps == 0 ) return ColorChat( id, "No recent maps to display." )
  332.  
  333.         return ColorChat( id, "The last ^4%d^1 recent maps: ^3%s^1.", countmaps, msg )
  334.     }
  335.  
  336.     //--------------- Show noms ---------------//
  337.     for( new i = 0; i < sizeof( nomcmds ); i++ ) if( equali( cmd, nomcmds[ i ] ) )
  338.     {
  339.         //--------------- Vote status ---------------//
  340.         if( votestatus( id ) ) return 1
  341.  
  342.         //--------------- if there is no nominations ---------------//
  343.         if( !votesystem[ nomcounter ] ) return ColorChat( id, "There is no ^3nominations^1 yet." )
  344.  
  345.         new msg[ 512 ], noms = 0
  346.         for( new i = 0; i < totalmaps; i++ ) if( mapsystem[ i ][ nominated ] )
  347.             noms += formatex( msg[ noms ], charsmax( msg ) -noms, ", %s", mapsystem[ i ][ mapname ] )
  348.  
  349.         return ColorChat( id, "^4%d^1 maps nominated: ^3%s^1.", votesystem[ nomcounter ], msg[ 2 ] )
  350.     }
  351.  
  352.     //--------------- maps menu ---------------//
  353.     for( new i = 0; i < sizeof( mapsmenucmds ); i++ ) if( equali( cmd, mapsmenucmds[ i ] ) )
  354.     {
  355.         //--------------- Vote status ---------------//
  356.         if( votestatus( id ) ) return 1
  357.  
  358.         sortmenu[ id ] = 0
  359.         searchmap[ id ] = false
  360.  
  361.         menupage[ id ] = ( equali( arg, "" ) ? 0 : str_to_num( arg ) - 1 )
  362.         return mapsmenu( id )
  363.     }
  364.  
  365.     //--------------- nominate ---------------//
  366.     if( strlen( cmd ) >= 4 )
  367.     {
  368.         new found = 0, foundid = 0
  369.         //-------------------- Search in the mapsystem vault for map which contain cmd --------------------//
  370.         for( new i = 0; i < totalmaps; i++ )
  371.         {
  372.             if( containi( mapsystem[ i ][ mapname ], cmd ) != -1 )
  373.             {
  374.                 if( equali( mapsystem[ i ][ mapname ], CurrentMap() ) || ( mapsystem[ i ][ nominated ] && IsMapNominated( mapsystem[ i ][ mapname ] ) != id ) ) continue
  375.  
  376.                 copy( searchmap[ id ], charsmax( searchmap ), cmd )
  377.                 found++
  378.                 foundid = i
  379.             }
  380.         }
  381.  
  382.         if( found == 1 ) NominateMap( id, foundid )
  383.         else if( found > 1 ) mapsmenu( id )
  384.     }
  385.  
  386.     //--------------- Admin - Random map ---------------//
  387.     for( new i = 0; i < sizeof( randommapcmds ); i++ ) if( equali( cmd, randommapcmds[ i ] ) && hasaccess( id ) )
  388.     {
  389.         new randommapcheck = random( totalmaps )
  390.  
  391.         //--------- Check if enough maps exist ---------//
  392.         if( totalmaps <= 1 ) return ColorChat( id, "There are not enough maps to do a ^3random map^1 between." )
  393.  
  394.         //--------- Make sure not to change to the current map ---------//
  395.         if( equali( mapsystem[ randommapcheck ][ mapname ], CurrentMap() ) )
  396.         {
  397.             if( randommapcheck == totalmaps - 1 ) randommapcheck -= 1
  398.             else randommapcheck += 1
  399.         }
  400.  
  401.         copy( randommap, charsmax( randommap ), mapsystem[ randommapcheck ][ mapname ] )
  402.         set_task( 0.5, "ChangeMap", 0, randommap, charsmax( randommap ) )
  403.  
  404.         return ColorChat( 0, "Admin: ^3%n^1 has randomly changed the map to ^4%s^1.", id, randommap )
  405.     }
  406.  
  407.     //--------------- Start votemap ---------------//
  408.     for( new i = 0; i < sizeof( startvotecmds ); i++ ) if( equali( cmd, startvotecmds[ i ] ) && hasaccess( id ) )
  409.     {
  410.         //--------------- Vote status ---------------//
  411.         if( votestatus( id ) ) return 1
  412.  
  413.         votesystem[ adminhud ] = true
  414.         StartVote()
  415.  
  416.         return ColorChat( 0, "Admin: ^3%n^1 has started the votemap.", id )
  417.     }
  418.  
  419.     //--------------- Stop votemap ---------------//
  420.     for( new i = 0; i < sizeof( stopvotecmds ); i++ ) if( equali( cmd, stopvotecmds[ i ] ) && hasaccess( id ) )
  421.     {
  422.         //--------------- Vote status ---------------//
  423.         if( votestate == Vote_NotRunning ) return ColorChat( id, "There is no vote ^3running^1." )
  424.  
  425.         //--------------- remove tasks ---------------//
  426.         if( task_exists( CountdowntovoteTaskID ) ) remove_task( CountdowntovoteTaskID )
  427.         if( task_exists( TimetochangeTaskID ) ) remove_task( TimetochangeTaskID )
  428.         if( task_exists( MenuTimeTaskID ) ) remove_task( MenuTimeTaskID )
  429.  
  430.         votestate = Vote_NotRunning
  431.         votesystem[ Timeleft ] = BaseSettings[ DefaultTime ]
  432.         votesystem[ Countdown ] = BaseSettings[ VoteCountdown ]
  433.         votesystem[ MenuTimer ] = BaseSettings[ MenuCountdown ]
  434.  
  435.         votesystem[ Allvotes ] = 0
  436.         votesystem[ rtvcounter ] = 0
  437.         votesystem[ nomcounter ] = 0
  438.  
  439.         arrayset( mapvotes, 0, sizeof mapvotes )
  440.         for( new i = 0; i < totalmaps; i++ ) mapsystem[ i ][ nominated ] = false    // reset the nominated maps
  441.         arrayset2D( playersystem, get_maxplayers(), MyStats, false )                // reset the players system
  442.  
  443.         set_task( 1.0, "Timetovote", TimeLeftTaskID, .flags = "b" )
  444.         show_menu( 0, 0, "^n", 1 )
  445.         return ColorChat( 0, "Admin: ^3%n^1 has stopped the votemap.", id )
  446.     }
  447.  
  448.     //--------------- Extend the map ---------------//
  449.     for( new i = 0; i < sizeof( extendcmds ); i++ ) if( equali( cmd, extendcmds[ i ] ) && hasaccess( id ) )
  450.     {
  451.         //--------------- Vote status ---------------//
  452.         if( votestatus( id, true ) ) return 1
  453.  
  454.         //--------------- If nothing wrote in the time it will add automatic ExtendTime ---------------//
  455.         if( equali( arg, "" ) )
  456.         {
  457.             votesystem[ votestate == Vote_Nextmap ? Timeleftnextmap : Timeleft ] = BaseSettings[ ExtendTime ]
  458.             return ColorChat( 0, "Admin: ^3%n^1 has extended the map to ^3%d^1 minutes.", id, BaseSettings[ ExtendTime ]/60 )
  459.         }
  460.  
  461.         //--------------- If only + wrote in the time it will add the ExtedTime ---------------//
  462.         if( equali( arg, "+" ) )
  463.         {
  464.             votesystem[ votestate == Vote_Nextmap ? Timeleftnextmap : Timeleft ] += BaseSettings[ ExtendTime ]
  465.             return ColorChat( 0, "Admin: ^3%n^1 has extended the map by ^3%d^1 minutes.", id, BaseSettings[ ExtendTime ]/60 )
  466.         }
  467.  
  468.         new amount = str_to_num( arg )
  469.         //--------------- If the number is not valid ---------------//
  470.         if( amount <= 0 ) return ColorChat( id, "You must type a number." )
  471.  
  472.         //--------------- If the number start with + then it will add time ---------------//
  473.         if( containi( arg, "+" ) != -1 )
  474.         {
  475.             votesystem[ votestate == Vote_Nextmap ? Timeleftnextmap : Timeleft ] += amount
  476.             return ColorChat( 0, "Admin: ^3%n^1 has extended the map by ^3%d^1 minute%s ^3%d^1 second%s.", id, amount/60, amount/60 > 1 ? "s" : "", amount%60, amount%60 > 1 ? "s" : "" )
  477.         }
  478.  
  479.         //--------------- The amount of time you wrote ---------------//
  480.         votesystem[ votestate == Vote_Nextmap ? Timeleftnextmap : Timeleft ] = amount
  481.         return ColorChat( 0, "Admin: ^3%n^1 has extended the map to ^3%d^1 minute%s ^3%d^1 second%s.", id, amount/60, amount/60 > 1 ? "s" : "", amount%60, amount%60 > 1 ? "s" : "" )
  482.     }
  483.  
  484.     return 0
  485. }
  486.  
  487. //--------------- Random map ---------------//
  488. public ChangeMap( const map[] ) if( is_map_valid( map ) ) engine_changelevel( map )
  489.  
  490. //--------------- Start vote ---------------//
  491. public StartVote()
  492. {
  493.     //--------------- remove tasks ---------------//
  494.     if( task_exists( TimeLeftTaskID ) ) remove_task( TimeLeftTaskID )
  495.     if( task_exists( CountdowntovoteTaskID ) ) remove_task( CountdowntovoteTaskID )
  496.  
  497.     //--------------- prepare some functions ---------------//
  498.     votestate = Vote_Starting
  499.     votesystem[ Countdown ] = BaseSettings[ VoteCountdown ]
  500.  
  501.     set_task( 1.0, "Countdowntovote", CountdowntovoteTaskID, .flags = "b" )
  502.     return 1
  503. }
  504.  
  505. //--------------- Countdown for vote ---------------//
  506. public Countdowntovote()
  507. {
  508.     //--------------- Failsafe ---------------//
  509.     if( votesystem[ Countdown ] <= 0 && task_exists( CountdowntovoteTaskID ) ) return remove_task( CountdowntovoteTaskID )
  510.  
  511.     if( --votesystem[ Countdown ] <= 0 )
  512.     {
  513.         //--------------- remove tasks ---------------//
  514.         if( task_exists( CountdowntovoteTaskID ) ) remove_task( CountdowntovoteTaskID )
  515.         if( task_exists( MenuTimeTaskID ) ) remove_task( MenuTimeTaskID )
  516.  
  517.         //--------------- prepare some functions ---------------//
  518.         votestate = Vote_Running
  519.         votesystem[ MenuTimer ] = BaseSettings[ MenuCountdown ] * 10
  520.  
  521.         for( new i = 1; i <= get_maxplayers(); i++ ) if( is_user_connected( i ) ) playersystem[ i ][ dontshowmenu ] = false
  522.  
  523.         SortCustom2D( mapsystem, totalmaps, "SortMaps" )
  524.  
  525.         client_cmd( 0, "spk Gman/Gman_Choose%d", random_num( 1, 2 ) )
  526.         set_task( 0.1, "MenuTime", MenuTimeTaskID, .flags = "b" )
  527.         return 1
  528.     }
  529.  
  530.     new Spk[ 10 ]; num_to_word( votesystem[ Countdown ], Spk, charsmax( Spk ) )
  531.     client_cmd( 0, "spk vox/%s", Spk )
  532.  
  533.     new msg[ 128 ]; formatex( msg, charsmax( msg ), "%svote will be start in %d second%s", votesystem[ adminhud ] ? "Admin vote^n-------------------^n" : "", votesystem[ Countdown ], votesystem[ Countdown ] > 1 ? "s" : "" )
  534.     GetHudMsg( 0, false, msg, 0, 255, 0, _, 0.10, 0, _, 1.0 )
  535.     return 1
  536. }
  537.  
  538. //--------------- Menu timer ---------------//
  539. public MenuTime()
  540. {
  541.     //--------------- Failsafe ---------------//
  542.     if( votesystem[ MenuTimer ] <= 0 && task_exists( MenuTimeTaskID ) ) return remove_task( MenuTimeTaskID )
  543.  
  544.     if( --votesystem[ MenuTimer ] <= 0 )
  545.     {
  546.         //--------------- remove tasks ---------------//
  547.         if( task_exists( MenuTimeTaskID ) ) remove_task( MenuTimeTaskID )
  548.  
  549.         show_menu( 0, 0, "^n", 1 )
  550.         return CheckResults()
  551.     }
  552.  
  553.     for( new i = 1; i <= get_maxplayers(); i++ )
  554.     {
  555.         //-------------------- If the player is not connected or bot or disable the menu --------------------//
  556.         if( !is_user_connected( i ) || is_user_bot( i ) || playersystem[ i ][ dontshowmenu ] ) continue
  557.  
  558.         MenuShitFunction = true
  559.         show_menu( i, 0, "^n", 1 )
  560.         ShowVote( i )
  561.         MenuShitFunction = false
  562.     }
  563.  
  564.     return 1
  565. }
  566.  
  567. //--------------- Show vote ---------------//
  568. public ShowVote( id )
  569. {
  570.     new item[ 512 ], Precent[ 32 ], ccc = BaseSettings[ MapsInMenu ]
  571.     new menu = menu_create( fmt( "\r[\w %s \r]\w Choose the map you would like to play next:^n^n\y>\d Time left: \r%.1f second%s", BaseSettings[ PREFIX ], float( votesystem[ MenuTimer ] ) / 10.0, votesystem[ MenuTimer ] <= 1 ? "" : "s" ), "sub_vote" )
  572.  
  573.     for( new i = 0; i < ( ccc > 5 ? 5 : ccc ); i++ )
  574.     {
  575.         //--------------- maps precent ---------------//
  576.         if( mapvotes[ i ] > 0 ) Precent[ i ] = ( ( mapvotes[ i ] * 100 ) / ( votesystem[ Allvotes ] ) )
  577.  
  578.         //--------------- map button ---------------//
  579.         formatex( item, charsmax( item ), "%s%s \d[\w votes: \y%d \d][\y %d%% \d]%s", ( i == playersystem[ id ][ mychoose ] && ( playersystem[ id ][ voted ] || playersystem[ id ][ revote ] ) ) ? "\y" : "", mapsystem[ i ][ mapname ], mapvotes[ i ], Precent[ i ], i == ccc - 1 ? "^n" : "" )
  580.         MenuCallback( menu, item, fmt( "%d.", i + 1 ), ( !playersystem[ id ][ voted ] || ( i == playersystem[ id ][ mychoose ] && !playersystem[ id ][ revote ] ) ) ? false : true )
  581.     }
  582.  
  583.     //--------------- Current map precent ---------------//
  584.     if( mapvotes[ ccc ] > 0 ) Precent[ ccc ] = ( ( mapvotes[ ccc ] * 100 ) / ( votesystem[ Allvotes ] ) )
  585.  
  586.     //--------------- Current map button ---------------//
  587.     formatex( item, charsmax( item ), "%s%s \r( Current map ) \d[\w votes: \y%d \d][\y %d%% \d]", ( ccc == playersystem[ id ][ mychoose ] && ( playersystem[ id ][ voted ] || playersystem[ id ][ revote ] ) ) ? "\y" : "", CurrentMap(), mapvotes[ ccc ], Precent[ ccc ] )
  588.     MenuCallback( menu, item, fmt( "%d.", BaseSettings[ MapsInMenu ] + 1 ), ( !playersystem[ id ][ voted ] || ( ccc == playersystem[ id ][ mychoose ] && !playersystem[ id ][ revote ] ) ) ? false : true )
  589.  
  590.     //--------------- dont show the menu button ---------------//
  591.     menu_setprop( menu, MPROP_EXITNAME, "Dont show me the menu" )
  592.     menu_display( id, menu )
  593.     return 1
  594. }
  595.  
  596. public sub_vote( id, menu, item )
  597. {
  598.     if( item == MENU_EXIT )
  599.     {
  600.         if( MenuShitFunction || MenuTimer <= 0 || votestate == Vote_NotRunning ) return menu_destroy( menu )
  601.  
  602.         //--------------- dont show the menu button ---------------//
  603.         return playersystem[ id ][ dontshowmenu ] = true
  604.     }
  605.  
  606.     //--------------- Revote system ---------------//
  607.     if( playersystem[ id ][ voted ] && !playersystem[ id ][ revote ] )
  608.     {
  609.         votesystem[ Allvotes ]--
  610.         mapvotes[ playersystem[ id ][ mychoose ] ]--
  611.  
  612.         playersystem[ id ][ voted ] = false
  613.         playersystem[ id ][ revote ] = true
  614.  
  615.         ColorChat( 0, "^3%n^1 has unvoted for ^4%s^1.", id, playersystem[ id ][ selectedmap ] )
  616.         return ShowVote( id )
  617.     }
  618.  
  619.     //--------------- current map button ---------------//
  620.     if( item == BaseSettings[ MapsInMenu ] )
  621.     {
  622.         copy( playersystem[ id ][ selectedmap ], 64, CurrentMap() )
  623.         ColorChat( 0, "^3%n^1 has voted to stay in the current map. ^3[^1 %s ^3]", id, CurrentMap() )
  624.     }
  625.     //--------------- selected map button ---------------//
  626.     else
  627.     {
  628.         copy( playersystem[ id ][ selectedmap ], 64, mapsystem[ item ][ mapname ] )
  629.         ColorChat( 0, "^3%n^1 has voted for ^4%s^1.", id, playersystem[ id ][ selectedmap ] )
  630.     }
  631.  
  632.     client_cmd( id, "spk sound/buttons/lightswitch2.wav" )
  633.     votesystem[ Allvotes ]++
  634.     mapvotes[ item ]++
  635.     playersystem[ id ][ voted ] = true
  636.     playersystem[ id ][ mychoose ] = item
  637.  
  638.     return ShowVote( id )
  639. }
  640.  
  641. //--------------- Sort maps ---------------//
  642. public SortMaps( const map1[], const map2[], const array[][] )
  643. {
  644.     //--------- Prevent current map from being selected ----------//
  645.     if( equali( map1[ mapname ], CurrentMap() ) ) return 1
  646.     if( equali( map2[ mapname ], CurrentMap() ) ) return -1
  647.  
  648.     //--------- Ascending nominated maps ----------//
  649.     if( map1[ nominated ] && !map2[ nominated ] ) return -1
  650.     else if( !map1[ nominated ] && map2[ nominated ] ) return 1
  651.  
  652.     switch( random( 3 ) )
  653.     {
  654.         case 0: return 0
  655.         case 1: return 1
  656.         default: return -1
  657.     }
  658.  
  659.     return 0
  660. }
  661.  
  662. //--------------- Results ---------------//
  663. CheckResults()
  664. {
  665.     new winner, winnercount, tienum, tie[ 10 ]
  666.  
  667.     //--------- Check for ties --------//
  668.     for( new i = 0; i <= BaseSettings[ MapsInMenu ]; i++ )
  669.     {
  670.         //--------- Add to vault if ties --------//
  671.         if( mapvotes[ i ] == winnercount ) tie[ tienum++ ] = i
  672.         //--------- Reset ties vault if there is higher votes then the votes in vault --------//
  673.         else if( mapvotes[ i ] > winnercount )
  674.         {
  675.             winner = i
  676.             winnercount = mapvotes[ i ]
  677.  
  678.             arrayset( tie, 0, sizeof tie )
  679.             tienum = 0
  680.         }
  681.     }
  682.  
  683.     //--------- no one voted --------//
  684.     if( !winnercount ) winner = random( BaseSettings[ MapsInMenu ] )
  685.     //--------- Tie --------//
  686.     else if( tienum && mapvotes[ tie[ 0 ] ] == winnercount && winnercount )
  687.     {
  688.         winner = tie[ random( tienum ) ]
  689.         ColorChat( 0, "^3%d^1 maps has the same number of votes. ^3random one^1 will be chosen.", tienum )
  690.     }
  691.  
  692.     //--------- map won --------//
  693.     if( winner != BaseSettings[ MapsInMenu ] )
  694.     {
  695.         votestate = Vote_Nextmap
  696.         votesystem[ Timeleftnextmap ] = BaseSettings[ NextmapTimeleft ]
  697.  
  698.         copy( votesystem[ Nextmap ], 64, mapsystem[ winner ][ mapname ] )
  699.  
  700.         set_task( 1.0, "Timetochange", TimetochangeTaskID, .flags = "b" )
  701.  
  702.         if( winnercount ) ColorChat( 0, "The chosen map is ^4%s^1 with ^3%d^1 vote%s. [^3 %.f%%%% ^1].", mapsystem[ winner ][ mapname ], mapvotes[ winner ], mapvotes[ winner ] == 1 ? "" : "s", ( mapvotes[ winner ] * 100.0 / votesystem[ Allvotes ] ) )
  703.         else ColorChat( 0, "No one voted. The server chose by random and the chosen map is ^4%s^1.", mapsystem[ winner ][ mapname ] )
  704.     }
  705.     //--------- Current map won --------//
  706.     else if( winner == BaseSettings[ MapsInMenu ] )
  707.     {
  708.         votestate = Vote_NotRunning
  709.         votesystem[ Timeleft ] = BaseSettings[ ExtendTime ]
  710.  
  711.         set_task( 1.0, "Timetovote", TimeLeftTaskID, .flags = "b" )
  712.  
  713.         if( winnercount ) ColorChat( 0, "The current map ^4%s^1 will be extended for ^3%d^1 minutes.", CurrentMap(), BaseSettings[ ExtendTime ]/60 )
  714.         else ColorChat( 0, "No one voted. The server chose by random and the chosen map is the current map ^4%s^1 will be extended for ^3%d^1 minutes.", CurrentMap(), BaseSettings[ ExtendTime ]/60 )
  715.     }
  716.  
  717.     votesystem[ Allvotes ] = 0
  718.     votesystem[ rtvcounter ] = 0
  719.     votesystem[ nomcounter ] = 0
  720.  
  721.     arrayset( mapvotes, 0, sizeof mapvotes )
  722.     for( new i = 0; i < totalmaps; i++ ) mapsystem[ i ][ nominated ] = false    // reset the nominated maps
  723.     arrayset2D( playersystem, get_maxplayers(), MyStats, false )                // reset the players system
  724.  
  725.     return 1
  726. }
  727.  
  728. //--------------- Time to change ---------------//
  729. public Timetochange()
  730. {
  731.     //--------------- Failsafe ---------------//
  732.     if( votesystem[ Timeleftnextmap ] <= 0 && task_exists( TimetochangeTaskID ) ) return remove_task( TimetochangeTaskID )
  733.  
  734.     if( --votesystem[ Timeleftnextmap ] <= 0 )
  735.     {
  736.         //--------------- remove tasks ---------------//
  737.         if( task_exists( TimetochangeTaskID ) ) remove_task( TimetochangeTaskID )
  738.  
  739.         set_task( 1.0, "ChangeMap", 0, votesystem[ Nextmap ], charsmax( votesystem[ Nextmap ] ) )
  740.         return ColorChat( 0, "The ^3map^1 will be change to ^3%s^1.", votesystem[ Nextmap ] )
  741.     }
  742.  
  743.     if( votesystem[ Timeleftnextmap ] < 11 )
  744.     {
  745.         new Spk[ 10 ]; num_to_word( votesystem[ Timeleftnextmap ], Spk, charsmax( Spk ) )
  746.         client_cmd( 0, "spk vox/%s", Spk )
  747.  
  748.         new msg[ 256 ]; formatex( msg, charsmax( msg ), "The map will be change in %d second%s", votesystem[ Timeleftnextmap ], votesystem[ Timeleftnextmap ] == 1 ? "" : "s" )
  749.         GetHudMsg( 0, false, msg, 255, 0, 0, _, 0.10, 0, _, 1.0 )
  750.     }
  751.  
  752.     return 1
  753. }
  754.  
  755. //-------------------- map functions - addtime --------------------//
  756. public mapaddtime()
  757. {
  758.     new Line[ 512 ], name[ 64 ], date[ 64 ], played[ 64 ], popularity[ 64 ], FileLine = -1, File = fopen( mapini, "rt" )
  759.     while( !feof( File ) )
  760.     {
  761.         //-------------------- Line counter --------------------//
  762.         FileLine++
  763.  
  764.         //-------------------- File info --------------------//
  765.         fgets( File, Line, charsmax( Line ) ); trim( Line )
  766.  
  767.         //-------------------- if line start with ; or empty skip --------------------//
  768.         if( Line[ 0 ] == ';' || !Line[ 0 ] ) continue
  769.  
  770.         //-------------------- Line info --------------------//
  771.         parse( Line, name, charsmax( name ), date, charsmax( date ), played, charsmax( played ), popularity, charsmax( popularity ) )
  772.  
  773.         //-------------------- add time only to the current map --------------------//
  774.         if( equali( name, CurrentMap() ) ) write_file( mapini, fmt( "%s %d %d %d", name, str_to_num( date ), str_to_num( played ), str_to_num( popularity ) + 1 ), FileLine )
  775.     }
  776.     fclose( File )
  777. }
  778.  
  779. //-------------------- map functions - Load maps --------------------//
  780. loadmaps()
  781. {
  782.     arrayset2D( mapsystem, totalmaps, MapStats, 0 ) // reset the map system memory
  783.     totalmaps = 0
  784.  
  785.     new Line[ 512 ], CuttedLine[ 512 ], checkmap[ 64 ], File = fopen( mapini, "rt" )
  786.     while( !feof( File ) )
  787.     {
  788.         //-------------------- File info --------------------//
  789.         fgets( File, Line, charsmax( Line ) ); trim( Line )
  790.  
  791.         //-------------------- if line start with ; or empty --------------------//
  792.         if( Line[ 0 ] == ';' || !Line[ 0 ] ) continue
  793.  
  794.         //-------------------- Line map for check --------------------//
  795.         parse( Line, checkmap, charsmax( checkmap ) )
  796.  
  797.         //-------------------- if not valid map --------------------//
  798.         if( !is_map_valid( checkmap ) ) continue
  799.  
  800.         //-------------------- if line contain ; make sure to not count it as part of the line --------------------//
  801.         strtok( Line, Line, charsmax( Line ), CuttedLine, charsmax( CuttedLine ), ';' )
  802.  
  803.         //-------------------- load the maps into vault --------------------//
  804.         parse( Line, mapsystem[ totalmaps ][ mapname ], sizeof( mapsystem ), mapsystem[ totalmaps ][ mapdate ], sizeof( mapsystem ),
  805.         mapsystem[ totalmaps ][ mapplayed ], sizeof( mapsystem ), mapsystem[ totalmaps ][ mappopularity ], sizeof( mapsystem ) )
  806.         totalmaps++
  807.     }
  808.     fclose( File )
  809. }
  810.  
  811. //-------------------- map functions - maps.ini generator --------------------//
  812. generatemaps( bool:valve = false )
  813. {
  814.     new mapdir[ 64 ], bool:skip = false, mapsdir = open_dir( "maps", mapdir, charsmax( mapdir ), _, valve ? true : false, valve ? NULL_STRING : "GAME" )
  815.     if( mapsdir )
  816.     {
  817.         while( next_file( mapsdir, mapdir, charsmax( mapdir ) ) )
  818.         {
  819.             //-------------------- Check if the map is valid --------------------//
  820.             replace( mapdir, charsmax( mapdir ), ".bsp", "" )
  821.             if( mapdir[ 0 ] == '.' || !is_map_valid( mapdir ) ) continue
  822.  
  823.             skip = false
  824.             //-------------------- Check if the map already in the file --------------------//
  825.             for( new i = 0; i < totalmaps; i++ )
  826.             {
  827.                 //-------------------- Load the size of the map --------------------//
  828.                 if( equali( mapsystem[ i ][ mapname ], mapdir ) ) skip = true, mapsystem[ i ][ mapsize ] = file_size( fmt( "maps/%s.bsp", mapdir ), 0 )
  829.                 //-------------------- Change the curentmap last played date --------------------//
  830.                 if( equali( mapsystem[ i ][ mapname ], CurrentMap() ) ) write_file( mapini, fmt( "%s %d %d %d", CurrentMap(), str_to_num( mapsystem[ i ][ mapdate ] ), get_systime( BaseSettings[ TimeZone ] ), str_to_num( mapsystem[ i ][ mappopularity ] ) ), i )
  831.             }
  832.             //-------------------- skip if the map is in the file or add if not --------------------//
  833.             if( !skip ) write_file( mapini, fmt( "%s %d 0 0", mapdir, get_systime( BaseSettings[ TimeZone ] ) ), findemptyline( mapini ) )
  834.         }
  835.         close_dir( mapsdir )
  836.     }
  837. }
  838.  
  839. //-------------------- Settings functions - load --------------------//
  840. loadsettings() // thanks to ocixcrom
  841. {
  842.     //-------------------- default settings ( if there is no settings then this is the default ) --------------------//
  843.     defaultbasesettings()
  844.  
  845.     new Line[ 256 ], CuttedLine[ 256 ], option[ 128 ], text[ 128 ], File = fopen( settingsini, "rt" )
  846.  
  847.     //-------------------- if the file dosn't exist then create it --------------------//
  848.     if( !File )
  849.     {
  850.         write_file( settingsini, "========== General Settings ==========", -1 )
  851.         write_file( settingsini, "prefix          = VM                     ; prefix name", -1 )
  852.         write_file( settingsini, "log_folder      = VM/                    ; Folder name for storing log files", -1 )
  853.         write_file( settingsini, "valvemaps       = no                     ; allow the search for maps to search in valve folder ( once its active, to remove valve maps needed manual work *im work on an automatic way )", -1 )
  854.         write_file( settingsini, "timezone        = 0                      ; Time Zone in seconds; 10800 for Israel, 7200 for one hour earlier", -1 )
  855.         write_file( settingsini, "access          = ADMIN_MAP              ; access to admin commands^n", -1 )
  856.         write_file( settingsini, "mapsinmenu      = 5                      ; The amount of maps to appear in the menu ( dont count the extend & max is 5 )", -1 )
  857.         write_file( settingsini, "maxrecentmaps   = 3                      ; The amount of maps to appear in the recent maps ( not include the correct map & max is 6 )", -1 )
  858.  
  859.         write_file( settingsini, "^n========== Timers Settings ( in seconds ) ==========", -1 )
  860.         write_file( settingsini, "defaulttime     = 600                    ; The time has set when the vote has stopped", -1 )
  861.         write_file( settingsini, "countdownrtv    = 60                     ; The time has set as countdown for rtv", -1 )
  862.         write_file( settingsini, "votecountdown   = 4                      ; The time has left to countdown for the vote menu to appear", -1 )
  863.         write_file( settingsini, "menucountdown   = 16                     ; The time has left to the menu to countdown to 0", -1 )
  864.         write_file( settingsini, "extendtime      = 600                    ; The time has set when extended the map", -1 )
  865.         write_file( settingsini, "nextmaptime     = 10                     ; The time has left to the next map to change", -1 )
  866.     }
  867.  
  868.     //-------------------- Read the settings --------------------//
  869.     if( File )
  870.     {
  871.         while( !feof( File ) )
  872.         {
  873.             //-------------------- File info --------------------//
  874.             fgets( File, Line, charsmax( Line ) ); trim( Line )
  875.  
  876.             switch( Line[ 0 ] )
  877.             {
  878.                 //-------------------- if line start with ; or empty skip --------------------//
  879.                 case EOS, ';': continue
  880.                 default:
  881.                 {
  882.                     //-------------------- make sure to be able to write info in the same line without count it as the line --------------------//
  883.                     strtok( Line, Line, charsmax( Line ), CuttedLine, charsmax( CuttedLine ), ';' ); trim( Line )
  884.  
  885.                     //-------------------- Split the line at '=' so that everything after the '=' is processed --------------------//
  886.                     strtok( Line, option, charsmax( option ), text, charsmax( text ), '=' ); trim( option ); trim( text )
  887.  
  888.                     //-------------------- if text is empty skip --------------------//
  889.                     if( text[ 0 ] == EOS ) continue
  890.  
  891.                     //-------------------- prefix --------------------//
  892.                     if( equali( option, "prefix" ) ) copy( BaseSettings[ PREFIX ], charsmax( BaseSettings ), text )
  893.                     //-------------------- log folder --------------------//
  894.                     if( equali( option, "log_folder" ) ) copy( BaseSettings[ LOG_FOLDER ], charsmax( BaseSettings ), text )
  895.                     //-------------------- valve maps --------------------//
  896.                     if( equali( option, "valvemaps" ) ) BaseSettings[ AllowValveMaps ] = equali( text, "yes" ) ? true : false
  897.                     //-------------------- timezone --------------------//
  898.                     if( equali( option, "timezone" ) ) BaseSettings[ TimeZone ] = str_to_num( text )
  899.                     //-------------------- access --------------------//
  900.                     if( equali( option, "access" ) ) BaseSettings[ ACCESS ] = read_flags( text )
  901.                     //-------------------- maps in menu --------------------//
  902.                     if( equali( option, "mapsinmenu" ) ) BaseSettings[ MapsInMenu ] = str_to_num( text )
  903.                     //-------------------- max recent maps --------------------//
  904.                     if( equali( option, "maxrecentmaps" ) ) BaseSettings[ MaxRecentMaps ] = str_to_num( text )
  905.  
  906.                     //-------------------- default time --------------------//
  907.                     if( equali( option, "defaulttime" ) ) BaseSettings[ DefaultTime ] = str_to_num( text )
  908.                     //-------------------- countdown rtv time --------------------//
  909.                     if( equali( option, "countdownrtv" ) ) BaseSettings[ Countdownrtv ] = str_to_num( text )
  910.                     //-------------------- vote countdown time --------------------//
  911.                     if( equali( option, "votecountdown" ) ) BaseSettings[ VoteCountdown ] = str_to_num( text )
  912.                     //-------------------- menu countdown time --------------------//
  913.                     if( equali( option, "menucountdown" ) ) BaseSettings[ MenuCountdown ] = str_to_num( text )
  914.                     //-------------------- extend time --------------------//
  915.                     if( equali( option, "extendtime" ) ) BaseSettings[ ExtendTime ] = str_to_num( text )
  916.                     //-------------------- nextmap time --------------------//
  917.                     if( equali( option, "nextmaptime" ) ) BaseSettings[ NextmapTimeleft ] = str_to_num( text )
  918.                 }
  919.             }
  920.         }
  921.         fclose( File )
  922.     }
  923.  
  924.     //-------------------- log's folder location --------------------//
  925.     if( BaseSettings[ LOG_FOLDER ] && !dir_exists( fmt( "%s/%s", GetDirPath( "amxx_logs" ), BaseSettings[ LOG_FOLDER ] ) ) ) mkdir( fmt( "%s/%s", GetDirPath( "amxx_logs" ), BaseSettings[ LOG_FOLDER ] ) )
  926. }
  927.  
  928. //-------------------- Settings functions - default settings --------------------//
  929. defaultbasesettings()
  930. {
  931.     copy( BaseSettings[ PREFIX ], charsmax( BaseSettings ), "VM" )          //-------- prefix ---------//
  932.     copy( BaseSettings[ LOG_FOLDER ], charsmax( BaseSettings ), "VM/" )     //-------- log folder ---------//
  933.     BaseSettings[ AllowValveMaps ]                  = false                 //-------- valve maps ---------//
  934.     BaseSettings[ TimeZone ]                        = 0                     //-------- timezone ---------//
  935.     BaseSettings[ ACCESS ]                          = ADMIN_MAP             //-------- access ---------//
  936.     BaseSettings[ MapsInMenu ]                      = 5                     //-------- maps in menu ---------//
  937.     BaseSettings[ MaxRecentMaps ]                   = 3                     //-------- max recent maps ---------//
  938.  
  939.     //-------- timers ---------//
  940.     BaseSettings[ DefaultTime ]                     = 600                   //-------- default time ---------//
  941.     BaseSettings[ Countdownrtv ]                    = 60                    //-------- countdown rtv time ---------//
  942.     BaseSettings[ VoteCountdown ]                   = 4                     //-------- vote countdown time ---------//
  943.     BaseSettings[ MenuCountdown ]                   = 16                    //-------- menu countdown time ---------//
  944.     BaseSettings[ ExtendTime ]                      = 600                   //-------- extend time ---------//
  945.     BaseSettings[ NextmapTimeleft ]                 = 10                    //-------- nextmap time ---------//
  946. }
  947.  
  948. //-------------------- Stocks - nomination system --------------------//
  949. stock NominateMap( id, map )
  950. {
  951.     //--------------- Vote status ---------------//
  952.     if( votestatus( id ) ) return 1
  953.  
  954.     //--------------- Failsafe ---------------//
  955.     if( map < 0 || map >= totalmaps ) return ColorChat( id, "Invalid map selection." )
  956.  
  957.     //-------------------- if the chosen map already have been nominated by another player --------------------//
  958.     if( mapsystem[ map ][ nominated ] && IsMapNominated( mapsystem[ map ][ mapname ] ) != id )
  959.         return ColorChat( id, "^3%n^1 has already nominated ^4%s^1.", IsMapNominated( mapsystem[ map ][ mapname ] ), mapsystem[ map ][ mapname ] )
  960.  
  961.     //-------------------- if the chosen map is nominated by you then denominate it --------------------//
  962.     if( playersystem[ id ][ nominate ] && equali( playersystem[ id ][ mynom ], mapsystem[ map ][ mapname ] ) )
  963.     {
  964.         playersystem[ id ][ nominate ] = false
  965.         playersystem[ id ][ mynom ] = 0
  966.         votesystem[ nomcounter ]--
  967.         mapsystem[ map ][ nominated ] = false
  968.  
  969.         ColorChat( 0, "^3%n^1 has denominated ^3%s^1.", id, mapsystem[ map ][ mapname ] )
  970.     }
  971.     else
  972.     {
  973.         //-------- if you already have nominated for another map then denominate it and nominate for the new one --------//
  974.         if( playersystem[ id ][ mynom ] )
  975.         {
  976.             for( new i = 0; i < totalmaps; i++ ) if( equali( mapsystem[ i ][ mapname ], playersystem[ id ][ mynom ] ) ) mapsystem[ i ][ nominated ] = false
  977.  
  978.             mapsystem[ map ][ nominated ] = true
  979.             ColorChat( 0, "^3%n^1 has changed his nominate from ^3%s^1 to ^3%s^1.", id, playersystem[ id ][ mynom ], mapsystem[ map ][ mapname ] )
  980.         }
  981.         else
  982.         {
  983.             votesystem[ nomcounter ]++
  984.             playersystem[ id ][ nominate ] = true
  985.             mapsystem[ map ][ nominated ] = true
  986.             ColorChat( 0, "^3%n^1 nominated ^3%s^1.", id, mapsystem[ map ][ mapname ] )
  987.         }
  988.  
  989.         copy( playersystem[ id ][ mynom ], 64, mapsystem[ map ][ mapname ] )
  990.     }
  991.  
  992.     return 0
  993. }
  994.  
  995. //-------------------- Stocks - check if this map nominated and by who --------------------//
  996. stock IsMapNominated( const map[] )
  997. {
  998.     for( new i = 1; i <= get_maxplayers(); i++ )
  999.     {
  1000.         //-------------------- If the player is not connected or its your own nominate --------------------//
  1001.         if( !is_user_connected( i ) ) continue
  1002.  
  1003.         if( equali( playersystem[ i ][ mynom ], map ) ) return i
  1004.     }
  1005.  
  1006.     return false
  1007. }
  1008.  
  1009. //-------------------- Stocks - check how many votes remain to rock the vote --------------------//
  1010. stock VotesRemain()
  1011. {
  1012.     new players[ 32 ], num = 0
  1013.     get_players( players, num, "ch" )
  1014.  
  1015.     return ( num/2 ) - votesystem[ rtvcounter ]
  1016. }
  1017.  
  1018. //-------------------- Stocks - ColorChat --------------------//
  1019. stock ColorChat( id, const string[], any:... )
  1020. {
  1021.     new msg[ 191 ], teamcolor = print_team_default
  1022.     new len = formatex( msg, charsmax( msg ), "^3[^1 %s ^3]^1 ", BaseSettings[ PREFIX ] )
  1023.     vformat( msg[ len ], charsmax( msg ) - len, string, 3 )
  1024.  
  1025.     if( containi( msg, "^5" ) != -1 ) replace_all( msg, charsmax( msg ), "^5", "^3"), teamcolor = print_team_red
  1026.     if( containi( msg, "^6" ) != -1 ) replace_all( msg, charsmax( msg ), "^6", "^3"), teamcolor = print_team_blue
  1027.     if( containi( msg, "^7" ) != -1 ) replace_all( msg, charsmax( msg ), "^7", "^3"), teamcolor = print_team_grey
  1028.  
  1029.     client_print_color( id, teamcolor, msg )
  1030.     return 1
  1031. }
  1032.  
  1033. //-------------------- Bools - vote status --------------------//
  1034. bool:votestatus( id, bool:ignorenextmap = false )
  1035. {
  1036.     if( votestate == Vote_Running ) ColorChat( id, "The vote is already ^3running^1." )
  1037.     else if( votestate == Vote_Starting ) ColorChat( id, "The vote is ^3starting^1 now." )
  1038.     else if( votestate == Vote_Nextmap && !ignorenextmap ) ColorChat( id, "The ^3map^1 will be change to ^3%s^1 in ^3%02d:%02d^1 %s%s.", votesystem[ Nextmap ], votesystem[ Timeleftnextmap ]/60, votesystem[ Timeleftnextmap ]%60, votesystem[ Timeleftnextmap ]/60 > 1 ? "minute" : "second", votesystem[ Timeleftnextmap ]/60 > 1 ? "s" : "" )
  1039.     else return false
  1040.  
  1041.     return true
  1042. }
  1043.  
  1044. //-------------------- Bools - admin access --------------------//
  1045. bool:hasaccess( id )
  1046. {
  1047.     if( get_user_flags( id ) & BaseSettings[ ACCESS ] ) return true
  1048.  
  1049.     return false
  1050. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement