Raised This Month: $ Target: $400
 0% 

Out of bounds


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 04-23-2013 , 19:44   Out of bounds
Reply With Quote #1

I am trying to recreate The RTLer from SourceMod in AMXX but I am getting "Index out of bounds" error in line 58 when I am saying 2 words or more.

Code:
#include <amxmodx>
#include <amxmisc>

#pragma semicolon 1

public plugin_init()
{
    register_plugin("The RTLer", "1.0", "alongub");
    
    register_cvar("amx_rtler_enabled", "1");
    
    register_clcmd("say", "Command_Say", -1, "Registers the say command in The RTLer");
    // register_clcmd("say_team", "Command_SayTeam", -1, "Registers the say_team command in The RTLer");
}

public Command_Say(client)
{
    if(!get_cvar_num("amx_rtler_enabled"))
    {
        return PLUGIN_CONTINUE;
    }
    
    new arg_string[255];
    read_args(arg_string, 255);
    
    client_print(client, print_chat, "RTLed words: %d", _RTLify(arg_string, arg_string));
    
    if(!_RTLify(arg_string, arg_string))
    {
        return PLUGIN_CONTINUE;
    }
    
    return PLUGIN_HANDLED_MAIN;
}

_RTLify(dest[], original[])
{
    new rtledWords;
    
    new casino[32][32];
    new words[sizeof(casino)][sizeof(casino[])];
    
    new n = ExplodeString(casino, 32, 32, original, ' ');
    
    for(new word; word < n; word++)
    {
        if(WordAnalysis(casino[word]) >= 0.1)
        {
            ReverseString(casino[word], sizeof(casino[]), words[n - 1 - word]);
            rtledWords++;
        }
        
        else
        {
            new firstWord = word;
            new lastWord = word;
            
            while(WordAnalysis(casino[lastWord]) < 0.1)
            {
                lastWord++;
            }
            
            for(new t = lastWord - 1; t >= firstWord; t--)
            {
                copy(words[n - 1 - word], sizeof(casino[]), casino[t]);
                
                if(t > firstWord)
                {
                    word++;
                }
            }
        }
    }
    
    ImplodeStrings(words, n, " ", dest, sizeof(words[]));
    
    return rtledWords;
}

stock ExplodeString( p_szOutput[][], p_nMax, p_nSize, p_szInput[], p_szDelimiter ) 
{
    new nIdx, l = strlen(p_szInput) ;
    
    new nLen = (1 + copyc(p_szOutput[nIdx], p_nSize, p_szInput, p_szDelimiter));
    
    while((nLen < l) && (++nIdx < p_nMax)) 
    {
        nLen += (1 + copyc(p_szOutput[nIdx], p_nSize, p_szInput[nLen], p_szDelimiter));
    }
    
    return nIdx;
}

ReverseString(str[], maxlength, buffer[])
{
    for(new character = strlen(str); character >= 0; character--)
    {
        if(str[character] >= 0xD6 && str[character] <= 0xDE)
        {
            continue;
        }
        
        if(character > 0 && str[character - 1] >= 0xD7 && str[character - 1] <= 0xD9)
        {
            format(buffer, maxlength, "%s%c%c", buffer, str[character - 1], str[character]);
        }
        
        else
        {
            format(buffer, maxlength, "%s%c", buffer, str[character]);
        }
    }
}

Float:WordAnalysis(word[])
{
    new count, length = strlen(word);
    
    for(new n; n < length - 1; n++)
    {
        if(IsRTLCharacter(word, n))
        {    
            count++;
            n++;
        }
    }
    
    return float(count) * 2 / length;
}

bool:IsRTLCharacter(str[], n)
{
    return (str[n] >= 0xD6 && str[n] <= 0xDE && str[n + 1] >= 0x80 && str[n + 1] <= 0xBF);
}

ImplodeStrings(const strings[][], numStrings, const join[], buffer[], maxLength)
{
    new total, length, part_length;
    new join_length = strlen(join);
    
    for(new i; i < numStrings; i++)
    {
        length = copy(buffer[total], maxLength - total, strings[i]);
        total += length;
        
        if(length < part_length)
        {
            break;
        }
        
        if(i != numStrings - 1)
        {
            length = copy(buffer[total], maxLength - total, join);
            total += length;
            
            if(length < join_length)
            {
                break;
            }
        }
    }
    
    return total;
}
Help would be appreciated.
__________________
retired
shavit is offline
 



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 10:55.


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