Caps lock on command.
#1

my stock for iscaps
Код:
stock IsCaps( text[ ] ) 
{
    for( new i, j = strlen( text )-1; i < j; i ++ )
    {
        if( ( 'A' <= text[ i ] <= 'Z' ) && ( 'A' <= text[ i+6 ] <= 'Z' ) )
            return true;
    }
    return false;
}
Here is my CMD for shout
Код:
CMD:s(playerid, params[]) return cmd_shout(playerid, params);
CMD:shout(playerid, params[])
{
    new
        string[128],
        shout[100];
    if( IsCaps( shout ) )
    {
        SendClientMessage( playerid, -1, ""COL_RED"[GRESKA]: "COL_WHITE"Ne mozete pisati Caps Lockom, velika slova oznacavaju sukob! "COL_RED"Iskljucite"COL_WHITE" Caps Lock"COL_RED"!" );
        return 0;
    }
    if(sscanf(params, "s[100]", shout))
    {
        SendClientMessage(playerid, -1, ""COL_CYAN"[KORISTI]: "COL_WHITE"/(s)hout [text]");
        return 1;
    }
    else
    {
        format(string, sizeof(string), "%s se dere: %s!!",GetName(playerid),shout);
        ProxDetector(50.0, playerid, string, -1);
    }
    return 1;
}
and i enter /s HAHAHAHAHAH and not working.. not giving error for caps lock
Reply
#2

You're trying to check an empty string, you need to check it after sscanf is passed the string to shout variable.
pawn Код:
CMD:s(playerid, params[]) return cmd_shout(playerid, params);
CMD:shout(playerid, params[])
{
    new
        string[128],
        shout[100];
    if(sscanf(params, "s[100]", shout))
    {
        SendClientMessage(playerid, -1, ""COL_CYAN"[KORISTI]: "COL_WHITE"/(s)hout [text]");
        return 1;
    }
    else
    {
        if( IsCaps( shout ) )
        {
            SendClientMessage( playerid, -1, ""COL_RED"[GRESKA]: "COL_WHITE"Ne mozete pisati Caps Lockom, velika slova oznacavaju sukob! "COL_RED"Iskljucite"COL_WHITE" Caps Lock"COL_RED"!" );
            return 0;
        }
        format(string, sizeof(string), "%s se dere: %s!!",GetName(playerid),shout);
        ProxDetector(50.0, playerid, string, -1);
    }
    return 1;
}
Also what is text[i+6]? This is unnecessary, and wouldn't work, because it will do this:
"Just A Text" = 11chars + 1 \0
'A' <= text[6+6] <= 'Z' will return false, as it's \0
'A' <= text[7+6] <= 'Z' will return false, as there is no char at string 13.... (might probably stop working)
Also strlen will not count the \0 at the end, so you don't need to -1, unless you want also call "HAHAHa" as Caps.
So change to this, don't worry, all characters will be checked if it's capitals
pawn Код:
stock IsCaps( text[ ] )
{
    for( new i, j = strlen( text ); i < j; i ++ )
    {
        if( ( 'A' <= text[ i ] <= 'Z' ) )
            return true;
    }
    return false;
}
I didn't test it, but i hope it works (it should).
Reply
#3

its 6 is allowed of CAPS LOCK, now player cant type "xD" "HAHA" ""
Reply
#4

What do you mean ?
Reply
#5

Quote:
Originally Posted by YanLanger
Посмотреть сообщение
What do you mean ?
i want make limit 6 CAPS LOCK in text
Reply
#6

pawn Код:
stock IsCaps(text[])
{
    new count = 0;
    for(new i = 0, j = strlen(text) - 1; i < j; i++)
    {
        if('A' <= text[i] <= 'Z') count++;
    }
    return (count >= 6) ? (true) : (false);
}

CMD:s(playerid, params[]) return cmd_shout(playerid, params);
CMD:shout(playerid, params[])
{
    new shout[90];
    if(sscanf(params, "s[90]", shout)) return SendClientMessage(playerid, -1, ""COL_CYAN"[KORISTI]: "COL_WHITE"/(s)hout [text]");
    if(IsCaps(shout)) return SendClientMessage( playerid, -1, ""COL_RED"[GRESKA]: "COL_WHITE"Ne mozete pisati Caps Lockom, velika slova oznacavaju sukob! "COL_RED"Iskljucite"COL_WHITE" Caps Lock"COL_RED"!" );
    new string[128];
    format(string, sizeof(string), "%s se dere: %s!!", GetName(playerid), shout);
    ProxDetector(50.0, playerid, string, -1);
    return 1;
}
pawn Код:
return (count >= 6) ? (true) : (false);
This line determines the limit for caps lock. If you want to change it to 8 capital characters, change the 6 to an 8.
Reply
#7

Quote:
Originally Posted by Threshold
Посмотреть сообщение
pawn Код:
stock IsCaps(text[])
{
    new count = 0;
    for(new i = 0, j = strlen(text) - 1; i < j; i++)
    {
        if('A' <= text[i] <= 'Z') count++;
    }
    return (count >= 6) ? (true) : (false);
}

CMD:s(playerid, params[]) return cmd_shout(playerid, params);
CMD:shout(playerid, params[])
{
    new shout[90];
    if(IsCaps(shout)) return SendClientMessage( playerid, -1, ""COL_RED"[GRESKA]: "COL_WHITE"Ne mozete pisati Caps Lockom, velika slova oznacavaju sukob! "COL_RED"Iskljucite"COL_WHITE" Caps Lock"COL_RED"!" );
    if(sscanf(params, "s[90]", shout)) return SendClientMessage(playerid, -1, ""COL_CYAN"[KORISTI]: "COL_WHITE"/(s)hout [text]");
    new string[128];
    format(string, sizeof(string), "%s se dere: %s!!", GetName(playerid), shout);
    ProxDetector(50.0, playerid, string, -1);
    return 1;
}
pawn Код:
return (count >= 6) ? (true) : (false);
This line determines the limit for caps lock. If you want to change it to 8 capital characters, change the 6 to an 8.
respect+ thank you
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)