Author Topic: [RESOURCE] Port's Prefix Command Detector for Client-side Chatbots  (Read 671 times)

for forget's sake, stop using switch, strStr, or strStrW to check what the forget the player wants to command for your client-side chatbot

Code: [Select]
package FrogCM
{
    function clientCmdChatMessage(%cl,%a,%b,%line,%pre,%name,%suf,%msg,%x)
    {
        Parent::clientCmdChatMessage(%cl,%a,%b,%line,%pre,%name,%suf,%msg,%x);
        if(getSubStr(%msg,0,1) $= "@")
        {
            %msg = getSubStr(%msg,1,strLen(%msg));
            %cmd = firstWord(%msg);
            %arg = restWords(%msg);
            if(isFunction(%func = "frogCmd" @ %cmd))
                call(%func, %name, %arg);
        }
    }
};
function frogCmdExample(%name,%arg)
{
    echo("Hello" SPC %name);
}
PLEASE

USE THIS

I AM BEGGING YOU

Source: http://forum.blockland.us/index.php?topic=137725.msg3129523#msg3129523
« Last Edit: September 12, 2012, 05:36:19 PM by Axolotl2 »

why would you not do it this way anyway
i see what you mean


...

no
stop it

this code is so old and terrible
the theory is correct though

here, have something new
only allows messages from yourself because you're going to add a check for that in your other thing anyway

Quote
$MessagePrefix = "#";
$FunctionPrefix = "foo_";

package foobar
{
    function NMH_Type::send( %this )
    {
        %value = %this.getValue();
        %length = strLen( $MessagePrefix );
        
        if ( getSubStr( %value, 0, %length ) $= $MessagePrefix )
        {
            %this.setValue( "" );
            %value = getSubStr( %value, %length, strLen( %value ) );
            
            if ( isFunction( %func = $FunctionPrefix @ firstWord( %value ) ) )
            {
                call( %func, restWords( %value ) );
            }
        }
        
        parent::send( %this );
    }
};

activatePackage( "foobar" );

function foo_ragequit( %args )
{
    commandToServer( 'MessageSent', "ragequit or something" );
    schedule( serverConnection.getPing() * 2 + 1, 0, "disconnect" );
}

run this and type #ragequit in chat
« Last Edit: September 14, 2012, 03:21:02 AM by Port »