Raised This Month: $ Target: $400
 0% 

Solved how to detect if there are more than 4 chars in command


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Meelo
Member
Join Date: Aug 2010
Old 02-14-2021 , 09:40   how to detect if there are more than 4 chars in command
Reply With Quote #1

Hi, i have plugin what detect value of fps_max client cvar.

It's detecting fps_max 99.5 and if someone type fps_max 99.5. or 99.5.1 he automatically gain 100.5 fps.

I'm using this:
Code:
public fps(id,const cvar[],const value[])
{
if(str_to_num(value) <= 99.5) {
		        return;

		}else{

                user_kill(id,1)
      }
}
The solution would be if we can detect if there are more than 4 chars in fps_max command but i dont know how to make it

Last edited by Meelo; 02-15-2021 at 08:15.
Meelo is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-14-2021 , 09:54   Re: how to detect if there are more than 4 chars in command
Reply With Quote #2

Check if strlen( value ) > 4?
__________________

Last edited by Bugsy; 02-14-2021 at 10:00.
Bugsy is offline
Meelo
Member
Join Date: Aug 2010
Old 02-14-2021 , 12:44   Re: how to detect if there are more than 4 chars in command
Reply With Quote #3

okay, it works but i found another problem:

str_to_num see only if values are 100,99,98. If i type 99.9 fps are increases to 100.1 - 100.4 even if i'm checking if fps_max is 99.5
Meelo is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 02-14-2021 , 12:50   Re: how to detect if there are more than 4 chars in command
Reply With Quote #4

have u tried this?

PHP Code:
public fps(id, const cvar[], Float:value)
{
    if(
value <= 99.5)
    {
        return;

    }
    else
    {
        
user_kill(id,1)
    }

__________________

Last edited by Napoleon_be; 02-14-2021 at 12:51.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Meelo
Member
Join Date: Aug 2010
Old 02-14-2021 , 13:00   Re: how to detect if there are more than 4 chars in command
Reply With Quote #5

i tried different way, now yours and nothing happens
Meelo is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 02-14-2021 , 15:30   Re: how to detect if there are more than 4 chars in command
Reply With Quote #6

Perhaps you should share your whole code then.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-14-2021 , 15:32   Re: how to detect if there are more than 4 chars in command
Reply With Quote #7

Napoleon_be, the query_client_cvar() callback function passes the cvar and value as a string, you cannot convert it to a Float: like you have.

Meelo, you should convert to a float instead of integer when doing the validation.

PHP Code:
if ( str_to_floatvalue ) > 99.5 )
{
    
user_killid );

If this doesn't solve your problem, you can validate that their fps_max value is in the appropriate float format (only 1 decimal point). The below will kill a player if they have something like 99.5.1 or 90.3.2 (invalid float) or if their value is formatted correctly, but over 99.5.

PHP Code:
public fpsid , const cvar[] , const value[] )
{
    new 
iCount bool:bInvalid;
    new 
iLen strlenvalue );
    
    for ( new 
iLen i++ )
    {
        if ( 
value] == '.' )
        {
            if ( ++
iCount )
            {
                
bInvalid true;
                break;
            }
        }
    }
    
    if ( 
bInvalid || ( str_to_floatvalue ) > 99.5 ) )
    {
        if ( 
bInvalid )
            
client_printid print_chat "* Please fix your fps_max value, %s is formatted incorrectly." value );

        
user_killid );
    }    

__________________

Last edited by Bugsy; 02-14-2021 at 15:33.
Bugsy is offline
Meelo
Member
Join Date: Aug 2010
Old 02-14-2021 , 17:07   Re: how to detect if there are more than 4 chars in command
Reply With Quote #8

It works perfecly, thanks. One more question is why you check two times bInvalid?

PHP Code:
if ( bInvalid || ( str_to_floatvalue ) > 99.5 ) )
    {
        if ( 
bInvalid )
            
client_printid print_chat "* Please fix your fps_max value, %s is formatted incorrectly." value );

        
user_killid );
    }    


Last edited by Meelo; 02-14-2021 at 17:08.
Meelo is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-14-2021 , 17:19   Re: how to detect if there are more than 4 chars in command
Reply With Quote #9

Quote:
Originally Posted by Meelo View Post
It works perfecly, thanks. One more question is why you check two times bInvalid?

PHP Code:
if ( bInvalid || ( str_to_floatvalue ) > 99.5 ) )
    {
        if ( 
bInvalid )
            
client_printid print_chat "* Please fix your fps_max value, %s is formatted incorrectly." value );

        
user_killid );
    }    

Because there are two ways to get into that first if statement. If the value is greater than 99.5 then you will kill the player but it will only print the message if bInvalid is true.
__________________
fysiks is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-14-2021 , 17:23   Re: how to detect if there are more than 4 chars in command
Reply With Quote #10

I added that so it can notify the player why he is getting slayed each time. You may also want to advise that he needs to lower his FPS.
PHP Code:
if ( bInvalid || ( str_to_floatvalue ) > 99.5 ) )
{
    if ( 
bInvalid )
        
client_printid print_chat "* Please fix your fps_max value, %s is formatted incorrectly." value );
    else
        
client_printid print_chat "* Please lower your fps_max value less than or equal to 95.5" );
        
    
user_killid );    

__________________

Last edited by Bugsy; 02-15-2021 at 09:43.
Bugsy 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:34.


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