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

menu choose limit


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Caldeum
Senior Member
Join Date: Jul 2010
Location: United Kingdom
Old 06-19-2012 , 11:01   menu choose limit
Reply With Quote #1

How to put limit of choosing functions in menu?

example:
I have menu with 7 numbers in a same time i can enable and use only 3 (choosed 1 4 6 of 7) if i try to choose one more function (gonna be 4) just disable choosed 1 and enable 4.

Is is possible?

sorry for my bad english.

Put it to SourceMod please.
__________________
Of all the things I lost, I miss my brain the most.

Last edited by Caldeum; 06-19-2012 at 11:12.
Caldeum is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 06-19-2012 , 11:33   Re: menu choose limit
Reply With Quote #2

make a new array called iChoosen[33].

in your menu handler, if the player choosen an item, set iChoosen[id]++ and check in the menu or menu handler if the iChoosen[id] == 3, then return PLUGIN_HANDLED and eventually print a message.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Caldeum
Senior Member
Join Date: Jul 2010
Location: United Kingdom
Old 06-19-2012 , 13:27   Re: menu choose limit
Reply With Quote #3

One more question, if i turn off function i can't choose another. How to -1 from iChoosen?

iChoosen[ id ]--;
iChoosen[ id ]-1;
?
__________________
Of all the things I lost, I miss my brain the most.
Caldeum is offline
Zylius
SourceMod Donor
Join Date: Nov 2009
Old 06-19-2012 , 13:30   Re: menu choose limit
Reply With Quote #4

Quote:
Originally Posted by Caldeum View Post
One more question, if i turn off function i can't choose another. How to -1 from iChoosen?

iChoosen[ id ]--;
iChoosen[ id ]-1;
?
We can't really tell you how to turn off a "function" (which is probably not a function, just a hook) without knowing how your plugin operates.
Zylius is offline
Caldeum
Senior Member
Join Date: Jul 2010
Location: United Kingdom
Old 06-19-2012 , 14:16   Re: menu choose limit
Reply With Quote #5

Quote:
Originally Posted by Zylius View Post
We can't really tell you how to turn off a "function" (which is probably not a function, just a hook) without knowing how your plugin operates.
one of my case menu handle.
PHP Code:
                case 0:
                {
                    if ( 
g_iItem )
                    {
                        if ( 
option_show_itemparam1 ] == )
                        {
                            
option_show_itemparam1 ] = 0;
                            
iChoosenparam1 ]--;
                        }
                        else if ( 
iChoosenparam1 ] == )
                        {
                            
CPrintToChatparam1"You can use only 3 functions in a same time!" );
                            return;
                        }
                        else {
                            
option_show_itemparam1 ] = 1;
                            
iChoosenparam1 ]++;
                        }
                    }
                    else {
                        return;
                    }
                } 
PHP Code:
iChoosenid ]--; 
this one is working, but i'm using coockies menu, if i choose 3 items from menu and disconnect after connect i have 3 items selected, i can select 3 items more and if i'm gonna unselect 3 of selected items iChoosen[ id ]-- gives me -3, means i have +3 more to select. Total i can select 6 items.

I think to fix it like this: after player connect to the server and if he's has more than 4 items selected make it all to = 0 and need to get what player has selected from menu and convert to iChoosen (if he have 2 items selected then iChoosen = 2 means player can select one more item...

Do not know how to fix..

i try to fix but i fail:
PHP Code:
if ( iChoosenparam1]-- > )
{
      
iChoosenparam1 ] = 3;
}
else if ( 
iChoosenparam1]++ > ) {
      
iChoosenparam1 ] = 3;

Sorry for english. I hope you understand what I mean.
__________________
Of all the things I lost, I miss my brain the most.

Last edited by Caldeum; 06-19-2012 at 14:22.
Caldeum is offline
Zylius
SourceMod Donor
Join Date: Nov 2009
Old 06-19-2012 , 14:25   Re: menu choose limit
Reply With Quote #6

Quote:
Originally Posted by Caldeum View Post
one of my case menu handle.
PHP Code:
                case 0:
                {
                    if ( 
g_iItem )
                    {
                        if ( 
option_show_itemparam1 ] == )
                        {
                            
option_show_itemparam1 ] = 0;
                            
iChoosenparam1 ]--;
                        }
                        else if ( 
iChoosenparam1 ] == )
                        {
                            
CPrintToChatparam1"You can use only 3 functions in a same time!" );
                            return;
                        }
                        else {
                            
option_show_itemparam1 ] = 1;
                            
iChoosenparam1 ]++;
                        }
                    }
                    else {
                        return;
                    }
                } 
PHP Code:
iChoosenid ]--; 
this one is working, but i'm using coockies menu, if i choose 3 items from menu and disconnect after connect i have 3 items selected, i can select 3 items more and if i'm gonna unselect 3 of selected items iChoosen[ id ]-- gives me -3, means i have +3 more to select. Total i can select 6 items.

I think to fix it like this: after player connect to the server and if he's has more than 4 items selected make it all to = 0 and need to get what player has selected from menu and convert to iChoosen (if he have 2 items selected then iChoosen = 2 means player can select one more item...

Do not know how to fix..

i try to fix but i fail:
PHP Code:
if ( iChoosenparam1]-- > )
{
      
iChoosenparam1 ] = 3;
}
else if ( 
iChoosenparam1]++ > ) {
      
iChoosenparam1 ] = 3;

Sorry for english. I hope you understand what I mean.
If you are using cookies, you should use them instead of arrays, since the DB is local, Cookies are really fast.
Zylius is offline
Caldeum
Senior Member
Join Date: Jul 2010
Location: United Kingdom
Old 06-19-2012 , 14:39   Re: menu choose limit
Reply With Quote #7

Really i'm looking now on coockie and can't imagine how to put iChoosen to the **** coockie.

Save coockie:
PHP Code:
 IntToStringoption_show_itemparam1 ], cookiesizeofcookie ) );
SetClientCookieparam1cookie_show_itemcookie ); 
Get coockie:
PHP Code:
GetClientCookieclientcookie_show_itemcookiesizeofcookie ) );
if ( !
StrEqualcookie"" ) ) {
   
option_show_itemclient ] = StringToIntcookie ); 
Is it possible to put limit in iChoosen?
PHP Code:
iChoosenparam1 ]++ max 3
iChoosen
param1 ]-- max 3 
__________________
Of all the things I lost, I miss my brain the most.
Caldeum is offline
Zylius
SourceMod Donor
Join Date: Nov 2009
Old 06-19-2012 , 15:01   Re: menu choose limit
Reply With Quote #8

Quote:
Originally Posted by Caldeum View Post
Really i'm looking now on coockie and can't imagine how to put iChoosen to the **** coockie.

Save coockie:
PHP Code:
 IntToStringoption_show_itemparam1 ], cookiesizeofcookie ) );
SetClientCookieparam1cookie_show_itemcookie ); 
Get coockie:
PHP Code:
GetClientCookieclientcookie_show_itemcookiesizeofcookie ) );
if ( !
StrEqualcookie"" ) ) {
   
option_show_itemclient ] = StringToIntcookie ); 
Is it possible to put limit in iChoosen?
PHP Code:
iChoosenparam1 ]++ max 3
iChoosen
param1 ]-- max 3 
No it's not possible, integer is always integer, ranging from −(2^31) to 2^31 − 1 (like in most languages)( you can also call it a "cell" iirc). Just check it and that's it. If it's over 3, make it 3.
If you want to use arrays, you can do it, but make sure to save them to cookies OnClientDisconnect.
Zylius is offline
Caldeum
Senior Member
Join Date: Jul 2010
Location: United Kingdom
Old 06-19-2012 , 15:47   Re: menu choose limit
Reply With Quote #9

I make it! working nice, will need optimize then i get more brains

Getting coocies i just put code to check if player has selected one of the items and if selected give him iChoosed +1.

PHP Code:
public GetCookie client )
{
    
decl String:cookie];
    
    
GetClientCookieclientcookie_itemcookiesizeofcookie ) );
    if ( !
StrEqualcookie"" ) ) {
        
option_itemclient ] = StringToIntcookie );
    }
    
    if ( 
option_itemclient ] ) {
        
iChoosenclient ]++;
    }
    
    
GetClientCookieclientcookie_item2cookiesizeofcookie ) );
    if ( !
StrEqualcookie"" ) ) {
        
option_item2client ] = StringToIntcookie );
    }
    
    if ( 
option_item2client ] ) {
        
iChoosenclient ]++;
    }

Menu handle:
PHP Code:
case 0:
{
   if ( 
option_itemparam1 ] == )
   {
      
option_itemparam1 ] = 0;
      
iChoosenparam1 ]--;
   }
   else if ( 
iChoosenparam1 ] >= )
   {
      
CPrintToChatparam1"You can use only 3 functions in a same time!" );
      return;
   }
   else {
      
option_itemparam1 ] = 1;
      
iChoosenparam1 ]++;
   }
}
case 
1:
{
   if ( 
option_item2param1 ] == )
   {
      
option_itemparam1 ] = 0;
      
iChoosenparam1 ]--;
   }
   else if ( 
iChoosenparam1 ] >= )
   {
      
CPrintToChatparam1"You can use only 3 functions in a same time!" );
      return;
   }
   else {
      
option_item2param1 ] = 1;
      
iChoosenparam1 ]++;
   }

__________________
Of all the things I lost, I miss my brain the most.
Caldeum 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 06:43.


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