Page 1 of 1

Reduction of slash commands in official plug-ins

Posted: Wed Jan 09, 2019 5:39 pm
by Zehra
One thing, I have noticed which could perhaps be improved on a few plug-ins is the reduction of slash commands.

For example, the following code within the KoTH plug-in:

Code: Select all

    if ( command == "kothautotimeon")
    {
        koth.autoTimeOn = true;
        autoTime();
        bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "King of the Hill automatic time adjustment on.");
        return true;
    }

    if ( command == "kothautotimeoff")
    {
        koth.autoTimeOn = false;
        koth.adjustedTime = koth.TTH;
        autoTime();
        bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "King of the Hill automatic time adjustment off.");
        return true;
    }
Could be rewritten as this:

Code: Select all

    if ( command == "kothautotime")
    {
        if (_param->get(0) == "on" || _param->get(0) == "1")
        {
            koth.autoTimeOn = true;
            autoTime();
            bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "King of the Hill automatic time adjustment on.");
        }
        else if (_param->get(0) == "off" || _param->get(0) == "0")
        {
            koth.autoTimeOn = false;
            koth.adjustedTime = koth.TTH;
            autoTime();
            bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "King of the Hill automatic time adjustment off.");
        }
        else
        {
            bz_sendTextMessage(BZ_SERVER, playerID, "Usage: /kothautotime on|off");
        }
        return true;
    }
Instead of two slash commands, a single one is used.
This could be done with a few plug-ins, and most likely make them easier to use as well.

-Zehra