View Single Post
youssef_randy
Junior Member
Join Date: Dec 2016
Location: Morocco
Old 01-04-2017 , 15:14   Re: [Help] Rate Admin (+rep , -rep)
Reply With Quote #8

Quote:
Originally Posted by Bugsy View Post
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
{
    
szName32 ],
    
szAuthID32 ],
    
bool:bIsAdmin,
    
iNumGood,
    
iNumBad,
    
bool:bVotedMAX_PLAYERS ]
}
new 
g_pdDataMAX_PLAYERS ][ 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_closeg_Vault );
}

public 
client_authorizedid )
{
    
get_user_authidid g_pdDataid ][ szAuthID ] , charsmaxg_pdData[][ szAuthID ] ) );
    
    if ( ( 
g_pdDataid ][ bIsAdmin ] = bool:( get_user_flagsid ) & AdminFlag ) ) )
    {
        
nvault_get_arrayg_Vault g_pdDataid ][ szAuthID ] , g_pdDataid ][ szName ][ ] , sizeofg_pdData[] ) );
        
        if ( ( 
g_pdDataid ][ iNumBad ] - g_pdDataid ][ iNumGood ] ) >= get_pcvar_numg_pMinusVotes ) )
        {
            
set_user_flagsid ADMIN_USER );
        }
    }
    
    
get_user_nameid g_pdDataid ][ szName ] , charsmaxg_pdData[][ szName ] ) );
    
    
arraysetg_pdDataid ][ bVoted ] , false sizeofg_pdData[][ bVoted ] ) ); 
}

public 
client_disconnectid )
{
    if ( 
g_pdDataid ][ bIsAdmin ] )
    {
        
nvault_set_arrayg_Vault g_pdDataid ][ szAuthID ] , g_pdDataid ][ szName ][ ] , sizeofg_pdData[] ) );
    }
}

public 
ShowRateMenuid )
{
    new 
iMenu menu_create"\r[AW] \wAdmin Rate menu" "AdminHandler" );
    new 
szID] , iAdminsLoaded;
    
    for( new 
<= MAX_PLAYERS i++ )
    {
        if ( ( 
!= id ) && ( g_pdData][ bIsAdmin ] == true ) )
        {
            
num_to_strszID charsmaxszID ) );
            
menu_additemiMenu g_pdData][ szName ] , szID );
            
iAdminsLoaded++;
        }
    }
    
    if ( 
iAdminsLoaded )
    {
        
menu_displayid iMenu );
    }
    else
    {
        
client_printid print_chat "^4[AW]^3 There are no admins to vote." );
    }
    
    return 
PLUGIN_HANDLED;
}

public 
AdminHandlerid iMenu iKey )
{
    new 
iNewMenu szID] , iDummy;
    
    
menu_item_getinfoiMenu iKey iDummy szID charsmaxszID ) , "" iDummy );  
    
    
iNewMenu menu_createg_pdDatastr_to_numszID ) ][ szName ] , "RateHandler");
    
    
menu_additemiNewMenu "\r+Rep \yGood Admin" szID );
    
menu_additemiNewMenu "\r-Rep \yBad Admin" szID );
    
    
menu_displayid iNewMenu );
}

public 
RateHandlerid iMenu iKey )
{
    new 
szID] , iDummy iAdminID;
    
    if( 
iKey == MENU_EXIT )
    {
        
menu_destroyiMenu );
        return;
    }
    
    
menu_item_getinfoiMenu iKey iDummy szID charsmaxszID ) , "" iDummy );  
    
    
iAdminID str_to_numszID );
    
    if ( 
g_pdDataid ][ bVoted ][ iAdminID ] == true 
    {
        
client_print(idprint_chat"^4[AW]^3 You have already rated this Player");
    }
    else
    {
        
g_pdDataid ][ bVoted ][ iAdminID ] = true;
        
        
client_printid print_chat "%s's rate %s" g_pdDataiAdminID ][ szName ] , iKey == "plus" "minus" );
        
        
log_to_file"AdminRate.log" "%s (%s) voted %s for %s (%s)" g_pdDataid ][ szName ] , g_pdDataid ][ szAuthID ] , iKey == "PLUS" "MINUS" g_pdDataiAdminID ][ szName ] , g_pdDataiAdminID ][ szAuthID ] );
        
        if ( 
iKey == )
        {
            
g_pdDataiAdminID ][ iNumGood ]++;
        }
        else
        {
            
g_pdDataiAdminID ][ iNumBad ]++;
        }
    }

Wow man thank you so mush!
youssef_randy is offline