Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* not tested yet */
- // todo
- // maybe add rounds as options instead of timeleft
- // maybe add second vote when 2 or more maps are tied up ( revote )
- //--------------- Includes ---------------//
- #include < amxmodx >
- #include < smartstocks >
- //-------------------- File's locations --------------------//
- #define mapini fmt( "%s/maps.ini", GetDirPath( "amxx_configsdir" ) ) // maps's ini
- #define settingsini fmt( "%s/vmsettings.ini", GetDirPath( "amxx_configsdir" ) ) // settings's ini
- //-------------------- TaskIDs --------------------//
- enum ( += 1000 ) { MapTaskID = 1000, TimeLeftTaskID, CountdowntovoteTaskID, MenuTimeTaskID, TimetochangeTaskID }
- //-------------------- Settings's functions --------------------//
- enum Settings
- {
- PREFIX[ 32 ], LOG_FOLDER[ 128 ], ACCESS, TimeZone,
- bool:AllowValveMaps,
- MapsInMenu, MaxRecentMaps,
- //--------------- Timers ---------------//
- DefaultTime, Countdownrtv, VoteCountdown, MenuCountdown, ExtendTime, NextmapTimeleft
- }
- new BaseSettings[ Settings ]
- //-------------------- map & vote functions --------------------//
- enum { Vote_NotRunning, Vote_Starting, Vote_Running, Vote_Nextmap }
- enum _:MapStats { mapname[ 64 ], mapdate[ 64 ], mapplayed[ 64 ], mappopularity[ 64 ], mapsize[ 64 ], bool:nominated }
- enum _:VoteStats { bool:adminhud, rtvcounter, nomcounter, Timeleft, Timeleftnextmap, Maptime, Mapcountdown, Countdown, MenuTimer, Allvotes, Nextmap[ 64 ] }
- enum _:MyStats { bool:RTV, bool:dontshowmenu, bool:revote, bool:nominate, mynom[ 64 ], bool:voted, selectedmap[ 64 ], mychoose }
- new mapsystem[ 1000 ][ MapStats ], votesystem[ VoteStats ], playersystem[ 33 ][ MyStats ]
- new totalmaps, votestate, sortmenu[ 33 ], searchmap[ 33 ], menupage[ 33 ], mapvotes[ 33 ], bool:MenuShitFunction
- //-------------------- commands --------------------//
- new startvotecmds[][] = { "startvote", "/startvote", "!startvote" }
- new stopvotecmds[][] = { "stopvote", "/stopvote", "!stopvote" }
- new randommapcmds[][] = { "/randommap", "!randommap" }
- new extendcmds[][] = { "/extend", "!extend" }
- new currentmapcmds[][] = { "cm", "/cm", "currentmap", "/currentmap", "mt", "/mt", "maptime", "/maptime" }
- new thetimecmds[][] = { "tt", "/tt", "thetime", "/thetime" }
- new timeleftcmds[][] = { "tl", "/tl", "timeleft", "/timeleft", "nm", "/nm", "nextmap", "/nextmap" }
- new rockthevotecmds[][] = { "rtv", "/rtv", "rockthevote", "/rockthevote" }
- new unrockthevotecmds[][] = { "unrtv", "/unrtv", "unrockthevote", "/unrockthevote" }
- new mapsmenucmds[][] = { "/maps" }
- new nomcmds[][] = { "noms", "/noms", "nominate", "/nominate", "nominations", "/nominations" }
- new recentmapcmds[][] = { "rm", "/rm", "recentmaps", "/recentmaps" }
- //--------------- Plugin init ---------------//
- public plugin_init()
- {
- register_plugin( "advanced votemap", "v1.0", "RanAway" )
- //--------------- Commands ---------------//
- register_clcmd( "say", "CmdSay" )
- register_clcmd( "say_team", "CmdSay" )
- //-------------------- load functions --------------------//
- loadsettings() // settings functions - load settings
- loadmaps() // map functions - load maps
- generatemaps() // map functions - generate maps
- if( BaseSettings[ AllowValveMaps ] ) generatemaps( true ) // map functions - generate valve maps
- votestate = Vote_NotRunning
- votesystem[ Timeleft ] = BaseSettings[ DefaultTime ]
- votesystem[ Mapcountdown ] = BaseSettings[ Countdownrtv ]
- votesystem[ Countdown ] = BaseSettings[ VoteCountdown ]
- votesystem[ MenuTimer ] = BaseSettings[ MenuCountdown ]
- //--------------- Timers ---------------//
- set_task( 1.0, "Timetovote", TimeLeftTaskID, .flags = "b" ) // vote functions - timeleft to vote
- set_task( 1.0, "MapTime", MapTaskID, .flags = "b" ) // map functions - count the current map time
- set_task( 1.0, "mapaddtime", MapTaskID, .flags = "b" ) // map functions - add time
- }
- //--------------- Disconnect ---------------//
- public client_disconnected( id )
- {
- //--------------- Vote status ---------------//
- if( !votestatus( id ) )
- {
- //--------------- if rocked the vote ---------------//
- if( playersystem[ id ][ RTV ] ) votesystem[ rtvcounter ]--
- //--------------- If nominated ---------------//
- if( playersystem[ id ][ nominate ] )
- {
- for( new i = 0; i < totalmaps; i++ ) if( equali( mapsystem[ i ][ mapname ], playersystem[ id ][ mynom ] ) ) mapsystem[ i ][ nominated ] = false
- votesystem[ nomcounter ]--
- ColorChat( 0, "^3%s^1 is no longer nominated.", playersystem[ id ][ mynom ] )
- }
- arrayset( playersystem[ id ], 0, MyStats )
- }
- }
- //--------------- Map time ---------------//
- public MapTime() votesystem[ Maptime ]++
- //--------------- Time to vote ---------------//
- public Timetovote()
- {
- //--------------- Failsafe ---------------//
- if( votesystem[ Timeleft ] <= 0 && task_exists( TimeLeftTaskID ) ) return remove_task( TimeLeftTaskID )
- if( --votesystem[ Timeleft ] <= 0 )
- {
- votesystem[ adminhud ] = false
- StartVote()
- ColorChat( 0, "The ^3votemap^1 has started." )
- }
- return 0
- }
- //--------------- maps & nominate menu ---------------//
- public mapsmenu( id )
- {
- //--------------- Vote status & prevent heap low ---------------//
- if( votestatus( id ) || !is_user_connected( id ) ) return 1
- 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" )
- //-------------------- Sorting --------------------//
- SortCustom2D( mapsystem, totalmaps, "MapSorting", _, id )
- for( new i = 0, counter = -1; i < totalmaps; i++ )
- {
- //-------------------- searching | Currentmap --------------------//
- if( ( searchmap[ id ] && containi( mapsystem[ i ][ mapname ], searchmap[ id ] ) == -1 ) || equali( mapsystem[ i ][ mapname ], CurrentMap() ) ) continue
- //-------------------- Sorting --------------------//
- 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" ) )
- //-------------------- map name & nominate symbol --------------------//
- formatex( item, charsmax( item ), "%s%s", mapsystem[ i ][ mapname ], mapsystem[ i ][ nominated ] ? "\y*" : "" )
- switch( sortmenu[ id ] )
- {
- //-------------------- map date --------------------//
- case 1: add( item, charsmax( item ), fmt( " \d(%s)", Getformattime( "%H:%M - %d/%m/%y", str_to_num( mapsystem[ i ][ mapdate ] ) ) ) )
- //-------------------- map played --------------------//
- 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" ) )
- //-------------------- map popularity --------------------//
- 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" ) )
- //-------------------- map size --------------------//
- case 4: add( item, charsmax( item ), fmt( " \d(%.2f %s)", mapsystem[ i ][ mapsize ] / 1048576.0, mapsystem[ i ][ mapsize ] / 1048576.0 >= 1.00 ? "MB" : "KB" ) )
- }
- MenuCallback( menu, item, _, ( mapsystem[ i ][ nominated ] && IsMapNominated( mapsystem[ i ][ mapname ] ) != id ) ? true : false, GetNumStr( i ) )
- }
- //-------------------- Previous / Next --------------------//
- menu_setprop( menu, MPROP_NEXTNAME, "next page" )
- menu_setprop( menu, MPROP_BACKNAME, "previous page" )
- menu_setprop( menu, MPROP_EXITNAME, "exit" )
- //-------------------- Search title --------------------//
- 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 ] ) )
- menu_display( id, menu, menupage[ id ] < 0 ? 0 : menupage[ id ] > totalmaps / 6 ? totalmaps / 6 : menupage[ id ] )
- return 1
- }
- //-------------------- map functions - sorting --------------------//
- public MapSorting( const map1[], const map2[], const array[][], data[], id )
- {
- //--------- Ascending nominated maps ----------//
- if( map1[ nominated ] && !map2[ nominated ] ) return -1
- else if( !map1[ nominated ] && map2[ nominated ] ) return 1
- switch( sortmenu[ id ] )
- {
- //--------- Ascending Alphabetical ----------//
- case 0: return strcmp( map1[ mapname ], map2[ mapname ], true )
- //--------- Ascending by added date ----------//
- case 1: return str_to_num( map2[ mapdate ] ) - str_to_num( map1[ mapdate ] ) > 0 ? 1 : -1
- //--------- Ascending by last time played ----------//
- case 2: return str_to_num( map2[ mapplayed ] ) - str_to_num( map1[ mapplayed ] ) > 0 ? 1 : -1
- //--------- Ascending by popularity ----------//
- case 3: return str_to_num( map2[ mappopularity ] ) - str_to_num( map1[ mappopularity ] ) > 0 ? 1 : -1
- //--------- Ascending by file size ----------//
- case 4: return float( map2[ mapsize ] ) - float( map1[ mapsize ] ) > 0 ? 1 : -1
- //--------- Failsafe ----------//
- default: return server_print( "Warning: Unknown sorting option %d", sortmenu[ id ] )
- }
- return 0
- }
- public sub_mapsmenu( id, menu, item )
- {
- if( item == MENU_EXIT ) return menu_destroy( menu )
- //--------------- Vote status ---------------//
- if( votestatus( id ) ) return 1
- //-------------------- Make sure the key is right --------------------//
- new aftersort = GetMenuKey( menu, item )
- //-------------------- Save the page --------------------//
- player_menu_info( id, menu, menu, menupage[ id ] )
- //-------------------- sorting maps --------------------//
- if( item % 7 == 0 )
- {
- if( sortmenu[ id ]++ >= 4 ) sortmenu[ id ] = 0
- }
- //-------------------- nominate the map --------------------//
- else NominateMap( id, aftersort )
- return mapsmenu( id )
- }
- //--------------- CmdSay ---------------//
- public CmdSay( id )
- {
- //-------------------- get the message --------------------//
- new message[ 192 ], cmd[ 64 ], arg[ 64 ], randommap[ 64 ]
- read_argv( 1, message, charsmax( message ) ); parse( message, cmd, charsmax( cmd ), arg, charsmax( arg ) )
- //--------------- Show the current map + map time ---------------//
- for( new i = 0; i < sizeof( currentmapcmds ); i++ ) if( equali( cmd, currentmapcmds[ i ] ) )
- 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 )
- //--------------- Show the time ---------------//
- for( new i = 0; i < sizeof( thetimecmds ); i++ ) if( equali( cmd, thetimecmds[ i ] ) )
- 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 ] ) ) )
- //--------------- Show when the votemap will start ---------------//
- for( new i = 0; i < sizeof( timeleftcmds ); i++ ) if( equali( cmd, timeleftcmds[ i ] ) )
- {
- //--------------- Vote status ---------------//
- if( votestatus( id ) ) return 1
- 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" : "" )
- }
- //--------------- Rock the vote ---------------//
- for( new i = 0; i < sizeof( rockthevotecmds ); i++ ) if( equali( cmd, rockthevotecmds[ i ] ) )
- {
- //--------------- Vote status ---------------//
- if( votestatus( id ) ) return 1
- //--------------- Countdown before you can rock the vote ---------------//
- if( votesystem[ Maptime ] < votesystem[ Mapcountdown ] ) return ColorChat( id, "You have to wait ^3%02d^1:^3%02d^1 %s%s for rock the vote.",
- ( votesystem[ Mapcountdown ] - votesystem[ Maptime ] )/60, ( votesystem[ Mapcountdown ] - votesystem[ Maptime ] )%60,
- ( 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" : "" )
- //--------------- if you already rocked the vote ---------------//
- if( playersystem[ id ][ RTV ] ) return ColorChat( id, "You have already rocked the vote. ^3%d^1 players remaning.", VotesRemain() )
- if( VotesRemain() <= votesystem[ rtvcounter ] )
- {
- votesystem[ adminhud ] = false
- StartVote()
- return ColorChat( 0, "^3%n^1 has rocked the vote, ^3votemap^1 has started.", id )
- }
- votesystem[ rtvcounter ]++
- playersystem[ id ][ RTV ] = true
- return ColorChat( 0, "^3%n^1 has rocked the vote, ^3%d^1 players remaning.", id, VotesRemain() )
- }
- //--------------- UnRock the vote ---------------//
- for( new i = 0; i < sizeof( unrockthevotecmds ); i++ ) if( equali( cmd, unrockthevotecmds[ i ] ) )
- {
- //--------------- Vote status ---------------//
- if( votestatus( id ) ) return 1
- //--------------- if you didnt rocked the vote yet ---------------//
- if( !playersystem[ id ][ RTV ] ) return ColorChat( id, "You have not rocked the vote yet." )
- votesystem[ rtvcounter ]--
- playersystem[ id ][ RTV ] = false
- return ColorChat( 0, "^3%n^1 has unrocked the vote, ^3%d^1 players remaning.", id, VotesRemain() )
- }
- //--------------- Show recent maps ---------------//
- for( new i = 0; i < sizeof( recentmapcmds ); i++ ) if( equali( cmd, recentmapcmds[ i ] ) )
- {
- //--------- Initialize arrays ---------//
- new HoldTimes[ 6 ]; arrayset( HoldTimes, 0, charsmax( HoldTimes ) )
- new HoldMaps[ 6 ][ 64 ]; arrayset2D( HoldMaps, 6, 64, EOS )
- //--------- Find recent maps ---------//
- for( new map = 0; map < totalmaps; map++ )
- {
- //--------- Make sure to not count the current map ---------//
- if( equali( mapsystem[ map ][ mapname ], CurrentMap() ) ) continue
- new playedTime = str_to_num( mapsystem[ map ][ mapplayed ] )
- for( new j = 0; j < 6; j++ )
- {
- //--------- Insert map into sorted list ---------//
- if( playedTime > HoldTimes[ j ] )
- {
- //--------- Shift maps down to make space ---------//
- for( new k = 5; k > j; k-- )
- {
- HoldTimes[ k ] = HoldTimes[ k - 1 ]
- copy( HoldMaps[ k ], charsmax( HoldMaps[] ), HoldMaps[ k - 1 ] )
- }
- HoldTimes[ j ] = playedTime
- copy( HoldMaps[ j ], charsmax( HoldMaps[] ), mapsystem[ map ][ mapname ] )
- break
- }
- }
- }
- //--------- Check if there are any recent maps ---------//
- if( HoldMaps[ 0 ][ 0 ] == EOS ) return ColorChat( id, "No maps have been played yet." )
- //--------- Build message to display ---------//
- new msg[ 256 ], recentmaps = 0, countmaps = 0
- for( new j = 0; j < BaseSettings[ MaxRecentMaps ]; j++ )
- {
- if( HoldMaps[ j ][ 0 ] == EOS ) continue
- recentmaps += formatex( msg[ recentmaps ], charsmax( msg ) - recentmaps, "%s%s", countmaps == 0 ? "" : ", ", HoldMaps[ j ] )
- countmaps++
- }
- if( countmaps == 0 ) return ColorChat( id, "No recent maps to display." )
- return ColorChat( id, "The last ^4%d^1 recent maps: ^3%s^1.", countmaps, msg )
- }
- //--------------- Show noms ---------------//
- for( new i = 0; i < sizeof( nomcmds ); i++ ) if( equali( cmd, nomcmds[ i ] ) )
- {
- //--------------- Vote status ---------------//
- if( votestatus( id ) ) return 1
- //--------------- if there is no nominations ---------------//
- if( !votesystem[ nomcounter ] ) return ColorChat( id, "There is no ^3nominations^1 yet." )
- new msg[ 512 ], noms = 0
- for( new i = 0; i < totalmaps; i++ ) if( mapsystem[ i ][ nominated ] )
- noms += formatex( msg[ noms ], charsmax( msg ) -noms, ", %s", mapsystem[ i ][ mapname ] )
- return ColorChat( id, "^4%d^1 maps nominated: ^3%s^1.", votesystem[ nomcounter ], msg[ 2 ] )
- }
- //--------------- maps menu ---------------//
- for( new i = 0; i < sizeof( mapsmenucmds ); i++ ) if( equali( cmd, mapsmenucmds[ i ] ) )
- {
- //--------------- Vote status ---------------//
- if( votestatus( id ) ) return 1
- sortmenu[ id ] = 0
- searchmap[ id ] = false
- menupage[ id ] = ( equali( arg, "" ) ? 0 : str_to_num( arg ) - 1 )
- return mapsmenu( id )
- }
- //--------------- nominate ---------------//
- if( strlen( cmd ) >= 4 )
- {
- new found = 0, foundid = 0
- //-------------------- Search in the mapsystem vault for map which contain cmd --------------------//
- for( new i = 0; i < totalmaps; i++ )
- {
- if( containi( mapsystem[ i ][ mapname ], cmd ) != -1 )
- {
- if( equali( mapsystem[ i ][ mapname ], CurrentMap() ) || ( mapsystem[ i ][ nominated ] && IsMapNominated( mapsystem[ i ][ mapname ] ) != id ) ) continue
- copy( searchmap[ id ], charsmax( searchmap ), cmd )
- found++
- foundid = i
- }
- }
- if( found == 1 ) NominateMap( id, foundid )
- else if( found > 1 ) mapsmenu( id )
- }
- //--------------- Admin - Random map ---------------//
- for( new i = 0; i < sizeof( randommapcmds ); i++ ) if( equali( cmd, randommapcmds[ i ] ) && hasaccess( id ) )
- {
- new randommapcheck = random( totalmaps )
- //--------- Check if enough maps exist ---------//
- if( totalmaps <= 1 ) return ColorChat( id, "There are not enough maps to do a ^3random map^1 between." )
- //--------- Make sure not to change to the current map ---------//
- if( equali( mapsystem[ randommapcheck ][ mapname ], CurrentMap() ) )
- {
- if( randommapcheck == totalmaps - 1 ) randommapcheck -= 1
- else randommapcheck += 1
- }
- copy( randommap, charsmax( randommap ), mapsystem[ randommapcheck ][ mapname ] )
- set_task( 0.5, "ChangeMap", 0, randommap, charsmax( randommap ) )
- return ColorChat( 0, "Admin: ^3%n^1 has randomly changed the map to ^4%s^1.", id, randommap )
- }
- //--------------- Start votemap ---------------//
- for( new i = 0; i < sizeof( startvotecmds ); i++ ) if( equali( cmd, startvotecmds[ i ] ) && hasaccess( id ) )
- {
- //--------------- Vote status ---------------//
- if( votestatus( id ) ) return 1
- votesystem[ adminhud ] = true
- StartVote()
- return ColorChat( 0, "Admin: ^3%n^1 has started the votemap.", id )
- }
- //--------------- Stop votemap ---------------//
- for( new i = 0; i < sizeof( stopvotecmds ); i++ ) if( equali( cmd, stopvotecmds[ i ] ) && hasaccess( id ) )
- {
- //--------------- Vote status ---------------//
- if( votestate == Vote_NotRunning ) return ColorChat( id, "There is no vote ^3running^1." )
- //--------------- remove tasks ---------------//
- if( task_exists( CountdowntovoteTaskID ) ) remove_task( CountdowntovoteTaskID )
- if( task_exists( TimetochangeTaskID ) ) remove_task( TimetochangeTaskID )
- if( task_exists( MenuTimeTaskID ) ) remove_task( MenuTimeTaskID )
- votestate = Vote_NotRunning
- votesystem[ Timeleft ] = BaseSettings[ DefaultTime ]
- votesystem[ Countdown ] = BaseSettings[ VoteCountdown ]
- votesystem[ MenuTimer ] = BaseSettings[ MenuCountdown ]
- votesystem[ Allvotes ] = 0
- votesystem[ rtvcounter ] = 0
- votesystem[ nomcounter ] = 0
- arrayset( mapvotes, 0, sizeof mapvotes )
- for( new i = 0; i < totalmaps; i++ ) mapsystem[ i ][ nominated ] = false // reset the nominated maps
- arrayset2D( playersystem, get_maxplayers(), MyStats, false ) // reset the players system
- set_task( 1.0, "Timetovote", TimeLeftTaskID, .flags = "b" )
- show_menu( 0, 0, "^n", 1 )
- return ColorChat( 0, "Admin: ^3%n^1 has stopped the votemap.", id )
- }
- //--------------- Extend the map ---------------//
- for( new i = 0; i < sizeof( extendcmds ); i++ ) if( equali( cmd, extendcmds[ i ] ) && hasaccess( id ) )
- {
- //--------------- Vote status ---------------//
- if( votestatus( id, true ) ) return 1
- //--------------- If nothing wrote in the time it will add automatic ExtendTime ---------------//
- if( equali( arg, "" ) )
- {
- votesystem[ votestate == Vote_Nextmap ? Timeleftnextmap : Timeleft ] = BaseSettings[ ExtendTime ]
- return ColorChat( 0, "Admin: ^3%n^1 has extended the map to ^3%d^1 minutes.", id, BaseSettings[ ExtendTime ]/60 )
- }
- //--------------- If only + wrote in the time it will add the ExtedTime ---------------//
- if( equali( arg, "+" ) )
- {
- votesystem[ votestate == Vote_Nextmap ? Timeleftnextmap : Timeleft ] += BaseSettings[ ExtendTime ]
- return ColorChat( 0, "Admin: ^3%n^1 has extended the map by ^3%d^1 minutes.", id, BaseSettings[ ExtendTime ]/60 )
- }
- new amount = str_to_num( arg )
- //--------------- If the number is not valid ---------------//
- if( amount <= 0 ) return ColorChat( id, "You must type a number." )
- //--------------- If the number start with + then it will add time ---------------//
- if( containi( arg, "+" ) != -1 )
- {
- votesystem[ votestate == Vote_Nextmap ? Timeleftnextmap : Timeleft ] += amount
- 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" : "" )
- }
- //--------------- The amount of time you wrote ---------------//
- votesystem[ votestate == Vote_Nextmap ? Timeleftnextmap : Timeleft ] = amount
- 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" : "" )
- }
- return 0
- }
- //--------------- Random map ---------------//
- public ChangeMap( const map[] ) if( is_map_valid( map ) ) engine_changelevel( map )
- //--------------- Start vote ---------------//
- public StartVote()
- {
- //--------------- remove tasks ---------------//
- if( task_exists( TimeLeftTaskID ) ) remove_task( TimeLeftTaskID )
- if( task_exists( CountdowntovoteTaskID ) ) remove_task( CountdowntovoteTaskID )
- //--------------- prepare some functions ---------------//
- votestate = Vote_Starting
- votesystem[ Countdown ] = BaseSettings[ VoteCountdown ]
- set_task( 1.0, "Countdowntovote", CountdowntovoteTaskID, .flags = "b" )
- return 1
- }
- //--------------- Countdown for vote ---------------//
- public Countdowntovote()
- {
- //--------------- Failsafe ---------------//
- if( votesystem[ Countdown ] <= 0 && task_exists( CountdowntovoteTaskID ) ) return remove_task( CountdowntovoteTaskID )
- if( --votesystem[ Countdown ] <= 0 )
- {
- //--------------- remove tasks ---------------//
- if( task_exists( CountdowntovoteTaskID ) ) remove_task( CountdowntovoteTaskID )
- if( task_exists( MenuTimeTaskID ) ) remove_task( MenuTimeTaskID )
- //--------------- prepare some functions ---------------//
- votestate = Vote_Running
- votesystem[ MenuTimer ] = BaseSettings[ MenuCountdown ] * 10
- for( new i = 1; i <= get_maxplayers(); i++ ) if( is_user_connected( i ) ) playersystem[ i ][ dontshowmenu ] = false
- SortCustom2D( mapsystem, totalmaps, "SortMaps" )
- client_cmd( 0, "spk Gman/Gman_Choose%d", random_num( 1, 2 ) )
- set_task( 0.1, "MenuTime", MenuTimeTaskID, .flags = "b" )
- return 1
- }
- new Spk[ 10 ]; num_to_word( votesystem[ Countdown ], Spk, charsmax( Spk ) )
- client_cmd( 0, "spk vox/%s", Spk )
- 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" : "" )
- GetHudMsg( 0, false, msg, 0, 255, 0, _, 0.10, 0, _, 1.0 )
- return 1
- }
- //--------------- Menu timer ---------------//
- public MenuTime()
- {
- //--------------- Failsafe ---------------//
- if( votesystem[ MenuTimer ] <= 0 && task_exists( MenuTimeTaskID ) ) return remove_task( MenuTimeTaskID )
- if( --votesystem[ MenuTimer ] <= 0 )
- {
- //--------------- remove tasks ---------------//
- if( task_exists( MenuTimeTaskID ) ) remove_task( MenuTimeTaskID )
- show_menu( 0, 0, "^n", 1 )
- return CheckResults()
- }
- for( new i = 1; i <= get_maxplayers(); i++ )
- {
- //-------------------- If the player is not connected or bot or disable the menu --------------------//
- if( !is_user_connected( i ) || is_user_bot( i ) || playersystem[ i ][ dontshowmenu ] ) continue
- MenuShitFunction = true
- show_menu( i, 0, "^n", 1 )
- ShowVote( i )
- MenuShitFunction = false
- }
- return 1
- }
- //--------------- Show vote ---------------//
- public ShowVote( id )
- {
- new item[ 512 ], Precent[ 32 ], ccc = BaseSettings[ MapsInMenu ]
- 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" )
- for( new i = 0; i < ( ccc > 5 ? 5 : ccc ); i++ )
- {
- //--------------- maps precent ---------------//
- if( mapvotes[ i ] > 0 ) Precent[ i ] = ( ( mapvotes[ i ] * 100 ) / ( votesystem[ Allvotes ] ) )
- //--------------- map button ---------------//
- 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" : "" )
- MenuCallback( menu, item, fmt( "%d.", i + 1 ), ( !playersystem[ id ][ voted ] || ( i == playersystem[ id ][ mychoose ] && !playersystem[ id ][ revote ] ) ) ? false : true )
- }
- //--------------- Current map precent ---------------//
- if( mapvotes[ ccc ] > 0 ) Precent[ ccc ] = ( ( mapvotes[ ccc ] * 100 ) / ( votesystem[ Allvotes ] ) )
- //--------------- Current map button ---------------//
- 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 ] )
- MenuCallback( menu, item, fmt( "%d.", BaseSettings[ MapsInMenu ] + 1 ), ( !playersystem[ id ][ voted ] || ( ccc == playersystem[ id ][ mychoose ] && !playersystem[ id ][ revote ] ) ) ? false : true )
- //--------------- dont show the menu button ---------------//
- menu_setprop( menu, MPROP_EXITNAME, "Dont show me the menu" )
- menu_display( id, menu )
- return 1
- }
- public sub_vote( id, menu, item )
- {
- if( item == MENU_EXIT )
- {
- if( MenuShitFunction || MenuTimer <= 0 || votestate == Vote_NotRunning ) return menu_destroy( menu )
- //--------------- dont show the menu button ---------------//
- return playersystem[ id ][ dontshowmenu ] = true
- }
- //--------------- Revote system ---------------//
- if( playersystem[ id ][ voted ] && !playersystem[ id ][ revote ] )
- {
- votesystem[ Allvotes ]--
- mapvotes[ playersystem[ id ][ mychoose ] ]--
- playersystem[ id ][ voted ] = false
- playersystem[ id ][ revote ] = true
- ColorChat( 0, "^3%n^1 has unvoted for ^4%s^1.", id, playersystem[ id ][ selectedmap ] )
- return ShowVote( id )
- }
- //--------------- current map button ---------------//
- if( item == BaseSettings[ MapsInMenu ] )
- {
- copy( playersystem[ id ][ selectedmap ], 64, CurrentMap() )
- ColorChat( 0, "^3%n^1 has voted to stay in the current map. ^3[^1 %s ^3]", id, CurrentMap() )
- }
- //--------------- selected map button ---------------//
- else
- {
- copy( playersystem[ id ][ selectedmap ], 64, mapsystem[ item ][ mapname ] )
- ColorChat( 0, "^3%n^1 has voted for ^4%s^1.", id, playersystem[ id ][ selectedmap ] )
- }
- client_cmd( id, "spk sound/buttons/lightswitch2.wav" )
- votesystem[ Allvotes ]++
- mapvotes[ item ]++
- playersystem[ id ][ voted ] = true
- playersystem[ id ][ mychoose ] = item
- return ShowVote( id )
- }
- //--------------- Sort maps ---------------//
- public SortMaps( const map1[], const map2[], const array[][] )
- {
- //--------- Prevent current map from being selected ----------//
- if( equali( map1[ mapname ], CurrentMap() ) ) return 1
- if( equali( map2[ mapname ], CurrentMap() ) ) return -1
- //--------- Ascending nominated maps ----------//
- if( map1[ nominated ] && !map2[ nominated ] ) return -1
- else if( !map1[ nominated ] && map2[ nominated ] ) return 1
- switch( random( 3 ) )
- {
- case 0: return 0
- case 1: return 1
- default: return -1
- }
- return 0
- }
- //--------------- Results ---------------//
- CheckResults()
- {
- new winner, winnercount, tienum, tie[ 10 ]
- //--------- Check for ties --------//
- for( new i = 0; i <= BaseSettings[ MapsInMenu ]; i++ )
- {
- //--------- Add to vault if ties --------//
- if( mapvotes[ i ] == winnercount ) tie[ tienum++ ] = i
- //--------- Reset ties vault if there is higher votes then the votes in vault --------//
- else if( mapvotes[ i ] > winnercount )
- {
- winner = i
- winnercount = mapvotes[ i ]
- arrayset( tie, 0, sizeof tie )
- tienum = 0
- }
- }
- //--------- no one voted --------//
- if( !winnercount ) winner = random( BaseSettings[ MapsInMenu ] )
- //--------- Tie --------//
- else if( tienum && mapvotes[ tie[ 0 ] ] == winnercount && winnercount )
- {
- winner = tie[ random( tienum ) ]
- ColorChat( 0, "^3%d^1 maps has the same number of votes. ^3random one^1 will be chosen.", tienum )
- }
- //--------- map won --------//
- if( winner != BaseSettings[ MapsInMenu ] )
- {
- votestate = Vote_Nextmap
- votesystem[ Timeleftnextmap ] = BaseSettings[ NextmapTimeleft ]
- copy( votesystem[ Nextmap ], 64, mapsystem[ winner ][ mapname ] )
- set_task( 1.0, "Timetochange", TimetochangeTaskID, .flags = "b" )
- 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 ] ) )
- else ColorChat( 0, "No one voted. The server chose by random and the chosen map is ^4%s^1.", mapsystem[ winner ][ mapname ] )
- }
- //--------- Current map won --------//
- else if( winner == BaseSettings[ MapsInMenu ] )
- {
- votestate = Vote_NotRunning
- votesystem[ Timeleft ] = BaseSettings[ ExtendTime ]
- set_task( 1.0, "Timetovote", TimeLeftTaskID, .flags = "b" )
- if( winnercount ) ColorChat( 0, "The current map ^4%s^1 will be extended for ^3%d^1 minutes.", CurrentMap(), BaseSettings[ ExtendTime ]/60 )
- 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 )
- }
- votesystem[ Allvotes ] = 0
- votesystem[ rtvcounter ] = 0
- votesystem[ nomcounter ] = 0
- arrayset( mapvotes, 0, sizeof mapvotes )
- for( new i = 0; i < totalmaps; i++ ) mapsystem[ i ][ nominated ] = false // reset the nominated maps
- arrayset2D( playersystem, get_maxplayers(), MyStats, false ) // reset the players system
- return 1
- }
- //--------------- Time to change ---------------//
- public Timetochange()
- {
- //--------------- Failsafe ---------------//
- if( votesystem[ Timeleftnextmap ] <= 0 && task_exists( TimetochangeTaskID ) ) return remove_task( TimetochangeTaskID )
- if( --votesystem[ Timeleftnextmap ] <= 0 )
- {
- //--------------- remove tasks ---------------//
- if( task_exists( TimetochangeTaskID ) ) remove_task( TimetochangeTaskID )
- set_task( 1.0, "ChangeMap", 0, votesystem[ Nextmap ], charsmax( votesystem[ Nextmap ] ) )
- return ColorChat( 0, "The ^3map^1 will be change to ^3%s^1.", votesystem[ Nextmap ] )
- }
- if( votesystem[ Timeleftnextmap ] < 11 )
- {
- new Spk[ 10 ]; num_to_word( votesystem[ Timeleftnextmap ], Spk, charsmax( Spk ) )
- client_cmd( 0, "spk vox/%s", Spk )
- new msg[ 256 ]; formatex( msg, charsmax( msg ), "The map will be change in %d second%s", votesystem[ Timeleftnextmap ], votesystem[ Timeleftnextmap ] == 1 ? "" : "s" )
- GetHudMsg( 0, false, msg, 255, 0, 0, _, 0.10, 0, _, 1.0 )
- }
- return 1
- }
- //-------------------- map functions - addtime --------------------//
- public mapaddtime()
- {
- new Line[ 512 ], name[ 64 ], date[ 64 ], played[ 64 ], popularity[ 64 ], FileLine = -1, File = fopen( mapini, "rt" )
- while( !feof( File ) )
- {
- //-------------------- Line counter --------------------//
- FileLine++
- //-------------------- File info --------------------//
- fgets( File, Line, charsmax( Line ) ); trim( Line )
- //-------------------- if line start with ; or empty skip --------------------//
- if( Line[ 0 ] == ';' || !Line[ 0 ] ) continue
- //-------------------- Line info --------------------//
- parse( Line, name, charsmax( name ), date, charsmax( date ), played, charsmax( played ), popularity, charsmax( popularity ) )
- //-------------------- add time only to the current map --------------------//
- 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 )
- }
- fclose( File )
- }
- //-------------------- map functions - Load maps --------------------//
- loadmaps()
- {
- arrayset2D( mapsystem, totalmaps, MapStats, 0 ) // reset the map system memory
- totalmaps = 0
- new Line[ 512 ], CuttedLine[ 512 ], checkmap[ 64 ], File = fopen( mapini, "rt" )
- while( !feof( File ) )
- {
- //-------------------- File info --------------------//
- fgets( File, Line, charsmax( Line ) ); trim( Line )
- //-------------------- if line start with ; or empty --------------------//
- if( Line[ 0 ] == ';' || !Line[ 0 ] ) continue
- //-------------------- Line map for check --------------------//
- parse( Line, checkmap, charsmax( checkmap ) )
- //-------------------- if not valid map --------------------//
- if( !is_map_valid( checkmap ) ) continue
- //-------------------- if line contain ; make sure to not count it as part of the line --------------------//
- strtok( Line, Line, charsmax( Line ), CuttedLine, charsmax( CuttedLine ), ';' )
- //-------------------- load the maps into vault --------------------//
- parse( Line, mapsystem[ totalmaps ][ mapname ], sizeof( mapsystem ), mapsystem[ totalmaps ][ mapdate ], sizeof( mapsystem ),
- mapsystem[ totalmaps ][ mapplayed ], sizeof( mapsystem ), mapsystem[ totalmaps ][ mappopularity ], sizeof( mapsystem ) )
- totalmaps++
- }
- fclose( File )
- }
- //-------------------- map functions - maps.ini generator --------------------//
- generatemaps( bool:valve = false )
- {
- new mapdir[ 64 ], bool:skip = false, mapsdir = open_dir( "maps", mapdir, charsmax( mapdir ), _, valve ? true : false, valve ? NULL_STRING : "GAME" )
- if( mapsdir )
- {
- while( next_file( mapsdir, mapdir, charsmax( mapdir ) ) )
- {
- //-------------------- Check if the map is valid --------------------//
- replace( mapdir, charsmax( mapdir ), ".bsp", "" )
- if( mapdir[ 0 ] == '.' || !is_map_valid( mapdir ) ) continue
- skip = false
- //-------------------- Check if the map already in the file --------------------//
- for( new i = 0; i < totalmaps; i++ )
- {
- //-------------------- Load the size of the map --------------------//
- if( equali( mapsystem[ i ][ mapname ], mapdir ) ) skip = true, mapsystem[ i ][ mapsize ] = file_size( fmt( "maps/%s.bsp", mapdir ), 0 )
- //-------------------- Change the curentmap last played date --------------------//
- 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 )
- }
- //-------------------- skip if the map is in the file or add if not --------------------//
- if( !skip ) write_file( mapini, fmt( "%s %d 0 0", mapdir, get_systime( BaseSettings[ TimeZone ] ) ), findemptyline( mapini ) )
- }
- close_dir( mapsdir )
- }
- }
- //-------------------- Settings functions - load --------------------//
- loadsettings() // thanks to ocixcrom
- {
- //-------------------- default settings ( if there is no settings then this is the default ) --------------------//
- defaultbasesettings()
- new Line[ 256 ], CuttedLine[ 256 ], option[ 128 ], text[ 128 ], File = fopen( settingsini, "rt" )
- //-------------------- if the file dosn't exist then create it --------------------//
- if( !File )
- {
- write_file( settingsini, "========== General Settings ==========", -1 )
- write_file( settingsini, "prefix = VM ; prefix name", -1 )
- write_file( settingsini, "log_folder = VM/ ; Folder name for storing log files", -1 )
- 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 )
- write_file( settingsini, "timezone = 0 ; Time Zone in seconds; 10800 for Israel, 7200 for one hour earlier", -1 )
- write_file( settingsini, "access = ADMIN_MAP ; access to admin commands^n", -1 )
- write_file( settingsini, "mapsinmenu = 5 ; The amount of maps to appear in the menu ( dont count the extend & max is 5 )", -1 )
- write_file( settingsini, "maxrecentmaps = 3 ; The amount of maps to appear in the recent maps ( not include the correct map & max is 6 )", -1 )
- write_file( settingsini, "^n========== Timers Settings ( in seconds ) ==========", -1 )
- write_file( settingsini, "defaulttime = 600 ; The time has set when the vote has stopped", -1 )
- write_file( settingsini, "countdownrtv = 60 ; The time has set as countdown for rtv", -1 )
- write_file( settingsini, "votecountdown = 4 ; The time has left to countdown for the vote menu to appear", -1 )
- write_file( settingsini, "menucountdown = 16 ; The time has left to the menu to countdown to 0", -1 )
- write_file( settingsini, "extendtime = 600 ; The time has set when extended the map", -1 )
- write_file( settingsini, "nextmaptime = 10 ; The time has left to the next map to change", -1 )
- }
- //-------------------- Read the settings --------------------//
- if( File )
- {
- while( !feof( File ) )
- {
- //-------------------- File info --------------------//
- fgets( File, Line, charsmax( Line ) ); trim( Line )
- switch( Line[ 0 ] )
- {
- //-------------------- if line start with ; or empty skip --------------------//
- case EOS, ';': continue
- default:
- {
- //-------------------- make sure to be able to write info in the same line without count it as the line --------------------//
- strtok( Line, Line, charsmax( Line ), CuttedLine, charsmax( CuttedLine ), ';' ); trim( Line )
- //-------------------- Split the line at '=' so that everything after the '=' is processed --------------------//
- strtok( Line, option, charsmax( option ), text, charsmax( text ), '=' ); trim( option ); trim( text )
- //-------------------- if text is empty skip --------------------//
- if( text[ 0 ] == EOS ) continue
- //-------------------- prefix --------------------//
- if( equali( option, "prefix" ) ) copy( BaseSettings[ PREFIX ], charsmax( BaseSettings ), text )
- //-------------------- log folder --------------------//
- if( equali( option, "log_folder" ) ) copy( BaseSettings[ LOG_FOLDER ], charsmax( BaseSettings ), text )
- //-------------------- valve maps --------------------//
- if( equali( option, "valvemaps" ) ) BaseSettings[ AllowValveMaps ] = equali( text, "yes" ) ? true : false
- //-------------------- timezone --------------------//
- if( equali( option, "timezone" ) ) BaseSettings[ TimeZone ] = str_to_num( text )
- //-------------------- access --------------------//
- if( equali( option, "access" ) ) BaseSettings[ ACCESS ] = read_flags( text )
- //-------------------- maps in menu --------------------//
- if( equali( option, "mapsinmenu" ) ) BaseSettings[ MapsInMenu ] = str_to_num( text )
- //-------------------- max recent maps --------------------//
- if( equali( option, "maxrecentmaps" ) ) BaseSettings[ MaxRecentMaps ] = str_to_num( text )
- //-------------------- default time --------------------//
- if( equali( option, "defaulttime" ) ) BaseSettings[ DefaultTime ] = str_to_num( text )
- //-------------------- countdown rtv time --------------------//
- if( equali( option, "countdownrtv" ) ) BaseSettings[ Countdownrtv ] = str_to_num( text )
- //-------------------- vote countdown time --------------------//
- if( equali( option, "votecountdown" ) ) BaseSettings[ VoteCountdown ] = str_to_num( text )
- //-------------------- menu countdown time --------------------//
- if( equali( option, "menucountdown" ) ) BaseSettings[ MenuCountdown ] = str_to_num( text )
- //-------------------- extend time --------------------//
- if( equali( option, "extendtime" ) ) BaseSettings[ ExtendTime ] = str_to_num( text )
- //-------------------- nextmap time --------------------//
- if( equali( option, "nextmaptime" ) ) BaseSettings[ NextmapTimeleft ] = str_to_num( text )
- }
- }
- }
- fclose( File )
- }
- //-------------------- log's folder location --------------------//
- 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 ] ) )
- }
- //-------------------- Settings functions - default settings --------------------//
- defaultbasesettings()
- {
- copy( BaseSettings[ PREFIX ], charsmax( BaseSettings ), "VM" ) //-------- prefix ---------//
- copy( BaseSettings[ LOG_FOLDER ], charsmax( BaseSettings ), "VM/" ) //-------- log folder ---------//
- BaseSettings[ AllowValveMaps ] = false //-------- valve maps ---------//
- BaseSettings[ TimeZone ] = 0 //-------- timezone ---------//
- BaseSettings[ ACCESS ] = ADMIN_MAP //-------- access ---------//
- BaseSettings[ MapsInMenu ] = 5 //-------- maps in menu ---------//
- BaseSettings[ MaxRecentMaps ] = 3 //-------- max recent maps ---------//
- //-------- timers ---------//
- BaseSettings[ DefaultTime ] = 600 //-------- default time ---------//
- BaseSettings[ Countdownrtv ] = 60 //-------- countdown rtv time ---------//
- BaseSettings[ VoteCountdown ] = 4 //-------- vote countdown time ---------//
- BaseSettings[ MenuCountdown ] = 16 //-------- menu countdown time ---------//
- BaseSettings[ ExtendTime ] = 600 //-------- extend time ---------//
- BaseSettings[ NextmapTimeleft ] = 10 //-------- nextmap time ---------//
- }
- //-------------------- Stocks - nomination system --------------------//
- stock NominateMap( id, map )
- {
- //--------------- Vote status ---------------//
- if( votestatus( id ) ) return 1
- //--------------- Failsafe ---------------//
- if( map < 0 || map >= totalmaps ) return ColorChat( id, "Invalid map selection." )
- //-------------------- if the chosen map already have been nominated by another player --------------------//
- if( mapsystem[ map ][ nominated ] && IsMapNominated( mapsystem[ map ][ mapname ] ) != id )
- return ColorChat( id, "^3%n^1 has already nominated ^4%s^1.", IsMapNominated( mapsystem[ map ][ mapname ] ), mapsystem[ map ][ mapname ] )
- //-------------------- if the chosen map is nominated by you then denominate it --------------------//
- if( playersystem[ id ][ nominate ] && equali( playersystem[ id ][ mynom ], mapsystem[ map ][ mapname ] ) )
- {
- playersystem[ id ][ nominate ] = false
- playersystem[ id ][ mynom ] = 0
- votesystem[ nomcounter ]--
- mapsystem[ map ][ nominated ] = false
- ColorChat( 0, "^3%n^1 has denominated ^3%s^1.", id, mapsystem[ map ][ mapname ] )
- }
- else
- {
- //-------- if you already have nominated for another map then denominate it and nominate for the new one --------//
- if( playersystem[ id ][ mynom ] )
- {
- for( new i = 0; i < totalmaps; i++ ) if( equali( mapsystem[ i ][ mapname ], playersystem[ id ][ mynom ] ) ) mapsystem[ i ][ nominated ] = false
- mapsystem[ map ][ nominated ] = true
- ColorChat( 0, "^3%n^1 has changed his nominate from ^3%s^1 to ^3%s^1.", id, playersystem[ id ][ mynom ], mapsystem[ map ][ mapname ] )
- }
- else
- {
- votesystem[ nomcounter ]++
- playersystem[ id ][ nominate ] = true
- mapsystem[ map ][ nominated ] = true
- ColorChat( 0, "^3%n^1 nominated ^3%s^1.", id, mapsystem[ map ][ mapname ] )
- }
- copy( playersystem[ id ][ mynom ], 64, mapsystem[ map ][ mapname ] )
- }
- return 0
- }
- //-------------------- Stocks - check if this map nominated and by who --------------------//
- stock IsMapNominated( const map[] )
- {
- for( new i = 1; i <= get_maxplayers(); i++ )
- {
- //-------------------- If the player is not connected or its your own nominate --------------------//
- if( !is_user_connected( i ) ) continue
- if( equali( playersystem[ i ][ mynom ], map ) ) return i
- }
- return false
- }
- //-------------------- Stocks - check how many votes remain to rock the vote --------------------//
- stock VotesRemain()
- {
- new players[ 32 ], num = 0
- get_players( players, num, "ch" )
- return ( num/2 ) - votesystem[ rtvcounter ]
- }
- //-------------------- Stocks - ColorChat --------------------//
- stock ColorChat( id, const string[], any:... )
- {
- new msg[ 191 ], teamcolor = print_team_default
- new len = formatex( msg, charsmax( msg ), "^3[^1 %s ^3]^1 ", BaseSettings[ PREFIX ] )
- vformat( msg[ len ], charsmax( msg ) - len, string, 3 )
- if( containi( msg, "^5" ) != -1 ) replace_all( msg, charsmax( msg ), "^5", "^3"), teamcolor = print_team_red
- if( containi( msg, "^6" ) != -1 ) replace_all( msg, charsmax( msg ), "^6", "^3"), teamcolor = print_team_blue
- if( containi( msg, "^7" ) != -1 ) replace_all( msg, charsmax( msg ), "^7", "^3"), teamcolor = print_team_grey
- client_print_color( id, teamcolor, msg )
- return 1
- }
- //-------------------- Bools - vote status --------------------//
- bool:votestatus( id, bool:ignorenextmap = false )
- {
- if( votestate == Vote_Running ) ColorChat( id, "The vote is already ^3running^1." )
- else if( votestate == Vote_Starting ) ColorChat( id, "The vote is ^3starting^1 now." )
- 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" : "" )
- else return false
- return true
- }
- //-------------------- Bools - admin access --------------------//
- bool:hasaccess( id )
- {
- if( get_user_flags( id ) & BaseSettings[ ACCESS ] ) return true
- return false
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement