Results 1 to 1 of 1

Thread: [advanced] Ignoring text said by certain players

  1. #1
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts

    [advanced] Ignoring text said by certain players

    Here's my example code for ignoring text set by certain players by some players(like mute on voicechat). It will allow player A to ignore player B, while player B can still communicate with all others on server, and A can still message B (only impossible option then is B->A)
    (its JH-specific code, but you might be able to port it to other mods if you want to)
    PHP Code:
    #include JH\_util;
    playerinit()
    {
        if(
    self.izno["first_run"])
        {
            
    self.izno["ignorelist"] = [];
            
    args = [];
            
    args[0] = self;
            
    add_async_query("SELECT ignore_id FROM ignorelist WHERE player_id = " self.izno["player_id"], ::createlistargs);
            
    add_async_query("SELECT player_id FROM ignorelist WHERE ignore_id = " self.izno["player_id"], ::createlist_otherargs);
        }
    }

    addignore(playerforever)
    {
        
    found false;
        for(
    0self.izno["ignorelist"].sizei++)
        {
            if(
    self.izno["ignorelist"][i] == player.izno["player_id"])
            {
                
    found true;
                break;
            }
        }
        if(!
    found)
            
    self.izno["ignorelist"][self.izno["ignorelist"].size] = player.izno["player_id"];
        if(
    forever)
        {
            
    add_async_query_nosave("INSERT IGNORE INTO ignorelist (player_id, ignore_id) VALUES (" self.izno["player_id"] + ", " player.izno["player_id"] + ")");
            
    self iprintln("You are persistently ignoring " player.name);
        }
        else
            
    self iprintln("You are now ignoring " player.name);
    }

    unignore(playerforever)
    {
        
    found false;
        for(
    0self.izno["ignorelist"].sizei++)
        {
            if(
    self.izno["ignorelist"][i] == player.izno["player_id"])
            {
                
    found true;
                
    self.izno["ignorelist"][i] = self.izno["ignorelist"][self.izno["ignorelist"].size 1];
                
    self.izno["ignorelist"][self.izno["ignorelist"].size 1] = undefined;
                break;
            }
        }
        if(!
    found)
        {
            
    self iprintln("You were not ignoring " player.name);
        }
        if(
    forever)
        {
            
    add_async_query_nosave("DELETE FROM ignorelist WHERE player_id = " self.izno["player_id"] + " AND ignore_id = " player.izno["player_id"]);
            
    self iprintln("You gave up ignoring " player.name "^7 forever");
        }
        else
            
    self iprintln("You gave up ignoring " player.name);
    }

    createlist_other(resultargs)
    {
        
    player args[0];
        if(!
    isdefined(player))
        {
            if(
    isdefined(result))
                
    mysql_free_result(result);
            return;
        }

        if(
    isdefined(result))
        {
            
    players getentarray("player""classname");
            
    rowcount mysql_num_rows(result);
            for(
    0rowcounti++)
            {
                
    row mysql_fetch_row(result);
                if(
    isdefined(row[0]))
                {
                    for(
    0players.sizej++)
                    {
                        if(
    isdefined(players[j].izno["login_completed"]))
                        {
                            if(
    players[j].izno["player_id"] == int(row[0]))
                            {
                                
    //this players[j] is ignoring player
                                
    players[j].izno["ignorelist"][players[j].izno["ignorelist"].size] = player.izno["player_id"];
                                break;
                            }
                        }
                    }
                }
            }
            
    mysql_free_result(result);
        }
    }

    createlist(resultargs)
    {
        
    player args[0];
        if(!
    isdefined(player))
        {
            if(
    isdefined(result))
                
    mysql_free_result(result);
            return;
        }
        if(
    isdefined(result))
        {
            
    players getentarray("player""classname");
            
    rowcount mysql_num_rows(result);
            for(
    0rowcounti++)
            {
                
    row mysql_fetch_row(result);
                if(
    isdefined(row[0]))
                {
                    for(
    0players.sizej++)
                    {
                        if(
    isdefined(players[j].izno["login_completed"]))
                        {
                            if(
    players[j].izno["player_id"] == int(row[0]))
                            {
                                
    //this player is ignoring players[j]
                                
    player.izno["ignorelist"][player.izno["ignorelist"].size] = players[j].izno["player_id"];
                                break;
                            }
                        }
                    }
                }
            }
            
    mysql_free_result(result);
        }

    above is the _ignore.gsc, which is mainly the list creating script (also it can save to a mysql database if you want to persistently ignore a player)
    PHP Code:
            else if(args[0] == "say")
            {
                
    txt args[1];
                for(
    2args.sizei++)
                    
    txt += " " args[i];
                
    players getentarray("player""classname");
                for(
    0players.sizei++)
                {
                    
    ignore false;
                    if(
    isdefined(players[i].izno["login_completed"]))
                    {
                        for(
    0players[i].izno["ignorelist"].sizej++)
                        {
                            if(
    players[i].izno["ignorelist"][j] == self.izno["player_id"])
                            {
                                
    ignore true;
                                break;
                            }
                        }
                    }
                    if(!
    ignore)
                        
    sendgameservercommand(players[igetentitynumber(), "h "" self.name "^7: " txt """);
                }
                return;
            } 
    Above is a snippet in callback_playercommand which handles incoming commands like chatting. As of now it does lack printing to the server console which makes it quite hard to follow any conversation using the serverconsole.

    PHP Code:

    init_async_mysql
    ()
    {
        
    host getcvar("mysql_host");
        
    user getcvar("mysql_user");
        
    port getcvarint("mysql_port");
        
    pass getcvar("mysql_password");
        
    db getcvar("mysql_database");
        
    mysql_async_initializer(hostuserpassdbport4);
        
    level.mysql_async = [];
        while(
    true)
        {
            list = 
    mysql_async_getdone_list();
            for(
    0< list.sizei++)
            {
                
    result mysql_async_getresult_and_free(list[i]);
                if(!
    isdefined(result))
                    continue;
                if(
    result == 0)
                    
    result undefined;
                
    level.mysql_async["" + list[i]];
                if(
    isdefined(f))
                {
                    if(
    isdefined(f.function))
                        
    thread [[f.function]](resultf.args);
                    else if(
    isdefined(result))
                        
    mysql_free_result(result);
                    
    undefined;
                }
                
    level.mysql_async["" + list[i]] = undefined;
            }
            
    wait .05;
        }
    }

    add_async_query_nosave(q, function, args)
    {
        if(
    getcvarint("show_mysql") == 1)
            
    printf("mysql_query async nosave:" "\n");
        
    id mysql_async_create_query_nosave(q);
        
    spawnstruct();
        
    f.query q;
        
    f.function = function;
        
    f.args args;
        
    level.mysql_async["" id] = f;
    }

    add_async_query(q, function, args)
    {
        if(
    getcvarint("show_mysql") == 1)
            
    printf("mysql_query async:" "\n");
        
    id mysql_async_create_query(q);
        
    spawnstruct();
        
    f.query q;
        
    f.function = function;
        
    f.args args;
        
    level.mysql_async["" id] = f;

    And finally the util file, which does not do much more than handle the mysql stuffs


    This code is still in testmode but it seems to work pretty nicely

    Edit: almost forgot: This is all possible thanks to Mitch his sendgameservercommand libcod function
    Last edited by IzNoGoD; 20th December 2014 at 21:57.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

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

    kung foo man (20th December 2014)

Posting Permissions

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