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

Vote menu for only CTs


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
rambomst
SourceMod Donor
Join Date: Nov 2009
Location: Sydney, Australia
Old 06-26-2010 , 01:56   Vote menu for only CTs
Reply With Quote #1

I am trying to make a votemenu only show up for people that are on CT and I have been having issues getting this to work correctly. Sometimes it will work, other times it wont. So I think it has something to do with the way I am putting the CT players into the Clients[] variable or that I shouldn't be using MaxClients as the array size but when I tried to use GetArraySize it just refused to work.
Code:
SimonMenu(client)
{
    new Clients[32];
    if (IsVoteInProgress())
    {
        return;
    }
    g_ClientVote[0] = client;
    PrintToChatAll("\x01[\x03Trident-Gaming\x01] \x04A vote for simon says has been initiated.");
    new Handle:menu = CreateMenu(Handle_VoteMenu);
    SetMenuTitle(menu, "%N wants to start simon says: ", client);
    AddMenuItem(menu, "yes", "Yes");
    AddMenuItem(menu, "no", "No");
    SetMenuExitButton(menu, false);
    for(new i = 1; i <= MaxClients; i++)
    {
        if (IsClientInGame(i) && GetClientTeam(i) == 3)
        {
            Clients[i] = i; 
        }
    }
    VoteMenu(menu, Clients, MaxClients, 25);
}
__________________
rambomst is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 06-26-2010 , 02:58   Re: Vote menu for only CTs
Reply With Quote #2

Any errors in your console?

And perhaps make your Clients[] a bit larger, as MaxClients is probably 32, which will leave you one place short.

Does VoteMenu support the 0 client (server) as a valid client?
Monkeys is offline
rambomst
SourceMod Donor
Join Date: Nov 2009
Location: Sydney, Australia
Old 06-26-2010 , 03:05   Re: Vote menu for only CTs
Reply With Quote #3

I completely forgot I increased the size of my server and 32 wasn't enough, thanks Monkeys.
__________________
rambomst is offline
BrutalGoerge
AlliedModders Donor
Join Date: Jul 2007
Old 06-26-2010 , 05:44   Re: Vote menu for only CTs
Reply With Quote #4

that's not the problem XD
the clients array should not be incrementing by i, but every time it finds a CT, cuz assuming everyone isn't going to be ordered by what team they're on, that array is guna have gaps in it

client 1 is team 2
clean 2 is team 2
client 3 is team 3

then u got
Clients[0] = 0
Clients[1] = 0
Clients[2] = some client index #

you want the array to have nothing but valid indexes
and you were passing 32 to the voteMenu function every time... you want to pass the number of valid clients in the array
lookie
PHP Code:
SimonMenu(client)
{
    new 
Clients[MaxClients], iCount;
    if (
IsVoteInProgress())
    {
        return;
    }
    
g_ClientVote[0] = client;
    
PrintToChatAll("\x01[\x03Trident-Gaming\x01] \x04A vote for simon says has been initiated.");
    new 
Handle:menu CreateMenu(Handle_VoteMenu);
    
SetMenuTitle(menu"%N wants to start simon says: "client);
    
AddMenuItem(menu"yes""Yes");
    
AddMenuItem(menu"no""No");
    
SetMenuExitButton(menufalse);
    for(new 
1<= MaxClientsi++)
    {
        if (
IsClientInGame(i) && GetClientTeam(i) == 3)
        {
            
Clients[iCount++] = i
        }
    }
    
VoteMenu(menuClientsiCount25);

__________________
My Pluggies If you like, consider to me.

Last edited by BrutalGoerge; 06-26-2010 at 05:55.
BrutalGoerge is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 06-26-2010 , 06:20   Re: Vote menu for only CTs
Reply With Quote #5

Quote:
Originally Posted by BrutalGoerge View Post
that's not the problem XD
the clients array should not be incrementing by i, but every time it finds a CT, cuz assuming everyone isn't going to be ordered by what team they're on, that array is guna have gaps in it

client 1 is team 2
clean 2 is team 2
client 3 is team 3

then u got
Clients[0] = 0
Clients[1] = 0
Clients[2] = some client index #

you want the array to have nothing but valid indexes
and you were passing 32 to the voteMenu function every time... you want to pass the number of valid clients in the array
lookie
PHP Code:
SimonMenu(client)
{
    new 
Clients[MaxClients], iCount;
    if (
IsVoteInProgress())
    {
        return;
    }
    
g_ClientVote[0] = client;
    
PrintToChatAll("\x01[\x03Trident-Gaming\x01] \x04A vote for simon says has been initiated.");
    new 
Handle:menu CreateMenu(Handle_VoteMenu);
    
SetMenuTitle(menu"%N wants to start simon says: "client);
    
AddMenuItem(menu"yes""Yes");
    
AddMenuItem(menu"no""No");
    
SetMenuExitButton(menufalse);
    for(new 
1<= MaxClientsi++)
    {
        if (
IsClientInGame(i) && GetClientTeam(i) == 3)
        {
            
Clients[iCount++] = i
        }
    }
    
VoteMenu(menuClientsiCount25);

True, but that wouldn't call for the random behaviour he had as all ct's would still get added, although with gaps.
Monkeys is offline
rambomst
SourceMod Donor
Join Date: Nov 2009
Location: Sydney, Australia
Old 06-26-2010 , 06:29   Re: Vote menu for only CTs
Reply With Quote #6

After I increased the array size and made those changes BrutalGoerge suggested everything seems to be working fine and haven't had any complaints.
__________________
rambomst is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 06-26-2010 , 06:54   Re: Vote menu for only CTs
Reply With Quote #7

Good to hear.
Oh and simply for nice-coding's sake, try and start filling all your future arrays from index 0. Doesn't take too much trouble and can save a lot of hassle.
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys 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 08:19.


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