Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define GAMEMESTATS // Comment this line if you are not going to use GameMe
- #if defined GAMEMESTATS
- #include <amxmodx>
- #include <amxmisc>
- #include <nvault>
- #include <gameme>
- #define QUERY_TYPE_ONCLIENTPUTINSERVER 1
- new MyRank[MAX_PLAYERS + 1]
- #else
- #include <amxmodx>
- #include <amxmisc>
- #include <nvault>
- #include <csstats>
- #endif
- #if AMXX_VERSION_NUM < 190
- #assert "This plugin requires AMXX 1.9 or above"
- #endif
- new VarRank, VarFlags[MAX_NAME_LENGTH], VarRestrict[MAX_NAME_LENGTH], Float:VarUpdateTime, bool:isTop[MAX_PLAYERS + 1], VarDaysToReset, VarReset, VarSkipAdmins
- public plugin_init()
- {
- register_plugin( "Top Flags", "3.0", "iceeedR" )
- register_cvar("TopFlags", "3.0", FCVAR_SERVER | FCVAR_SPONLY)
- register_dictionary("TopFlags.txt")
- bind_pcvar_num(create_cvar("tf_ranks", "10", .description = "Range of players that will receive the flags^nbased on rank. (Top 1, 2, 5, 10, 15 etc"), VarRank)
- bind_pcvar_string(create_cvar("tf_flags", "k", .description = "The flags that TOP players will receive."), VarFlags, charsmax(VarFlags ))
- bind_pcvar_string(create_cvar("tf_restricted", "a", .description = "Players with any of the flags set there will be ignored."), VarRestrict, charsmax(VarRestrict))
- bind_pcvar_float(create_cvar("tf_update_rank_time", "120", .description = "Time interval to update ranks", .has_min = true, .min_val = 40.0), VarUpdateTime)
- #if defined GAMEMESTATS
- bind_pcvar_num(create_cvar("tf_rank_reset", "1", .description = "A simple way to choose if you wanna reset^nyour rank or not", .has_min = true, .min_val = 0.0, .has_max = true, .max_val = 1.0), VarReset)
- bind_pcvar_num(create_cvar("tf_days_toreset", "30", .description = "Set an interval in days for resetting cs stats.", .has_min = true, .min_val = 1.0), VarDaysToReset)
- bind_pcvar_num(create_cvar("tf_skipadmins", "1", .description = "SkipAdmins to count topX ?", .has_min = true, .min_val = 0.0, .has_max = true, .max_val = 1.0), VarSkipAdmins)
- #endif
- set_task_ex(VarUpdateTime, "UpdateRanks", .flags = SetTask_Repeat)
- AutoExecConfig(.autoCreate = true, .name = "TopFlags")
- }
- #if defined GAMEMESTATS
- public UpdateRanks()
- {
- new iPlayers[MAX_PLAYERS], iNum, id
- get_players_ex(iPlayers, iNum, GetPlayers_ExcludeBots | GetPlayers_ExcludeHLTV)
- for(new i; i < iNum; i++)
- {
- id = iPlayers[i]
- if(has_flag(id, VarRestrict))
- continue
- QueryGameMEStats("playerinfo", id, "QuerygameMEStatsCallback", QUERY_TYPE_ONCLIENTPUTINSERVER)
- if(MyRank[id] && MyRank[id] > 0 && MyRank[id] <= VarRank)
- {
- if(!isTop[id])
- {
- client_print_color(0, print_team_default,"%L", id, "ONTOP", id, VarRank)
- remove_user_flags(id, ADMIN_USER)
- set_user_flags(id, read_flags(VarFlags))
- isTop[id] = true
- return PLUGIN_HANDLED
- }
- }
- else
- {
- if(isTop[id])
- {
- client_print_color(0, print_team_default,"%L", id, "TOPOUT", id, VarRank)
- remove_user_flags(id, read_flags(VarFlags))
- set_user_flags(id, ADMIN_USER)
- isTop[id] = false
- return PLUGIN_HANDLED
- }
- }
- }
- return PLUGIN_HANDLED
- }
- public QuerygameMEStatsCallback(command, payload, client, &DataPack:datapack)
- {
- if ((command == RAW_MESSAGE_CALLBACK_PLAYER) && (client > 0))
- {
- ResetPack(datapack)
- new iRank = ReadPackCell(datapack)
- SetPackPosition(datapack, 18)
- DestroyDataPack(datapack)
- if (payload == QUERY_TYPE_ONCLIENTPUTINSERVER)
- {
- MyRank[client] = iRank
- }
- }
- return PLUGIN_HANDLED;
- }
- #else
- public plugin_cfg()
- {
- if(VarReset)
- CheckDate()
- }
- public CheckDate()
- {
- new iVault , iTimeStamp , iRecordExists
- iVault = nvault_open( "TopFlags" )
- iRecordExists = nvault_lookup( iVault , "StatsReset" , "" , 0 , iTimeStamp )
- if ( !iRecordExists || ( iRecordExists && ( ( get_systime() - iTimeStamp ) >= ( VarDaysToReset * 86400 ) ) ) )
- {
- server_cmd( "amx_cvar csstats_reset 1" )
- nvault_set( iVault , "StatsReset" , "" )
- }
- nvault_close( iVault )
- }
- public getAdminCount()
- {
- new AdminCount = 0
- new izStats[STATSX_MAX_STATS], izBody[MAX_BODYHITS], iRankPos
- new iPlayers[MAX_PLAYERS], iNum
- get_players_ex(iPlayers, iNum, GetPlayers_ExcludeBots | GetPlayers_ExcludeHLTV)
- for(new i; i < iNum; i++)
- {
- iRankPos = get_user_stats(iPlayers[i], izStats, izBody)
- if(has_flag(iPlayers[i], VarRestrict) && iRankPos && iRankPos <= VarRank)
- {
- AdminCount ++
- }
- }
- return AdminCount
- }
- public UpdateRanks()
- {
- new izStats[STATSX_MAX_STATS], izBody[MAX_BODYHITS], iPlayers[MAX_PLAYERS], iNum, id, iRankPos
- new MaxCount = VarRank + (VarSkipAdmins == 1 ? getAdminCount() : 0)
- get_players_ex(iPlayers, iNum, GetPlayers_ExcludeBots | GetPlayers_ExcludeHLTV)
- for(new i; i < iNum; i++)
- {
- id = iPlayers[i]
- iRankPos = get_user_stats(id, izStats, izBody)
- if(has_flag(id, VarRestrict))
- continue
- if(iRankPos && iRankPos <= MaxCount)
- {
- if(!isTop[id])
- {
- client_print_color(0, print_team_default,"%L", id, "ONTOP", id, VarRank)
- remove_user_flags(id, ADMIN_USER)
- set_user_flags(id, read_flags(VarFlags))
- isTop[id] = true
- return PLUGIN_HANDLED
- }
- }
- else
- {
- if(isTop[id])
- {
- client_print_color(0, print_team_default,"%L", id, "TOPOUT", id, VarRank)
- remove_user_flags(id, read_flags(VarFlags))
- set_user_flags(id, ADMIN_USER)
- isTop[id] = false
- return PLUGIN_HANDLED
- }
- }
- }
- return PLUGIN_HANDLED
- }
- #endif
- public client_putinserver(id)
- isTop[id] = false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement