Most of the plugins here are made by B3 users and the authors may not visit frequently. If you need support for plugins or if questions remain unanswered, you will have to contact the author directly. Read the full Support Disclaimer here
NOTE: Do not attach plugins to your forumtopics! Attachements are periodically removed by maintenance tasks. Upload your plugins to our Downloads section instead!

You are here: Big Brother Bot ForumAdd-OnsPlugins Discussion (Moderator: MordyT)Skill plugin request
Pages: [1]   Go Down
  Print  
Author Topic: Skill plugin request  (Read 676 times) Bookmark and Share
Jr. Member
**
Posts: 12
Offline Offline
« on: March 14, 2011, 10:29:12 PM »

This would be for Urban Terror. What I'm looking for is a plugin to kick a player after they have been killed 8-10 times without a kill. This would be good to keep only good players on. It will also weed out afks. I tried to modify the spree plugin with something like self.console.write('kick "%s"' % (client.exactName)). I know little about python so I don't really know where to start to do this. It basically just needs to track deaths and kick after going 0-8. Thanks for any help. -DEFeKt
Logged

Senior Dev.
*
OS: Linux
Type: Home user
Posts: 3484
Offline Offline
WWW
Support Specialty: B3-Core, UrT/SmG/BFBC2 parsers, Plugin development
« Reply #1 on: March 15, 2011, 01:30:53 AM »

Hi, I took a quick look at the spree plugin. Here's what I would try to do :

Search for :
Code: python
        if victim:
           spreeStats = self.get_spree_stats(victim)
           spreeStats.deaths += 1

Replace with :
Code: python
        if victim:
           spreeStats = self.get_spree_stats(victim)
           spreeStats.deaths += 1
           
           # check if the victim is dead 8 times without making a kill
           if speeStats.deaths >= 8:
               victim.kick("You were kill too many times")
               self.console.write("%s was kicked because of skill failure" % victim.name)

Disclaimer : this code is untested and might need a few modifications to work
« Last Edit: March 15, 2011, 02:07:48 AM by Courgette » Logged

Jr. Member
**
Posts: 12
Offline Offline
« Reply #2 on: March 15, 2011, 06:55:59 PM »

Hi, I took a quick look at the spree plugin. Here's what I would try to do :



Replace with :
Code: python
        if victim:
           spreeStats = self.get_spree_stats(victim)
           spreeStats.deaths += 1
           
           # check if the victim is dead 8 times without making a kill
           if speeStats.deaths >= 8:
               victim.kick("You were kill too many times")
               self.console.write("%s was kicked because of skill failure" % victim.name)

Disclaimer : this code is untested and might need a few modifications to work

I tried it so far no good. Is this part doing the kicking? victim.kick("You were killed too many times")
I also tried
 self.console.write('kick "%s" was kicked because of skill failure' % victim.name)
 Thanks for the fast reply.
Logged
Senior Dev.
*
OS: Linux
Type: Home user
Posts: 3484
Offline Offline
WWW
Support Specialty: B3-Core, UrT/SmG/BFBC2 parsers, Plugin development
« Reply #3 on: March 16, 2011, 01:29:03 AM »

I found a typo, try instead ('r' missing in 'speeStats') :

Code: python
        if victim:
           spreeStats = self.get_spree_stats(victim)
           spreeStats.deaths += 1
           
           # check if the victim is dead 8 times without making a kill
           if spreeStats.deaths >= 8:
               victim.kick("You were kill too many times")
               self.console.write("%s was kicked because of skill failure" % victim.name)

Is this part doing the kicking? victim.kick("You were killed too many times")
yes it is. It tells B3 to kick victim with reason "You were kill too many times"
Logged

Jr. Member
**
Posts: 12
Offline Offline
« Reply #4 on: March 16, 2011, 06:20:07 AM »

I found a typo, try instead ('r' missing in 'speeStats') :

Code: python
        if victim:
           spreeStats = self.get_spree_stats(victim)
           spreeStats.deaths += 1
           
           # check if the victim is dead 8 times without making a kill
           if spreeStats.deaths >= 8:
               victim.kick("You were kill too many times")
               self.console.write("%s was kicked because of skill failure" % victim.name)
yes it is. It tells B3 to kick victim with reason "You were kill too many times"
That was actually the first thing i fixed before pasting into the file. Its not giving any errors but it also is not kicking. I will mess with it more tonight. Thanks again
Logged
Senior Dev.
*
OS: Linux
Type: Home user
Posts: 3484
Offline Offline
WWW
Support Specialty: B3-Core, UrT/SmG/BFBC2 parsers, Plugin development
« Reply #5 on: March 16, 2011, 06:37:28 AM »

make sure to post your b3.log showing your tests
Logged

Jr. Member
**
Posts: 12
Offline Offline
« Reply #6 on: March 16, 2011, 08:29:57 PM »

make sure to post your b3.log showing your tests
I was wrong. there are errors
Quote
SyntaxError: Non-ASCII character '\xc2' in file C:\UserFiles\user\GameServers\etcetc\b3\extplugins\noob.py on line 146, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details (noob.py, line 146

That line is self.console.write("%s was kicked because of skill failure" % victim.name) 
Logged
XLRstats dev.
Dev. Team
*
OS: Linux
Type: Home user
Gameservers: COD5, COD7, BF3
Posts: 947
Offline Offline
WWW
Support Specialty: XLRstats webfront
« Reply #7 on: March 17, 2011, 01:08:07 AM »

Please attach full b3.log together with noob.py so we can have a better idea.
Logged

Jr. Member
**
Posts: 12
Offline Offline
« Reply #8 on: March 17, 2011, 08:44:59 PM »

Code:
I attached the log file.
[code# b3/plugins/spree.py
#
# This plugin will show killing or loosing spree messages.
#
# It's written with fun, for fun. Please report any errors or
# if something can be done more efficient to Walker@1stsop.nl
#
# 08-03-2005, Walker: Changed the end spree messages a bit.
# 08-01-2005, ThorN:  Code change suggestions
# 08-01-2005, Walker: Initial creation
#
# all plugins must import b3 and b3.events
import b3
import b3.events

class SpreeStats:
    kills                  = 0
    deaths                 = 0
    endLoosingSpreeMessage = None
    endKillSpreeMessage    = None
   
#--------------------------------------------------------------------------------------------------
class NoobPlugin(b3.plugin.Plugin):
    _adminPlugin = None
    _killingspree_messages_dict = {}
    _loosingspree_messages_dict = {}
    _reset_spree_stats = 0
    _min_level_spree_cmd = 0
    _clientvar_name = 'spree_info'
   
    def startup(self):
        """\
        Initialize plugin settings
        """

        self.debug('Starting')
        # get the plugin so we can register commands
        self._adminPlugin = self.console.getPlugin('admin')
        if not self._adminPlugin:
            # something is wrong, can't start without admin plugin
            self.error('Could not find admin plugin')
            return False

        # Get the settings from the config.
        if self.config.get('settings', 'reset_spree') == '1':
            self._reset_spree_stats = 1
        self._min_level_spree_cmd = self.config.getint('settings', 'min_level_spree_cmd')
       
        # register our !spree command
        self.verbose('Registering commands')
        self._adminPlugin.registerCommand(self, 'spree', self._min_level_spree_cmd, self.cmd_spree)

        # listen for client events
        self.verbose('Registering events')
        self.registerEvent(b3.events.EVT_CLIENT_KILL)
        self.registerEvent(b3.events.EVT_GAME_EXIT)

        # Initialize the message list used in this plugin
        self.init_spreemessage_list()

        self.debug('Started')

    def onLoadConfig(self):
        self.init_spreemessage_list()

    def handle(self, event):
        """\
        Handle intercepted events
        """
        if event.type == b3.events.EVT_CLIENT_KILL:
             self.handle_kills(event.client, event.target)
        elif event.type == b3.events.EVT_GAME_EXIT:
             if self._reset_spree_stats:
                for c in self.console.clients.getList():
                   self.init_spree_stats(c)
             
    def init_spreemessage_list(self):
        # Get the spree messages from the config
        # Split the start and end spree messages and save it in the dictionary
        for kills, message  in self.config.items('killingspree_messages'):
            # force the kills to an integer
            self._killingspree_messages_dict[int(kills)]  = message.split('#')
       
        for deaths, message in self.config.items('loosingspree_messages'):
            self._loosingspree_messages_dict[int(deaths)] = message.split('#')

        self.verbose('spree-messages are loaded in memory')

    def init_spree_stats(self, client):
        # initialize the clients spree stats
        client.setvar(self, self._clientvar_name, SpreeStats())
   
    def get_spree_stats(self, client):
        # get the clients stats
        # pass the plugin reference first
        # the key second
        # the defualt value first
       
        if not client.isvar(self, self._clientvar_name):
            # initialize the default spree object
            # we don't just use the client.var(...,default) here so we
            # don't create a new SpreeStats object for no reason every call
            client.setvar(self, self._clientvar_name, SpreeStats())
           
        return client.var(self, self._clientvar_name).value
   
    def handle_kills(self, client=None, victim=None):
        """\
        A kill was made. Add 1 to the client and set his deaths to 0.
        Add 1 death to the victim and set his kills to 0.
        """

        # client (attacker)
        if client:
            # we grab our SpreeStats object here
            # any changes to its values will be saved "automagically"
            spreeStats = self.get_spree_stats(client)
            spreeStats.kills += 1
           
            # Check if the client was on a loosing spree. If so then show his end loosing spree msg.
            if spreeStats.endLoosingSpreeMessage:
                self.show_message( client, victim, spreeStats.endLoosingSpreeMessage )
                # reset any possible loosing spree to None
                spreeStats.endLoosingSpreeMessage = None
            # Check if the client is on a killing spree. If so then show it.
            message = self.get_spree_message(spreeStats.kills, 0)
            if message:
                #Save the 'end'spree message in the client. That is used when the spree ends.
                spreeStats.endKillSpreeMessage = message[1]


                #Show the 'start'spree message
                self.show_message( client, victim, message[0] )

            # deaths spree is over, reset deaths
            spreeStats.deaths = 0

        # Victim
        if victim:
            spreeStats = self.get_spree_stats(victim)
            spreeStats.deaths += 1
             
            # check if the victim is dead 8 times without making a kill 
            if spreeStats.deaths >= 8: 
               victim.kick("You are a big naab or afk") 
               self.console.write("%s was kicked because of skill failure" % victim.name) 
           
            # Check if the victim had a killing spree and show a end_killing_spree message
            if spreeStats.endKillSpreeMessage:
                self.show_message( client, victim, spreeStats.endKillSpreeMessage )
                # reset any possible end spree to None
                spreeStats.endKillSpreeMessage = None

            #Check if the victim is on a 'loosing'spree
            message = self.get_spree_message(0, spreeStats.deaths)
            if message:
                #Save the 'loosing'spree message in the client.
                spreeStats.endLoosingSpreeMessage = message[1]
               
                self.show_message( victim, client, message[0] )
               
            # kill spree is over, reset kills
            spreeStats.kills = 0

    def get_spree_message(self, kills, deaths):
        """\
        Get the appropriate spree message.
        Return a list in the format (start spree message, end spree message)
        """
       
        # default is None, there is no message
        message = None
       
        # killing spree check
        if kills != 0:
            # if there is an entry for this number of kills, grab it, otherwise
            # return None
            message = self._killingspree_messages_dict.get(kills, None)
       
        # loosing spree check
        elif deaths != 0:
            message = self._loosingspree_messages_dict.get(deaths, None)
           
        return message

    def show_message(self, client, victim=None, message=None):
        """\
        Replace variables and display the message
        """
        if (message != None) and not (client.hide):
            message = message.replace('%player%',client.name)
            if victim:
                message = message.replace('%victim%',victim.name)
            self.console.write('bigtext "%s"' % (message))       
   
   
    def cmd_noob(self, data, client, cmd=None):
        """\
        Show a players winning/loosing spree
        """       
        spreeStats = self.get_spree_stats(client)

        if spreeStats.kills > 0:
            cmd.sayLoudOrPM(client, '^7You have ^2%s^7 kills in a row' % spreeStats.kills)
        elif spreeStats.deaths > 0:
            cmd.sayLoudOrPM(client, '^7You have ^1%s^7 deaths in a row' % spreeStats.deaths)
        else:
            cmd.sayLoudOrPM(client, '^7You\'re not having a spree right now')]




[attachment deleted by maintenance]
Logged
XLRstats dev.
Dev. Team
*
OS: Linux
Type: Home user
Gameservers: COD5, COD7, BF3
Posts: 947
Offline Offline
WWW
Support Specialty: XLRstats webfront
« Reply #9 on: March 18, 2011, 12:03:03 AM »

I'm not very sure but I'd try this. First of all I recommend you to use an editor like Notepad++.

Go to the line that error points to and check if you have any white spaces at the end of line. If yes, clean them and try to run the bot again.

After you run the but if the error message is pointing to another line, check that line too the same way and so on.
Logged

Jr. Member
**
Posts: 12
Offline Offline
« Reply #10 on: March 18, 2011, 07:36:32 AM »

im using gedit for the editor. I will check for any spaces. Thanks
Logged
Jr. Member
**
Posts: 12
Offline Offline
« Reply #11 on: March 18, 2011, 08:46:19 AM »

It was an indentation problem. It works now. Thanks for the help.
I called it noobfilter.py
I changed cmd_spree to cmd_noob spree to nb so now !nb tells deaths/kill streak 

Code:
# b3/plugins/noobfilter.py
#
#
#
# It's written with fun, for fun. Please report any errors or
# if something can be done more efficient to Walker@1stsop.nl
#
# 08-03-2005, Walker: Changed the end spree messages a bit.
# 08-01-2005, ThorN:  Code change suggestions
# 08-01-2005, Walker: Initial creation
#Modified by DEFeKt with code and help from Courgette and Freelander
#Kicks after 8 deaths. May be useful to weed out afks and no0bs
# all plugins must import b3 and b3.events
import b3
import b3.events

class SpreeStats:
    kills                  = 0
    deaths                 = 0
    endLoosingSpreeMessage = None
    endKillSpreeMessage    = None
    
#--------------------------------------------------------------------------------------------------
class NoobfilterPlugin(b3.plugin.Plugin):
    _adminPlugin = None
    _killingspree_messages_dict = {}
    _loosingspree_messages_dict = {}
    _reset_spree_stats = 0
    _min_level_spree_cmd = 0
    _clientvar_name = 'spree_info'
    
    def startup(self):
        """\
        Initialize plugin settings
        """

        self.debug('Starting')
        # get the plugin so we can register commands
        self._adminPlugin = self.console.getPlugin('admin')
        if not self._adminPlugin:
            # something is wrong, can't start without admin plugin
            self.error('Could not find admin plugin')
            return False

        # Get the settings from the config.
        if self.config.get('settings', 'reset_spree') == '1':
            self._reset_spree_stats = 1
        self._min_level_spree_cmd = self.config.getint('settings', 'min_level_spree_cmd')
        
        # register our !spree command
        self.verbose('Registering commands')
        self._adminPlugin.registerCommand(self, 'nb', self._min_level_spree_cmd, self.cmd_noob)

        # listen for client events
        self.verbose('Registering events')
        self.registerEvent(b3.events.EVT_CLIENT_KILL)
        self.registerEvent(b3.events.EVT_GAME_EXIT)

        # Initialize the message list used in this plugin
        self.init_spreemessage_list()

        self.debug('Started')

    def onLoadConfig(self):
        self.init_spreemessage_list()

    def handle(self, event):
        """\
        Handle intercepted events
        """
        if event.type == b3.events.EVT_CLIENT_KILL:
             self.handle_kills(event.client, event.target)
        elif event.type == b3.events.EVT_GAME_EXIT:
             if self._reset_spree_stats:
                for c in self.console.clients.getList():
                   self.init_spree_stats(c)
              
    def init_spreemessage_list(self):
        # Get the spree messages from the config
        # Split the start and end spree messages and save it in the dictionary
        for kills, message  in self.config.items('killingspree_messages'):
            # force the kills to an integer
            self._killingspree_messages_dict[int(kills)]  = message.split('#')
        
        for deaths, message in self.config.items('loosingspree_messages'):
            self._loosingspree_messages_dict[int(deaths)] = message.split('#')

        self.verbose('spree-messages are loaded in memory')

    def init_spree_stats(self, client):
        # initialize the clients spree stats
        client.setvar(self, self._clientvar_name, SpreeStats())
    
    def get_spree_stats(self, client):
        # get the clients stats
        # pass the plugin reference first
        # the key second
        # the defualt value first
        
        if not client.isvar(self, self._clientvar_name):
            # initialize the default spree object
            # we don't just use the client.var(...,default) here so we
            # don't create a new SpreeStats object for no reason every call
            client.setvar(self, self._clientvar_name, SpreeStats())
            
        return client.var(self, self._clientvar_name).value
    
    def handle_kills(self, client=None, victim=None):
        """\
        A kill was made. Add 1 to the client and set his deaths to 0.
        Add 1 death to the victim and set his kills to 0.
        """

        # client (attacker)
        if client:
            # we grab our SpreeStats object here
            # any changes to its values will be saved "automagically"
            spreeStats = self.get_spree_stats(client)
            spreeStats.kills += 1
            
            # Check if the client was on a loosing spree. If so then show his end loosing spree msg.
            if spreeStats.endLoosingSpreeMessage:
                self.show_message( client, victim, spreeStats.endLoosingSpreeMessage )
                # reset any possible loosing spree to None
                spreeStats.endLoosingSpreeMessage = None
            # Check if the client is on a killing spree. If so then show it.
            message = self.get_spree_message(spreeStats.kills, 0)
            if message:
                #Save the 'end'spree message in the client. That is used when the spree ends.
                spreeStats.endKillSpreeMessage = message[1]


                #Show the 'start'spree message
                self.show_message( client, victim, message[0] )

            # deaths spree is over, reset deaths
            spreeStats.deaths = 0

        # Victim
        if victim:
            spreeStats = self.get_spree_stats(victim)
            spreeStats.deaths += 1
            
            # check if the victim is dead 8 times without making a kill  
            if spreeStats.deaths >= 8:  
                victim.kick("You are either a big naab or afk")  
                self.console.write("%s was kicked ^5[^78 deaths without a kill^5]" % victim.name)
            
            # Check if the victim had a killing spree and show a end_killing_spree message
            if spreeStats.endKillSpreeMessage:
                self.show_message( client, victim, spreeStats.endKillSpreeMessage )
                # reset any possible end spree to None
                spreeStats.endKillSpreeMessage = None

            #Check if the victim is on a 'loosing'spree
            message = self.get_spree_message(0, spreeStats.deaths)
            if message:
                #Save the 'loosing'spree message in the client.
                spreeStats.endLoosingSpreeMessage = message[1]
                
                self.show_message( victim, client, message[0] )
                
            # kill spree is over, reset kills
            spreeStats.kills = 0

    def get_spree_message(self, kills, deaths):
        """\
        Get the appropriate spree message.
        Return a list in the format (start spree message, end spree message)
        """
        
        # default is None, there is no message
        message = None
        
        # killing spree check
        if kills != 0:
            # if there is an entry for this number of kills, grab it, otherwise
            # return None
            message = self._killingspree_messages_dict.get(kills, None)
        
        # loosing spree check
        elif deaths != 0:
            message = self._loosingspree_messages_dict.get(deaths, None)
            
        return message

    def show_message(self, client, victim=None, message=None):
        """\
        Replace variables and display the message
        """
        if (message != None) and not (client.hide):
            message = message.replace('%player%',client.name)
            if victim:
                message = message.replace('%victim%',victim.name)
            self.console.write('bigtext "%s"' % (message))        
    
    
    def cmd_noob(self, data, client, cmd=None):
        """\
        Show a players winning/loosing spree
        """        
        spreeStats = self.get_spree_stats(client)

        if spreeStats.kills > 0:
            cmd.sayLoudOrPM(client, '^7You have ^2%s^7 kills in a row' % spreeStats.kills)
        elif spreeStats.deaths > 0:
            cmd.sayLoudOrPM(client, '^7You have ^1%s^7 deaths in a row' % spreeStats.deaths)
        else:
            cmd.sayLoudOrPM(client, '^7You\'re not having a spree right now')
« Last Edit: March 18, 2011, 11:04:52 AM by DEFeKt » Logged
Tags: noobs afk 
Pages: [1]   Go Up
  Print  
 
Jump to:  


Rate this page +1 at Google Search


SimplePortal 2.3.1 © 2008-2009, SimplePortal