youssef_randy |
01-04-2017 15:14 |
Re: [Help] Rate Admin (+rep , -rep)
Quote:
Originally Posted by Bugsy
(Post 2483260)
Here's the first draft. Once an admin accumulates 12 minus votes, his admin power will be removed the next time he connects. The calculation is done using [minus votes] - [plus votes]; so if he has 15 minus votes and 5 plus votes (10 total minus), he is ok and keeps admin, but if has 15 minus and 2 plus (13 minus), he loses admin. Each vote on the admin is remembered between admin connections so you can keep track of votes over time. Each vote is stored in a log file so you can see if the same player re-votes for a specific admin. I'm thinking of bringing in nVault Utility to show a MOTD displaying each admin and their vote counts.
What I think would be better is to only allow each player to vote a specific admin 1 time. It does do this per-connection, but if the player disconnects/re-connects, he can again vote the same admin.
You will need nVault Array
PHP Code:
#include <amxmodx>
#include <nvault_array>
new const Version[] = "0.1";
#define MAX_PLAYERS 32
const AdminFlag = ADMIN_IMMUNITY;
enum PlayerData
{
szName[ 32 ],
szAuthID[ 32 ],
bool:bIsAdmin,
iNumGood,
iNumBad,
bool:bVoted[ MAX_PLAYERS + 1 ]
}
new g_pdData[ MAX_PLAYERS + 1 ][ PlayerData ];
new g_Vault , g_pMinusVotes;
public plugin_init()
{
register_plugin( "Rate Admins" , Version , "bugsy" );
register_clcmd( "say /eport" , "ShowRateMenu" );
g_pMinusVotes = register_cvar( "ra_minusvotes" , "12" );
if ( ( g_Vault = nvault_open( "RateAdmins" ) ) == INVALID_HANDLE )
set_fail_state( "Error opening vault" );
}
public plugin_end()
{
nvault_close( g_Vault );
}
public client_authorized( id )
{
get_user_authid( id , g_pdData[ id ][ szAuthID ] , charsmax( g_pdData[][ szAuthID ] ) );
if ( ( g_pdData[ id ][ bIsAdmin ] = bool:( get_user_flags( id ) & AdminFlag ) ) )
{
nvault_get_array( g_Vault , g_pdData[ id ][ szAuthID ] , g_pdData[ id ][ szName ][ 0 ] , sizeof( g_pdData[] ) );
if ( ( g_pdData[ id ][ iNumBad ] - g_pdData[ id ][ iNumGood ] ) >= get_pcvar_num( g_pMinusVotes ) )
{
set_user_flags( id , ADMIN_USER );
}
}
get_user_name( id , g_pdData[ id ][ szName ] , charsmax( g_pdData[][ szName ] ) );
arrayset( g_pdData[ id ][ bVoted ] , false , sizeof( g_pdData[][ bVoted ] ) );
}
public client_disconnect( id )
{
if ( g_pdData[ id ][ bIsAdmin ] )
{
nvault_set_array( g_Vault , g_pdData[ id ][ szAuthID ] , g_pdData[ id ][ szName ][ 0 ] , sizeof( g_pdData[] ) );
}
}
public ShowRateMenu( id )
{
new iMenu = menu_create( "\r[AW] \wAdmin Rate menu" , "AdminHandler" );
new szID[ 3 ] , iAdminsLoaded;
for( new i = 1 ; i <= MAX_PLAYERS ; i++ )
{
if ( ( i != id ) && ( g_pdData[ i ][ bIsAdmin ] == true ) )
{
num_to_str( i , szID , charsmax( szID ) );
menu_additem( iMenu , g_pdData[ i ][ szName ] , szID );
iAdminsLoaded++;
}
}
if ( iAdminsLoaded )
{
menu_display( id , iMenu );
}
else
{
client_print( id , print_chat , "^4[AW]^3 There are no admins to vote." );
}
return PLUGIN_HANDLED;
}
public AdminHandler( id , iMenu , iKey )
{
new iNewMenu , szID[ 3 ] , iDummy;
menu_item_getinfo( iMenu , iKey , iDummy , szID , charsmax( szID ) , "" , 0 , iDummy );
iNewMenu = menu_create( g_pdData[ str_to_num( szID ) ][ szName ] , "RateHandler");
menu_additem( iNewMenu , "\r+Rep \yGood Admin" , szID );
menu_additem( iNewMenu , "\r-Rep \yBad Admin" , szID );
menu_display( id , iNewMenu );
}
public RateHandler( id , iMenu , iKey )
{
new szID[ 3 ] , iDummy , iAdminID;
if( iKey == MENU_EXIT )
{
menu_destroy( iMenu );
return;
}
menu_item_getinfo( iMenu , iKey , iDummy , szID , charsmax( szID ) , "" , 0 , iDummy );
iAdminID = str_to_num( szID );
if ( g_pdData[ id ][ bVoted ][ iAdminID ] == true )
{
client_print(id, print_chat, "^4[AW]^3 You have already rated this Player");
}
else
{
g_pdData[ id ][ bVoted ][ iAdminID ] = true;
client_print( id , print_chat , "%s's rate %s" , g_pdData[ iAdminID ][ szName ] , iKey == 0 ? "plus" : "minus" );
log_to_file( "AdminRate.log" , "%s (%s) voted %s for %s (%s)" , g_pdData[ id ][ szName ] , g_pdData[ id ][ szAuthID ] , iKey == 0 ? "PLUS" : "MINUS" , g_pdData[ iAdminID ][ szName ] , g_pdData[ iAdminID ][ szAuthID ] );
if ( iKey == 0 )
{
g_pdData[ iAdminID ][ iNumGood ]++;
}
else
{
g_pdData[ iAdminID ][ iNumBad ]++;
}
}
}
|
Wow man thank you so mush!
|