Raised This Month: $32 Target: $400
 8% 

[L4D2] !kickspec


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
dustinandband
Senior Member
Join Date: May 2015
Old 12-20-2017 , 10:19   [L4D2] !kickspec
Reply With Quote #1

* vote panel should use nativevotes:
https://forums.alliedmods.net/showthread.php?t=208008

* Should manually count the votes and tally them up (see line 108 of example code).

* spectators cannot vote, just people on the survivor or infected team.


Example code, using nativevotes (for changing server slots):
https://pastebin.com/cPxDaSFA
dustinandband is offline
dustinandband
Senior Member
Join Date: May 2015
Old 12-20-2017 , 10:23   Re: [L4D2] !kickspec
Reply With Quote #2

Ah also forgot, when it's looping for anyone on the spectate team to be kicked (if the vote passes), it should skip admins. Thanks
dustinandband is offline
dustinandband
Senior Member
Join Date: May 2015
Old 12-22-2017 , 04:20   Re: [L4D2] !kickspec
Reply With Quote #3

Drixevel was kind to code this, wanted to share.

Required dependencies
Native Votes - https://forums.alliedmods.net/showthread.php?t=208008

edit: spectators can no longer vote
PHP Code:
#include <sourcemod>
#include <nativevotes>

public Plugin myinfo =
{
    
name "[NativeVotes] KickSpec",
    
author "Keith Warren (Sky Guardian)",
    
description "Vote to kick all spectators from the server.",
    
url "http://www.sourcemod.com/"
}

public 
OnPluginStart()
{
    
RegConsoleCmd("sm_kickspec"OnCallVote"Vote to kick all spectators from the server.");
    
RegConsoleCmd("sm_kickspecs"OnCallVote"Vote to kick all spectators from the server.");
}

public 
Action OnCallVote(int clientint args)
{
    
    if ((
GetClientTeam(client) == 1) && (!IsGenericAdmin(client)))
    {
        
PrintToChat(client"\x04You must be on the survivor or infected team to use this command.");
        return 
Plugin_Handled;
    }

    if (
IsVoteInProgress())
    {
        
PrintToChat(client"\x04[SM] You cannot start a vote while one is currently going.");
        return 
Plugin_Handled;
    }

    
Handle vote NativeVotes_Create(MenuHandler_VoteCallbackNativeVotesType_Custom_YesNo);
    
NativeVotes_SetInitiator(voteclient);

    
char sDetails[256];
    
FormatEx(sDetailssizeof(sDetails), "Kick spectators from the server?");
    
NativeVotes_SetDetails(votesDetails);
    
NativeVotes_SetResultCallback(voteVoteResultHandler);
    
NativeVotes_DisplayToAllNonSpectators(vote20);

    return 
Plugin_Handled;
}

public 
int MenuHandler_VoteCallback(Menu menuMenuAction actionint param1int param2)
{
    switch (
action)
    {
    case 
MenuAction_VoteCancel:
        {
            if (
param1 == VoteCancel_NoVotes)
            {
                
NativeVotes_DisplayFail(menuNativeVotesFail_NotEnoughVotes);
            }
            else
            {
                
NativeVotes_DisplayFail(menuNativeVotesFail_Generic);
            }
        }
        
    case 
MenuAction_End:
        {
            
NativeVotes_Close(menu);
        }
    }
}

public 
int VoteResultHandler(Handle voteint num_votesint num_clients, const int[] client_indexes, const int[] client_votesint num_items, const int[] item_indexes, const int[] item_votes)
{
    for (
int i 0num_itemsi++)
    {
        if (
item_indexes[i] == NATIVEVOTES_VOTE_YES && item_votes[i] > (num_clients 2))
        {
            
char sDetails[256];
            
FormatEx(sDetailssizeof(sDetails), "Kicking non-admin spectators from the server...");
            
NativeVotes_DisplayPass(votesDetails);
            
            for (
int x 1<= MaxClientsx++)
            {
                if (
IsClientInGame(x) && GetClientTeam(x) == && !CheckCommandAccess(x"kickspec_immune"ADMFLAG_RESERVATIONtrue))
                {
                    
KickClient(x"You have been kicked for being a spectator.");
                }
            }
            
            return;
        }
    }

    
NativeVotes_DisplayFail(voteNativeVotesFail_Loses);


static 
bool:IsGenericAdmin(client) {
    return 
CheckCommandAccess(client"generic_admin"ADMFLAG_GENERICfalse); 


Last edited by dustinandband; 03-17-2018 at 02:47.
dustinandband is offline
valedar
Member
Join Date: May 2022
Location: Russian
Old 06-26-2022 , 10:31   Re: [L4D2] !kickspec
Reply With Quote #4

Quote:
Originally Posted by dustinandband View Post
Drixevel was kind to code this, wanted to share.

Required dependencies
Native Votes - https://forums.alliedmods.net/showthread.php?t=208008

edit: spectators can no longer vote
PHP Code:
#include <sourcemod>
#include <nativevotes>

public Plugin myinfo =
{
    
name "[NativeVotes] KickSpec",
    
author "Keith Warren (Sky Guardian)",
    
description "Vote to kick all spectators from the server.",
    
url "http://www.sourcemod.com/"
}

public 
OnPluginStart()
{
    
RegConsoleCmd("sm_kickspec"OnCallVote"Vote to kick all spectators from the server.");
    
RegConsoleCmd("sm_kickspecs"OnCallVote"Vote to kick all spectators from the server.");
}

public 
Action OnCallVote(int clientint args)
{
    
    if ((
GetClientTeam(client) == 1) && (!IsGenericAdmin(client)))
    {
        
PrintToChat(client"\x04You must be on the survivor or infected team to use this command.");
        return 
Plugin_Handled;
    }

    if (
IsVoteInProgress())
    {
        
PrintToChat(client"\x04[SM] You cannot start a vote while one is currently going.");
        return 
Plugin_Handled;
    }

    
Handle vote NativeVotes_Create(MenuHandler_VoteCallbackNativeVotesType_Custom_YesNo);
    
NativeVotes_SetInitiator(voteclient);

    
char sDetails[256];
    
FormatEx(sDetailssizeof(sDetails), "Kick spectators from the server?");
    
NativeVotes_SetDetails(votesDetails);
    
NativeVotes_SetResultCallback(voteVoteResultHandler);
    
NativeVotes_DisplayToAllNonSpectators(vote20);

    return 
Plugin_Handled;
}

public 
int MenuHandler_VoteCallback(Menu menuMenuAction actionint param1int param2)
{
    switch (
action)
    {
    case 
MenuAction_VoteCancel:
        {
            if (
param1 == VoteCancel_NoVotes)
            {
                
NativeVotes_DisplayFail(menuNativeVotesFail_NotEnoughVotes);
            }
            else
            {
                
NativeVotes_DisplayFail(menuNativeVotesFail_Generic);
            }
        }
        
    case 
MenuAction_End:
        {
            
NativeVotes_Close(menu);
        }
    }
}

public 
int VoteResultHandler(Handle voteint num_votesint num_clients, const int[] client_indexes, const int[] client_votesint num_items, const int[] item_indexes, const int[] item_votes)
{
    for (
int i 0num_itemsi++)
    {
        if (
item_indexes[i] == NATIVEVOTES_VOTE_YES && item_votes[i] > (num_clients 2))
        {
            
char sDetails[256];
            
FormatEx(sDetailssizeof(sDetails), "Kicking non-admin spectators from the server...");
            
NativeVotes_DisplayPass(votesDetails);
            
            for (
int x 1<= MaxClientsx++)
            {
                if (
IsClientInGame(x) && GetClientTeam(x) == && !CheckCommandAccess(x"kickspec_immune"ADMFLAG_RESERVATIONtrue))
                {
                    
KickClient(x"You have been kicked for being a spectator.");
                }
            }
            
            return;
        }
    }

    
NativeVotes_DisplayFail(voteNativeVotesFail_Loses);


static 
bool:IsGenericAdmin(client) {
    return 
CheckCommandAccess(client"generic_admin"ADMFLAG_GENERICfalse); 

kickspec.sp(33) : error 100: function prototypes do not match
kickspec.sp(40) : warning 234: symbol "NativeVotes_DisplayToAllNonSpectators" is marked as deprecated: This functionality should be done in client plugins instead
valedar is offline
Sreaper
髪を用心
Join Date: Nov 2009
Old 06-27-2022 , 00:24   Re: [L4D2] !kickspec
Reply With Quote #5

Quote:
Originally Posted by valedar View Post
kickspec.sp(33) : error 100: function prototypes do not match
kickspec.sp(40) : warning 234: symbol "NativeVotes_DisplayToAllNonSpectators" is marked as deprecated: This functionality should be done in client plugins instead
Compiled on Sourcemod 1.11, verified working on TF2.

PHP Code:
#include <sourcemod>
#include <nativevotes>

public Plugin myinfo 
{
    
name "[NativeVotes] KickSpec"
    
author "Keith Warren (Sky Guardian), edited by Malifox"
    
description "Vote to kick all spectators from the server."
    
url "http://www.sourcemod.com/"
}

public 
OnPluginStart()
{
    
RegConsoleCmd("sm_kickspec"OnCallVote"Vote to kick all spectators from the server.");
    
RegConsoleCmd("sm_kickspecs"OnCallVote"Vote to kick all spectators from the server.");
}

public 
Action OnCallVote(int clientint args)
{
    
    if ((
GetClientTeam(client) == 1) && (!IsGenericAdmin(client))){
        
PrintToChat(client"\x04[SM] Spectators may not use this command.");
        return 
Plugin_Handled;
    }
        
    if (
NativeVotes_IsVoteInProgress())
    {
        
PrintToChat(client"\x04[SM] You cannot start a vote while one is currently going.");
        return 
Plugin_Handled;
    }
    
    
//NativeVote vote = NativeVotes_Create(MenuHandler_VoteCallback, NativeVotesType_Custom_YesNo);
    
NativeVote vote = new NativeVote(MenuHandler_VoteCallbackNativeVotesType_Custom_YesNoNATIVEVOTES_ACTIONS_DEFAULT MenuAction_Display);
    
/*NativeVotes_SetInitiator(vote, client);

    char sDetails[256];
    FormatEx(sDetails, sizeof(sDetails), "Kick spectators from the server?");
    NativeVotes_SetDetails(vote, sDetails);
    NativeVotes_SetResultCallback(vote, VoteResultHandler);
    NativeVotes_DisplayToAllNonSpectators(vote, 20);*/
    
    
vote.Initiator client;
    
vote.SetDetails("Kick spectators from the server?");
    
vote.DisplayVoteToAll(20);
    
    return 
Plugin_Handled;
}

/*public int MenuHandler_VoteCallback(NativeVote menu, MenuAction action, int param1, int param2)
{
    switch (action)
    {
    case MenuAction_VoteCancel:
        {
            if (param1 == VoteCancel_NoVotes)
            {
                NativeVotes_DisplayFail(menu, NativeVotesFail_NotEnoughVotes);
            }
            else
            {
                NativeVotes_DisplayFail(menu, NativeVotesFail_Generic);
            }
        }
        
    case MenuAction_End:
        {
            NativeVotes_Close(menu);
        }
    }
}*/

public int MenuHandler_VoteCallback(NativeVote voteMenuAction actionint param1int param2)
{
    switch (
action)
    {
        case 
MenuAction_End:
        {
            
vote.Close();
        }
        
        case 
MenuAction_Display:
        {
            
char display[64];
            
Format(displaysizeof(display), "Kick spectators from the server?");
            
PrintToChat(param1"Vote: %s"display);
            
NativeVotes_RedrawVoteTitle(display);
            return 
view_as<int>(Plugin_Changed);
        }
        
        case 
MenuAction_VoteCancel:
        {
            if (
param1 == VoteCancel_NoVotes)
            {
                
vote.DisplayFail(NativeVotesFail_NotEnoughVotes);
            }
            else
            {
                
vote.DisplayFail(NativeVotesFail_Generic);
            }
        }
        
        case 
MenuAction_VoteEnd:
        {
            if (
param1 == NATIVEVOTES_VOTE_NO)
            {
                
vote.DisplayFail(NativeVotesFail_Loses);
            }
            else
            {
                
vote.DisplayPass("Vote Passed!");
                for (
int i 1<= MaxClientsi++) {
                    if (
IsClientInGame(i) && !IsFakeClient(i) && GetClientTeam(i) == && !CheckCommandAccess(i"kickspec_immune"ADMFLAG_RESERVATIONtrue))
                    {
                        
KickClient(i"You have been votekicked.");
                    }
                }
                
                
            }
        }
    }
    
    return 
0;
}

/*public int VoteResultHandler(Handle vote, int num_votes, int num_clients, const int[] client_indexes, const int[] client_votes, int num_items, const int[] item_indexes, const int[] item_votes)
{
    for (int i = 0; i < num_items; i++)
    {
        if (item_indexes[i] == NATIVEVOTES_VOTE_YES && item_votes[i] > (num_clients / 2))
        {
            char sDetails[256];
            FormatEx(sDetails, sizeof(sDetails), "Kicking non-admin spectators from the server...");
            NativeVotes_DisplayPass(vote, sDetails);
            
            for (int x = 1; x <= MaxClients; x++)
            {
                if (IsClientInGame(x) && GetClientTeam(x) == 1 && !CheckCommandAccess(x, "kickspec_immune", ADMFLAG_RESERVATION, true))
                {
                    KickClient(x, "You have been kicked for being a spectator.");
                }
            }
            
            return;
        }
    }

    NativeVotes_DisplayFail(vote, NativeVotesFail_Loses);
}*/

static bool:IsGenericAdmin(client) {
    return 
CheckCommandAccess(client"generic_admin"ADMFLAG_GENERICfalse);


Last edited by Sreaper; 06-27-2022 at 01:30.
Sreaper is offline
valedar
Member
Join Date: May 2022
Location: Russian
Old 06-27-2022 , 09:07   Re: [L4D2] !kickspec
Reply With Quote #6

Quote:
Originally Posted by Sreaper View Post
Compiled on Sourcemod 1.11, verified working on TF2.

PHP Code:
#include <sourcemod>
#include <nativevotes>

public Plugin myinfo 
{
    
name "[NativeVotes] KickSpec"
    
author "Keith Warren (Sky Guardian), edited by Malifox"
    
description "Vote to kick all spectators from the server."
    
url "http://www.sourcemod.com/"
}

public 
OnPluginStart()
{
    
RegConsoleCmd("sm_kickspec"OnCallVote"Vote to kick all spectators from the server.");
    
RegConsoleCmd("sm_kickspecs"OnCallVote"Vote to kick all spectators from the server.");
}

public 
Action OnCallVote(int clientint args)
{
    
    if ((
GetClientTeam(client) == 1) && (!IsGenericAdmin(client))){
        
PrintToChat(client"\x04[SM] Spectators may not use this command.");
        return 
Plugin_Handled;
    }
        
    if (
NativeVotes_IsVoteInProgress())
    {
        
PrintToChat(client"\x04[SM] You cannot start a vote while one is currently going.");
        return 
Plugin_Handled;
    }
    
    
//NativeVote vote = NativeVotes_Create(MenuHandler_VoteCallback, NativeVotesType_Custom_YesNo);
    
NativeVote vote = new NativeVote(MenuHandler_VoteCallbackNativeVotesType_Custom_YesNoNATIVEVOTES_ACTIONS_DEFAULT MenuAction_Display);
    
/*NativeVotes_SetInitiator(vote, client);

    char sDetails[256];
    FormatEx(sDetails, sizeof(sDetails), "Kick spectators from the server?");
    NativeVotes_SetDetails(vote, sDetails);
    NativeVotes_SetResultCallback(vote, VoteResultHandler);
    NativeVotes_DisplayToAllNonSpectators(vote, 20);*/
    
    
vote.Initiator client;
    
vote.SetDetails("Kick spectators from the server?");
    
vote.DisplayVoteToAll(20);
    
    return 
Plugin_Handled;
}

/*public int MenuHandler_VoteCallback(NativeVote menu, MenuAction action, int param1, int param2)
{
    switch (action)
    {
    case MenuAction_VoteCancel:
        {
            if (param1 == VoteCancel_NoVotes)
            {
                NativeVotes_DisplayFail(menu, NativeVotesFail_NotEnoughVotes);
            }
            else
            {
                NativeVotes_DisplayFail(menu, NativeVotesFail_Generic);
            }
        }
        
    case MenuAction_End:
        {
            NativeVotes_Close(menu);
        }
    }
}*/

public int MenuHandler_VoteCallback(NativeVote voteMenuAction actionint param1int param2)
{
    switch (
action)
    {
        case 
MenuAction_End:
        {
            
vote.Close();
        }
        
        case 
MenuAction_Display:
        {
            
char display[64];
            
Format(displaysizeof(display), "Kick spectators from the server?");
            
PrintToChat(param1"Vote: %s"display);
            
NativeVotes_RedrawVoteTitle(display);
            return 
view_as<int>(Plugin_Changed);
        }
        
        case 
MenuAction_VoteCancel:
        {
            if (
param1 == VoteCancel_NoVotes)
            {
                
vote.DisplayFail(NativeVotesFail_NotEnoughVotes);
            }
            else
            {
                
vote.DisplayFail(NativeVotesFail_Generic);
            }
        }
        
        case 
MenuAction_VoteEnd:
        {
            if (
param1 == NATIVEVOTES_VOTE_NO)
            {
                
vote.DisplayFail(NativeVotesFail_Loses);
            }
            else
            {
                
vote.DisplayPass("Vote Passed!");
                for (
int i 1<= MaxClientsi++) {
                    if (
IsClientInGame(i) && !IsFakeClient(i) && GetClientTeam(i) == && !CheckCommandAccess(i"kickspec_immune"ADMFLAG_RESERVATIONtrue))
                    {
                        
KickClient(i"You have been votekicked.");
                    }
                }
                
                
            }
        }
    }
    
    return 
0;
}

/*public int VoteResultHandler(Handle vote, int num_votes, int num_clients, const int[] client_indexes, const int[] client_votes, int num_items, const int[] item_indexes, const int[] item_votes)
{
    for (int i = 0; i < num_items; i++)
    {
        if (item_indexes[i] == NATIVEVOTES_VOTE_YES && item_votes[i] > (num_clients / 2))
        {
            char sDetails[256];
            FormatEx(sDetails, sizeof(sDetails), "Kicking non-admin spectators from the server...");
            NativeVotes_DisplayPass(vote, sDetails);
            
            for (int x = 1; x <= MaxClients; x++)
            {
                if (IsClientInGame(x) && GetClientTeam(x) == 1 && !CheckCommandAccess(x, "kickspec_immune", ADMFLAG_RESERVATION, true))
                {
                    KickClient(x, "You have been kicked for being a spectator.");
                }
            }
            
            return;
        }
    }

    NativeVotes_DisplayFail(vote, NativeVotesFail_Loses);
}*/

static bool:IsGenericAdmin(client) {
    return 
CheckCommandAccess(client"generic_admin"ADMFLAG_GENERICfalse);

thanks

Last edited by valedar; 06-27-2022 at 09:17.
valedar is offline
Reply


Thread Tools
Display Modes

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 04:12.


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