Binary Tree insead of strcmp
#2

As pawno preview : << I'll edit the topic in few minutes to add full command list.

Now full code, comands and first letters are typed down in comment.
And i think it'll be in 2 ways - 1st precoded into a file or anything and then downloaded by plugin. 2st made in script with some AddCommandNode("text") function.
pawn Код:
#include <a_samp>
forward cmdcmp(const string1[],const string2[], index);
/*
a c e i k m
/earn
/apply
/animat
/count
/counting
/info
/information
/kaiser
/mansion
/mapplace
*/

public OnFilterScriptInit()
{
    print("BinTree");
    OnPlayerCommandText(0, "/animat");
    return 1;
}

stock cmdcmp(const string1[],const string2[], index)
{
    while(strlen(string1)>index&&strlen(string2)>index)
    {
        if(string1[index]!=string2[index]) return false;
        index++;
    }
    return true;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if(cmdtext[1]==0x61) // Skips error, 0x61 = "a" Starts from 2nd char as 1st is always "/"
    {                    // Btw some of you always compare if "/" is once again equal to "/"
        if(cmdtext[2]==0x70) // "p" Oh and index is deepness in my means of this code
        {
            if(cmdcmp(cmdtext,"/apply",3)) print("Ok");
            else print("Failure");
            return 1;
        }
        else if(cmdtext[2]==0x6E) // "n"
        {
            if(cmdcmp(cmdtext,"/animat",3)) print("OK");
            return 1;
        }
        return 0;
    }
    else if(cmdtext[1]==0x63) // "c"
    {
        if(cmdtext[2]==0x6F) // "o"
        {
            if(cmdcmp(cmdtext,"/count",3)) // Doubleways
            {
                if(cmdcmp(cmdtext,"/counting",6))
                {
                    print("ing OK");
                }
                else print("count OK");
                return 1;
            }
            return 0;
        }
        return 0;
    }
    else if(cmdtext[1]==0x65) // "e"
    {
        if(cmdcmp(cmdtext,"/earn",2)) // One way - happens when last choose returns 1 command or maybe more. (Not everything is clear for me)
        {
            print("OK");
            return 1;
        }
        return 0;
    }
    else if(cmdtext[1]==0x69) // "i"
    {
        if(cmdtext[2]==0x65) // "f" - I'm not sure if i need to always directly go with cmdcmp here
        {
            if(cmdcmp(cmdtext,"/info",3)) //Another Doubleways, this time equal doubleways. Some developement is required here too.
            {
                print("OK");
                return 1;
            }
        }
        return 0;
    }
    else if(cmdtext[1]==0x6B) // "k"
    {
        if(cmdcmp(cmdtext,"/kaiser",2))// One way again
        {
            print("OK");
            return 1;
        }
        return 0;
    }
    else if(cmdtext[1]==0x6D) // "m"
    {
        if(cmdtext[2]==0x61) // "a"
        {
            if(cmdtext[3]==0x6E) // "n" 3rd level deepness check and i show the split which i hope will exist only in pawn
            {
                if(cmdcmp(cmdtext,"/mansion",4))
                {
                    print("OK");
                    return 1;
                }
            }
            else if(cmdcmp(cmdtext,"/mapplace",4)) // Here's the "problem" - i could do the same as in /mansion, but which is faster?
            //While it's one char, it should be here as it doesn't make anything new, but now i'm unsure. And this may appear in plugin too.
            {
                print("OK");
                return 1;
            }
            return 0;
        }
        return 0;
    }
    return 0;
}
Reply


Messages In This Thread
BST insead of strcmp(Could make faster cmd) - by RSX - 05.09.2010, 08:33
Re: Binary Tree insead of strcmp - by RSX - 05.09.2010, 10:32
Re: Binary Tree insead of strcmp - by RSX - 06.09.2010, 19:38

Forum Jump:


Users browsing this thread: 1 Guest(s)