Coder Social home page Coder Social logo

Comments (3)

cato-a avatar cato-a commented on August 18, 2024

Hey

Perhaps you could redesign the code a bit and modify the CodeCallback_PlayerCommand in callback.gsc.

This is just a suggestion, I've not tested the code.

Modify command(str) function to the following:

command(str)
{
    str = codam\_mm_mmm::strip(str);
    if(str.size == 1) return; // just 1 letter, ignore

    isloggedin = (bool)isDefined(self.pers["mm_group"]);
    cmd = codam\_mm_mmm::strTok(str, " "); // is a command with level.prefix
    if(isDefined(level.commands[cmd[0]])) {
        perms = level.perms["default"];

        cmduser = "none";
        cmdgroup = cmduser;

        if(isloggedin) {
            cmduser = self.pers["mm_user"];
            cmdgroup = self.pers["mm_group"];
            perms = codam\_mm_mmm::array_join(perms, level.perms[cmdgroup]);
        }

        command = cmd[0]; // !something
        if(command != "!login") {
            commandargs = "";
            for(i = 1; i < cmd.size; i++) {
                if(i > 1)
                    commandargs += " ";
                commandargs += cmd[i];
            }

            if(commandargs == "")
                commandargs = "none";

            codam\_mm_mmm::mmlog("command;" + self getip() + ";" + codam\_mm_mmm::namefix(self.name) + ";" + cmduser + ";" + cmdgroup + ";" + command + ";" + commandargs);
        }

        commandid = level.commands[command]["id"]; // permission id
        if(commandid == 0 || permissions(perms, commandid))
            thread [[ level.commands[command]["func"] ]](cmd);
        else if(isloggedin)
            message_player("^1ERROR: ^7Access denied.");
        else
            message_player("^1ERROR: ^7No such command. Check your spelling.");
    } else {
        if(getCvarInt("scr_mm_rcm_compatibility") > 0) { // RCM compatibility
            logmessage = "";
            for(i = 0; i < cmd.size; i++) {
                if(i > 0)
                    logmessage += " ";

                logmessage += cmd[i];
            }

            codam\_mm_mmm::mmlog("say;" + codam\_mm_mmm::namefix(self.name) + ";" + logmessage);
        } else
            message_player("^1ERROR: ^7No such command. Check your spelling.");
    }
}

Create a function below command(str) function called command_mute(str):

command_mute(str)
{
    if((bool)isDefined(self.pers["mm_group"])) {
        return false;
    }

    if(level.maxmessages > 0) {
        penaltytime = level.penaltytime;
        if(self.pers["mm_chatmessages"] > level.maxmessages)
            penaltytime += self.pers["mm_chatmessages"] - level.maxmessages;
        penaltytime *= 1000;

        if(getTime() - self.pers["mm_chattimer"] >= penaltytime) {
            self.pers["mm_chattimer"] = getTime();
            self.pers["mm_chatmessages"] = 1;
        } else {
            self.pers["mm_chatmessages"]++;
            if(self.pers["mm_chatmessages"] > level.maxmessages) {
                if(self.pers["mm_chatmessages"] > 19) // 20 seconds max wait
                    self.pers["mm_chatmessages"] = 19; // 20 seconds max wait
                
                unit = "seconds";
                if(penaltytime == 1000) // 1 second
                    unit = "second";
                message_player("You are currently muted for " + (penaltytime / 1000.0) + " " + unit + ".");
            }
        }
    }

    if(isDefined(self.pers["mm_mute"]) || (level.maxmessages > 0 && self.pers["mm_chatmessages"] > level.maxmessages)) {
        return true;
    }

    if(badwords_mute(str)) {
        badmessage = "^5INFO: ^7You were silenced due to inappropriate language.";
        if(isDefined(self.badword))
            badmessage += " The offensive word in question was: " + self.badword + ".";
        message_player(badmessage);

        return true;
    }

    return false;
}

Modify callback.gsc to the following:

CodeCallback_PlayerCommand(args)
{
    if(isDefined(level.command)) {
        if(args[0] == "say" || args[0] == "say_team") {
            if(!isDefined(args[1])) {
                return;
            }

            command = "";
            for(i = 1; i < args.size; i++) {
                command += args[i];
                if(i < args.size - 1) {
                    command += " ";
                }
            }

            if(codam\_mm_commands::command_mute(command)) {
                return;
            }

            if(args[1][0] == level.prefix) {
                [[ level.command ]](command);

                return;
            }
        }
    }

    self processClientCommand();
}

Maybe it's a good idea to redesign the command codebase further to avoid all those array -> str -> array -> str and come up with something better.

from codam_miscmod.

raphael12333 avatar raphael12333 commented on August 18, 2024

@cato-a i have just tried the code and now !mute works, but when muted the player can't use miscmod commands anymore

i don't think that is the case when using the main branch but i would check to be sure

i guess the way to allow the player to use miscmod commands while being muted would be to handle the client commands like codextended does, or maybe i'm missing the part in the gsc where it could be done

from codam_miscmod.

cato-a avatar cato-a commented on August 18, 2024

In "main" MiscMod the player would also not be able to use any commands while muted.

For commands to work I guess you could move the following if below if(args[1][0] == level.prefix) statement:

if(codam\_mm_commands::command_mute(command)) {
    return;
}

from codam_miscmod.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.