Raised This Month: $51 Target: $400
 12% 

Players vban - Voice Ban command


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 09-07-2016 , 16:32   Players vban - Voice Ban command
Reply With Quote #1

Players use vban command when connect into server and mute/unmute players.
vban execute two arguments, ex. vban 1 1

I'm not sure what purpose have second argument, because I have tested with bots, it just identical with first argument.

But vban command execute hexadecimal values, which is ban list
Just convert hex string to decimal, then use player slot as shift bit in binary.
(Slot start from index 0)



PHP Code:
int vban[MAXPLAYERS+1];

public 
void OnPluginStart()
{
    
AddCommandListener(listen"vban");
}

public 
Action listen(int client, const char[] commandint argc)
{
    
// vban mute list is hexadecimal
    
char hexadecimal[100];
    
GetCmdArg(1hexadecimalsizeof(hexadecimal));

    
// lets think it is binary, player slots, 00000000000000000000010000001000000000000000000000010000001011111
    
int binary;
    
StringToIntEx(hexadecimalbinary16);

    
// follow which bits get change from previous vban
    
int bits_toggle binary vban[client];

    
// store current vban
    
vban[client] = binary;

    
int slot;

    
// Loop in game players
    
for(new player 1player <= MaxClientsplayer++)
    {
        if(!
IsClientInGame(player)) continue;

        
// change player index to match player slot, shifted bit
        
slot player 1;

        
// bit has change ?
        
if(bits_toggle & (<< slot))
        {
            
// client muted player
            
if(binary & (<< slot))
            {
                
ClientMutedPlayer(clientplayerbinary);
            }
            else 
// client unmuted player
            
{
                
ClientUnMutedPlayer(clientplayerbinary);
            }
        }
    }

    return 
Plugin_Continue;
}

void ClientMutedPlayer(int clientint playerint &ban)
{
    
PrintToServer("ClientMutedPlayer(%N %N)"clientplayer);
    
MuteStatus();
}

void ClientUnMutedPlayer(int clientint playerint &ban)
{
    
PrintToServer("ClientUnMutedPlayer(%N %N)"clientplayer);
    
MuteStatus();
}

stock void MuteStatus()
{
    
int[] list = new int[MaxClients+1];
    
int slot;

    for(
int client 1client <= MaxClientsclient++)
    {
        if(!
IsClientInGame(client)) continue;

        for(
int player 1player <= MaxClientsplayer++)
        {
            if(!
IsClientInGame(player) || IsFakeClient(player)) continue;

            
slot client 1;
            if(
vban[player] & (<< slot)) list[client]++;
        }

        
PrintToServer("%i players muted %N", list[client], client);
    }

__________________
Do not Private Message @me

Last edited by Bacardi; 09-07-2016 at 16:35.
Bacardi is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 09-07-2016 , 18:33   Re: Players vban - Voice Ban command
Reply With Quote #2

Since the arguments are bitfields of which player to ban or not it can only store info of up to 32 players in one argument, so the second argument is for the other players, if the server has more than 32 slots.
See the code here.

Here's more info about the VoiceMask user message, which contains this info as well as info about which other players the player is able to hear (e.g. teammates). The usermessage sent by the server might be more reliable against players spaming shit ;)
__________________
Peace-Maker is offline
xines
Veteran Member
Join Date: Aug 2013
Location: Denmark
Old 09-08-2016 , 11:35   Re: Players vban - Voice Ban command
Reply With Quote #3

Nothing really to say about this, looks nice.

I'm a big fan of using as less characters as possible in loops, like:

PHP Code:
for(new player 1player <= MaxClientsplayer++) 
to:
PHP Code:
for(int p 1<= MaxClientsp++) 
of course this is a micro improvement, and is more a question about visual vs performance.
__________________
xines is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 09-08-2016 , 14:31   Re: Players vban - Voice Ban command
Reply With Quote #4

Thx for info @Peace-Maker.
Some day update snip to read argument(s) depending server max player size.
And perhaps look those user messages.

Ok @xines. I'm not really coder...
So I try name variables as words to get more readable etc. etc.
Bacardi is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 09:40.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode