Results 1 to 9 of 9

Thread: [Extension] Player Command Control (includes CHAT-Control for Builtin-B3!)

  1. #1
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,014
    Thanks
    2,110
    Thanked 1,086 Times in 753 Posts

    [Extension] Player Command Control (includes CHAT-Control for Builtin-B3!)

    Hey all! I'm happy to announce a new feature!

    I've added a new callback into CoDScript, which is called: CodeCallback_PlayerCommand(args)

    What does it do?

    Lets say somebody wrote in Chat: hello
    args[0] = "say"
    args[1] = "hello"

    (are you already dreaming about your own builtin-BigBrotherBot? )

    Since its not only about chat-messages, you can catch ALL other client commands, like "mr", for menuresponses. Or even console-commands sent by client!

    Type in console: /lol a command
    args[0] = "lol"
    args[1] = "a"
    args[2] = "command"

    (the command is ONLY forwarded to server, if the client couldn't execute it!)

    To get a feeling of all the messages a server is arriving, just uncomment this in the callback:
    PHP Code:
        //printf("PLAYER COMMAND! message=\"%\"\n", output);
        //self iprintlnbold("you wrote: " + output); 
    Many new possibilities


    The first functions are the normal ones, just look at the last:
    PHP Code:
    //    Callback Setup
    //    This script provides the hooks from code into script for the gametype callback functions.

    //=============================================================================
    // Code Callback functions

    /*================
    Called by code after the level's main script function has run.
    ================*/
    CodeCallback_StartGameType()
    {
        
    // If the gametype has not beed started, run the startup
        
    if(!isDefined(level.gametypestarted) || !level.gametypestarted)
        {
            [[
    level.callbackStartGameType]]();

            
    level.gametypestarted true// so we know that the gametype has been started up
        
    }
    }

    /*================
    Called when a player begins connecting to the server.
    Called again for every map change or tournement restart.

    Return undefined if the client should be allowed, otherwise return
    a string with the reason for denial.

    Otherwise, the client will be sent the current gamestate
    and will eventually get to ClientBegin.

    firstTime will be qtrue the very first time a client connects
    to the server machine, but qfalse on map changes and tournement
    restarts.
    ================*/
    CodeCallback_PlayerConnect()
    {
        
    self endon("disconnect");
        [[
    level.callbackPlayerConnect]]();
    }

    /*================
    Called when a player drops from the server.
    Will not be called between levels.
    self is the player that is disconnecting.
    ================*/
    CodeCallback_PlayerDisconnect()
    {
        
    self notify("disconnect");
        [[
    level.callbackPlayerDisconnect]]();
    }

    /*================
    Called when a player has taken damage.
    self is the player that took damage.
    ================*/
    CodeCallback_PlayerDamage(eInflictoreAttackeriDamageiDFlagssMeansOfDeathsWeaponvPointvDirsHitLoctimeOffset)
    {
        
    self endon("disconnect");
        [[
    level.callbackPlayerDamage]](eInflictoreAttackeriDamageiDFlagssMeansOfDeathsWeaponvPointvDirsHitLoctimeOffset);
    }

    /*================
    Called when a player has been killed.
    self is the player that was killed.
    ================*/
    CodeCallback_PlayerKilled(eInflictoreAttackeriDamagesMeansOfDeathsWeaponvDirsHitLoctimeOffsetdeathAnimDuration)
    {
        
    self endon("disconnect");
        [[
    level.callbackPlayerKilled]](eInflictoreAttackeriDamagesMeansOfDeathsWeaponvDirsHitLoctimeOffsetdeathAnimDuration);
    }

    //=============================================================================

    /*================
    Setup any misc callbacks stuff like defines and default callbacks
    ================*/
    SetupCallbacks()
    {
        
    SetDefaultCallbacks();
        
        
    // Set defined for damage flags used in the playerDamage callback
        
    level.iDFLAGS_RADIUS            1;
        
    level.iDFLAGS_NO_ARMOR            2;
        
    level.iDFLAGS_NO_KNOCKBACK        4;
        
    level.iDFLAGS_NO_TEAM_PROTECTION    8;
        
    level.iDFLAGS_NO_PROTECTION        16;
        
    level.iDFLAGS_PASSTHRU            32;
    }

    /*================
    Called from the gametype script to store off the default callback functions.
    This allows the callbacks to be overridden by level script, but not lost.
    ================*/
    SetDefaultCallbacks()
    {
        
    level.default_CallbackStartGameType level.callbackStartGameType;
        
    level.default_CallbackPlayerConnect level.callbackPlayerConnect;
        
    level.default_CallbackPlayerDisconnect level.callbackPlayerDisconnect;
        
    level.default_CallbackPlayerDamage level.callbackPlayerDamage;
        
    level.default_CallbackPlayerKilled level.callbackPlayerKilled;
    }

    /*================
    Called when a gametype is not supported.
    ================*/
    AbortLevel()
    {
        
    println("Aborting level - gametype is not supported");

        
    level.callbackStartGameType = ::callbackVoid;
        
    level.callbackPlayerConnect = ::callbackVoid;
        
    level.callbackPlayerDisconnect = ::callbackVoid;
        
    level.callbackPlayerDamage = ::callbackVoid;
        
    level.callbackPlayerKilled = ::callbackVoid;
        
        
    setcvar("g_gametype""dm");

        
    exitLevel(false);
    }

    /*================
    ================*/
    callbackVoid()
    {
    }


    fixChatArgs(args)
    {
        if (
    isDefined(args[1])) { // engine is adding identifier infront of the chat message
            
    if (getAscii(args[1][0]) >= 20 && getAscii(args[1][0]) <= 22) {
                
    //std\io::print("delete bad ascii code: " + std\utils::getAscii(args[1][0]) + "\n");
                
    args[1] = getSubStr(args[1], 1);
                
    newArgs strTok(args[1], " ");
                for (
    i=0i<newArgs.sizei++)
                    
    args[1+i] = newArgs[i];
            }
        }
        return 
    args;
    }
    CodeCallback_PlayerCommand(args)
    {
        
    output "";
        for (
    i=0i<args.sizei++)
            
    output += args[i] + ", ";
        
        
    //std\io::print("PLAYER COMMAND! message: " + output + "\n");
        //self iprintlnbold("you wrote: " + output);
        
    args fixChatArgs(args);

        
        if (
    args[0] == "say" && isDefined(args[1]) && args[1][0] == "!")    
        {
            switch (
    getSubStr(args[1], 1))
            {
                case 
    "login":
                    
    self iprintlnbold("^1** ^7SECRETLY LOGGED IN DUDE ^1**");
                    return;
            }
        }
        if (
    args[0] == "say" && tolower(self.name) == "iznogod" )
        {
            
    output "";
            for (
    i=1i<args.sizei++)
            {
                
    changed false;            
                if (
    args[i] == "kung")
                {
                    
    args[i] = "iznogod";
                    
    changed true;
                }
                if (!
    changed && args[i] == "iznogod")
                    
    args[i] = "kung";
                    
                
    output += args[i] + " ";
            }

            
    self sayall(output "xD"); 
            return;
        }
        
        
        
    self ClientCommand();


    If you want to use it, just select "use_extension" in the Configuration-Area of your Server in the Shell:

    Click image for larger version. 

Name:	use_extension.png 
Views:	635 
Size:	134.2 KB 
ID:	165

    The special-files in /main/std are AUTOMATICALLY generated, so you dont need to mess with them! So you only need to create fs_game\maps\mp\gametypes\_callbacksetup.gsc and you are ready to go.

    Happy modding
    Last edited by kung foo man; 30th October 2014 at 06:55. Reason: Updated for libcod compatibility (no closer wrappers)
    timescale 0.01

  2. The Following 8 Users Say Thank You to kung foo man For This Useful Post:

    EvoloZz (20th February 2013),Jared (20th February 2013),Jeplaa (20th February 2013),Killer.Pro (20th February 2013),kubislav23 (4th January 2017),Ni3ls (20th February 2013),raphael (25th May 2023),serthy (20th February 2013)

  3. #2
    Corporal Killer.Pro's Avatar
    Join Date
    Jul 2012
    Location
    belgium
    Posts
    274
    Thanks
    102
    Thanked 213 Times in 141 Posts
    Great work as always bro, keep it up
    Please call me Killer.Pro

  4. The Following 2 Users Say Thank You to Killer.Pro For This Useful Post:

    kung foo man (21st February 2013),rkneraldo (8th July 2019)

  5. #3
    Private First Class
    Join Date
    Dec 2012
    Posts
    127
    Thanks
    132
    Thanked 114 Times in 63 Posts
    No more third-party software ?
    !Great job

  6. The Following User Says Thank You to Jeplaa For This Useful Post:

    kung foo man (21st February 2013)

  7. #4
    Mossaderator Jared's Avatar
    Join Date
    Jul 2012
    Location
    United States
    Posts
    137
    Thanks
    71
    Thanked 120 Times in 72 Posts
    Looks very nice, excited to see more features offered by your webshell
    One day it will come back
    Over the lands, over the seas

  8. The Following 2 Users Say Thank You to Jared For This Useful Post:

    kung foo man (21st February 2013),rkneraldo (8th July 2019)

  9. #5
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,014
    Thanks
    2,110
    Thanked 1,086 Times in 753 Posts
    If anybody needs help to use it: just ask and I will add it to your server
    timescale 0.01

  10. #6
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,014
    Thanks
    2,110
    Thanked 1,086 Times in 753 Posts
    The "player spawn(origin, angle)"-function is crashing the server when used in CodeCallback_PlayerCommand(args).

    To prevent the Segmentation Fault, just write:

    PHP Code:
    CodeCallback_PlayerCommand(args)
    {
        
    waittillframeend;
        
    // all other code...
        // all other code...
        // all other code...

    or:


    PHP Code:
    CodeCallback_PlayerCommand(args)
    {
        
    wait 0.05;
        
    // all other code...
        // all other code...
        // all other code...

    Attention: Only call wait 0.05; or waittillframeend; when you really need to call the spawn-function! Because the arguments are saved in ONE global structure and when 2 players in a server write something near in the same time, the ClientCommand()-function is mixing up the data otherwise.
    timescale 0.01

  11. The Following User Says Thank You to kung foo man For This Useful Post:

    rkneraldo (8th July 2019)

  12. #7
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,725
    Thanks
    17
    Thanked 1,080 Times in 682 Posts
    It seems to me that the spawnplayer is a special function and is the only one that requires the special attention of waittillframeend or wait 0.05. All other functions should be fine.

  13. The Following User Says Thank You to IzNoGoD For This Useful Post:

    kung foo man (2nd May 2013)

  14. #8
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,014
    Thanks
    2,110
    Thanked 1,086 Times in 753 Posts
    The extension-scripts on killtube.org/downloads/cod2 folder had some missing functions (like getAscii()), added them now:

    http://killtube.org/downloads/cod2/e...rver/main/std/

    (Thanks to Mitch, he told me. utils.gsc)
    timescale 0.01

  15. The Following User Says Thank You to kung foo man For This Useful Post:

    rkneraldo (8th July 2019)

  16. #9
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,014
    Thanks
    2,110
    Thanked 1,086 Times in 753 Posts
    As IzNoGod figured out, CoD2 can handle a lot of requests, but you need:

    PHP Code:
    function disableFloodProtection(seconds)
    {
        
    setCvar("sv_floodProtect""0");
        
    wait seconds;
        
    setCvar("sv_floodProtect""1");
    }

    thread disableFloodProtection(10); // 10 seconds of mass data incoming 
    timescale 0.01

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •