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

Help with filtering CT/T in loop


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
BeeFighter
Member
Join Date: Feb 2012
Old 02-17-2012 , 09:52   Help with filtering CT/T in loop
Reply With Quote #1

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <colorchat>
#include <cstrike>

#define PLUGIN "JB Spec Day"
#define AUTHOR "Pancakez"

//How many different votes there will be in the menu
#define MAX_VOTEIDS 7

//How much "weight" a normal player's vote is worth
#define WEIGHT_PLAYER 1

//How much "weight" an admin's vote is worth
#define WEIGHT_ADMIN 2
 
new gVoteMenu;
new 
gVotes[MAX_VOTEIDS];
new 
gVoting;
new 
gVoteID[MAX_VOTEIDS];

new 
bool:IsCommander[33]

public 
plugin_init() 
{
    
register_plugin(PLUGIN"0.0.1"AUTHOR)
    
register_logevent("EventNewRound"2"1=Round_Start")
    
register_logevent("EventRoundEnd"2"1=Round_End")
    
register_clcmd("say /vote""StartVote")
    
register_clcmd("say /blabla""blabla")
}

public 
EventNewRound(id)
{
    
//StartVote(id)
}

public 
EventRoundEnd(id)
{
    
IsCommander[id] = false
}

public 
StartVote(id)
{
    if( 
gVoting )
    {
        
ColorChat(idGREY"[^4HB^3] There is already a vote going.");
        return 
PLUGIN_HANDLED;
    }

    
gVoteMenu menu_create("\rWho should be the commander?""menu_handler");

    
//Here you can do whatever you want to add your voteids.
    //We are going to use players for the example
    
new players[32], pnumtempid;
    
get_players(playerspnum"a");
    
    
//Variable for if the player was added to the vote
    
new bool:player_added[33], voteid_count;

    new 
szName[32], szTempid[10];
        
    
//Loop through until we get enough voteids or run out of players
    
while( voteid_count MAX_VOTEIDS && voteid_count pnum)
    {
        
//Get a random player
        
tempid playersrandom(pnum) ];
        
        
//If they haven't been added yet
        
if( !player_added[tempid] )
        {
            
get_user_name(tempidszNamecharsmax(szName));

            
//We are setting the data to the voteid number, not the actual voteid
            
num_to_str(voteid_countszTempidcharsmax(szTempid));

            
menu_additem(gVoteMenuszNameszTempid0);

            
//Make sure we do not add them again
            
player_added[tempid] = true;

            
//Save the voteid
            
gVoteID[voteid_count] = tempid;

            
//Go to the next voteid
            
voteid_count++;
        }
    }

    
//Now we have all the voteids

    
for( new ii<pnumi++ )
    {        
        
//Save a tempid so we do not re-index
        
tempid players[i];

        
//Show the vote to this player
        
menu_display(tempidgVoteMenu0);

        
//Increase how many players are voting by their weight
        
if( is_user_admin(tempid) )
            
gVoting += WEIGHT_ADMIN;
        else
            
gVoting += WEIGHT_PLAYER;
    }

    
set_task(10.0"EndVote");
    
    return 
PLUGIN_HANDLED;
}

public 
menu_handler(idmenuitem)
{
    
//If the menu was exited or if there is not a vote
    
if( item == MENU_EXIT || !gVoting )
    {
        return 
PLUGIN_HANDLED;
    }

    new 
data[6], szName[64];
    new 
accesscallback;
    
menu_item_getinfo(menuitemaccessdata,charsmax(data), szName,charsmax(szName), callback);

    
//Get the voteid number that was selected
    
new voteid_num str_to_num(data);

    
//Increase the votes for what they selected by weight
    
if( is_user_admin(id) )
        
gVotes[voteid_num] += WEIGHT_ADMIN;
    else
        
gVotes[voteid_num] += WEIGHT_PLAYER;
    
    return 
PLUGIN_HANDLED;
}

public 
EndVote()
{
    
//This will hold how many different votes were selected
    
new votes_select;

    
//This will hold the top 3 votes
    
new votes[3];

    
//This will hold the top 3 selected voteids
    
new voteid[3];

    new 
ij;

    
//Loop through all the voteids
    
for( i=0i<MAX_VOTEIDSi++ )
    {
        
//If the voteid recieved any votes
        
if( gVotes[i] )
        {
            
//If we are still trying to get the top 3
            
if( votes_select )
            {
                
//Save the data for the current voteid selected
                
votes[votes_select] = gVotes[i];
                
voteid[votes_select] = i;

                
//Go to the next voteid that might have been selected
                
votes_select++;
            }
            else
            {
                
//Loop through all the top votes, replace any that are lower than the selected voteid
                
for( j=0j<3j++ )
                {
                    
//If this one recieved less votes
                    
if( votes[j] < gVotes[i] )
                    {
                        
//Change the data to the voteid with more votes
                        
votes[j] = gVotes[i];
                        
voteid[j] = i;

                        
//Don't need to bother looking for more
                        
break;
                    }
                }
            }
        }
    }

    
//If noone voted
    
if( !votes_select )
    {
        
ColorChat(0GREY"[^4HB^3] Commander Vote Failed.");
    }
    
//Else if one voteid recieved all the votes
    
else if( votes_select == )
    {
        
//Give it to the voteid
        
VoteGiveCommandervoteid[0] );
    }
    
//Else if two different voteids recieved all the votes
    
else if( votes_select == )
    {
        
//If they recieved even votes
        
if( votes[0] == votes[1] )
        {
            
//Give it to a random one
            
ColorChat(0GREY"[^4HB^3] Vote has tied. Choosing random from tied votes.");
            
VoteGiveCommandervoteidrandom(2) ] );
        }

        
//Else if the first recieved the most
        
else if( votes[0] > votes[1] )
            
//Give it to the first
            
VoteGiveCommandervoteid[0] );

        
//Else the second recieved the most
        
else
            
//Give it to the second
            
VoteGiveCommandervoteid[1] );
    }
    
//Else there were at least 3 different votes
    
else
    {
        
//Here you might want to do run-off voting, but well just select a random one
        
ColorChat(0GREY"[^4HB^3] Could not determine a winner. Selecting random.");
        
VoteGiveCommandervoteidrandom(3) ] );
    }

    
menu_destroy(gVoteMenu);
    
gVoting 0;
}

VoteGiveCommander(index

    new 
id gVoteID[index]
    if( 
is_user_alive(id) ) 
    { 
        
IsCommander[id] = true
        
new szName[32]; 
        
get_user_name(idszNamecharsmax(szName)); 
        
ColorChat(0GREY"[^4HB^3] %s Have been voted as commander!"szName); 
    } 
}

public 
blabla(id)
{
    if(
IsCommander[id] == true)
    {
        
set_user_noclip(id1)
    }
    else 
client_print(idprint_chat"You are not the commander!")

I want the CT's only to show up in the vote menu. I've tried several things but without succes. Don't bother the public bla bla, it's only testing things.
BeeFighter is offline
anakin_cstrike
Veteran Member
Join Date: Nov 2007
Location: Romania
Old 02-18-2012 , 09:54   Re: Help with filtering CT/T in loop
Reply With Quote #2

PHP Code:
get_players(playerspnum"ae""CT"); 
__________________

anakin_cstrike 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 18:55.


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