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)My first plugin!!!
Pages: [1]   Go Down
  Print  
Author Topic: My first plugin!!!  (Read 392 times) Bookmark and Share
Beta Testers
*
OS: Linux
Type: Owner dedicated server(s)
Gameservers: CoD4
Posts: 43
Offline Offline
WWW
« on: August 16, 2010, 09:42:31 AM »

Well, this is my plugin I made. It has cmd_map but, it is different then the normal map change command.

Code: python
__version__ = '1.0'
__author__  = 'FlashYorkHunt'

import b3, re
import b3.events
# Import the necessary libaries you need here, for example, I need random for the randomization of answers part of it.
import random
#--------------------------------------------------------------------------------------------------
#This lot doesn't need to be changed for simple commands, it gets the admin plugin and registers commands.
class FlashPlugin(b3.plugin.Plugin):
   _adminPlugin = None

   def startup(self):
     """\
     Initialize plugin settings
     """

  # get the admin 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
   
   # register our commands (you can ignore this bit)
     if 'commands' in self.config.sections():
       for cmd in self.config.options('commands'):
         level = self.config.get('commands', cmd)
         sp = cmd.split('-')
         alias = None
         if len(sp) == 2:
           cmd, alias = sp

         func = self.getCmd(cmd)
         if func:
           self._adminPlugin.registerCommand(self, cmd, level, func, alias)

     self.debug('Started')


   def getCmd(self, cmd):
     cmd = 'cmd_%s' % cmd
     if hasattr(self, cmd):
       func = getattr(self, cmd)
       return func

     return None
#--------------------------------------------------------------------
 def cmd_voice(self, data, client, cmd=None)
   """\
   Turns off voice chat
   !voice off
   """
   if not data:
     client.message('^7Missing data, type off or on behind the command')
     return False
   else:
     input = data.split(' ',1)
     if input[0] == 'off' :
         self.console.say('^2Voice chat has been turned ^1OFF')
         time.sleep(2)
         self.console.write('sv_voice 0')
         self.console.write('fast_restart')
         return True
     if input[0] == 'on' :
         self.console.say('^2Voice chat has been turned ^1ON')
         time.sleep(2)
         self.console.write('sv_voice 1')
         self.console.write('fast_restart')
         return True
       client.message('^7Invalid data, type off or on')
   return True
#---------------------------------------------
 def cmd_map(self, data, client, cmd=None)
   """\
   Changes the map
   !map broadcast
   """
   if not data:
     client.message('^7Missing data, type the map name after !map')
     return False
   else:
     input = data.split(' ',1)
     map = input[0]
     input[0] = 'mp_%s'% input[0]
         self.console.say('^2Map will be changed to ^2%s,'% map)
         self.console.write('map %s'% input[0])
        return True
     client.message('^7Invalid data, type the map name')
   return True
#---------------------------------------------
 def cmd_servername(self, data, client, cmd=None)
   """\
   !servername ^1Hardcore ^3Team ^2Deathmatch
   """
   if not data:
     client.message('^7Missing data, type the server name after !servername')
     return False
   else:
     input = data.split(' ',1)
     servername = input[0]
     input[0] = '^0+++'% input[0]
         self.console.say('^7Server name changed to %s,'% servername)
         self.console.write('set sv_hostname %s'% input[0])
         return True
     client.message('^7Invalid data, type the server name')
   return True
#---------------------------------------------
 def cmd_axistname(self, data, client, cmd=None)
   """\
   Changes the axis's teamname
   !axistname ^6Rank's bitches
   """
   if not data:
     client.message('Missing data, type a name for the Axis team after the command')
     return False
   else:
     input = data.split(' ',1)
     axisname = input[0]
     input[0] = '^7'% input[0]
         self.console.say('^7Axis team name changed to %s, '% axisname)
         time.sleep(2)
         self.console.write('set g_TeamName_Axis %s,'% axisname)
         return True
     client.message('^7Invalid data, type off or on')
   return True
#---------------------------------------------
 def cmd_alliestname(self, data, client, cmd=None)
   """\
   Changes the aallies's teamname
   !alliestname ^6Rank's bitches
   """
   if not data:
     client.message('Missing data, type a name for the Axis team after the command')
     return False
   else:
     input = data.split(' ',1)
     alliesname = input[0]
     input[0] = '^7'% input[0]
         self.console.say('^7Allies team name changed to %s, '% alliesname)
         time.sleep(2)
         self.console.write('set g_TeamName_Allies %s,'% alliesname)
         return True
     client.message('^7Invalid data, type off or on')
   return True
#---------------------------------------------
 def cmd_beasian(self, data, client, cmd=None)
   """\
Makes you be asian
!beasian gum
"""
       m = self.parseUserCmd(data)  
       if not m:  
           client.message('^7Invalid parameters, you must supply a player name')  
           return False  
 
       if m[0] == 'RankFaster':  
           self.warnClient(client, 'He will never be asian!!', None, False, '', 1)  
       else:  
           sclient = self.findClientPrompt(m[0], client)  
           if sclient:  
               self.console.say('^7%s %s^7!' % (random.choice(('is now a ^2fish-smelling^7 asian!', 'now has a larger peripheral vision thanks to his ^2Asian-ness^7!', 'is almost as ^2Asian^7 as ^2[MN]Gum^7!', 'must now go back to ^3Communist ^1China^7!', 'now has a ^2dick^7 smaller then ^2defender_18^7')), sclient.exactName))
#---------------------------------------------
 def cmd_bitchslap(self, data, client, cmd=None)
   """\
can bitch slap another
!bitchslap Rank
"""
    m = self.parseUserCMD(data)
if not m:
    client.message('^7Try ^2!bitchslap playernamehere^7 and see if the command works then')
return False
if m[0] == 'RankFaster'
    self.warnClient(client, 'Back off BIATCH, I am God!!', None, False, '', 1)
   else:
   sclient = self.findClientPrompt(m[0], client)
if sclient:
   self.console.say('^2%s^7 just got BITCH SLAPPED in the back of the head by ^2%s^7!^2!^7') % (sclient.exactName, client.name))

#---------------------------------------------
 def cmd_cuntpunt(self, data, client, cmd=None)
   """\
Cuntpunt another player
"""
    m = self.parseUserCMD(data)
if not m:
    client.message('^7Try !cuntpunt playernamehere')
return False
   if m[0] == 'RankFaster'
    self.warnClient(client, 'Rank doesn\'t have a cunt to be punted. Fail on your part.', None, False, '', 1)
   else:
   sclient = self.findClientPrompt(m[0], client)
if sclient:
   self.console.say('^2%s^7 just got their dirty, hairy, cunt punted by ^2%s^7!^2!') % (sclient.exactName, client.name))

How does it look? If someone could, please look over the whole thing and tell me if there are any mistakes.
« Last Edit: August 16, 2010, 09:44:57 AM by FlashYorkHunt » 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: August 16, 2010, 10:26:30 AM »

Hi, it looks alright but I cannot test it as I don't run any cod server.

You should consider packaging this in a zip file :
Code:
b3-plugin-flash.zip
  \
   +-- extplugins\
   |      \
   |       +-- flash.py
   |       |
   |       +-- conf\
   |              \
   |               +-- plugin_flash.xml
   |
   +-- readme.txt
This will make it easier for people to install
Logged

Beta Testers
*
OS: Linux
Type: Owner dedicated server(s)
Gameservers: CoD4
Posts: 43
Offline Offline
WWW
« Reply #2 on: August 16, 2010, 10:29:06 AM »

Thanks Cheesy
Yeah, I will be doing that after I add some more commands. I will adding more of the random ones like, bitch slap, cuntpunt, and other things.
Logged


Tags:
Pages: [1]   Go Up
  Print  
 
Jump to:  


Rate this page +1 at Google Search


SimplePortal 2.3.1 © 2008-2009, SimplePortal