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)Random client select
Pages: [1] 2   Go Down
  Print  
Author Topic: Random client select  (Read 768 times) Bookmark and Share
Jr. Member
**
OS: Windows
Type: Renting Server with B3
Gameservers: CoD4
Posts: 24
Offline Offline
« on: November 29, 2011, 08:47:22 PM »

what would be the thing for random client.cid select? i have a random int selection but it can't auth when players are in the game or out of the the game... if you could get me how to auth a cid then that would be cool too:)
Logged

Jr. Member
**
OS: Windows
Type: Renting Server with B3
Gameservers: CoD4
Posts: 24
Offline Offline
« Reply #1 on: December 02, 2011, 10:50:49 PM »

Come on i need some help:/
Logged
Jr. Member
**
OS: Windows
Type: Renting Server with B3
Gameservers: CoD4
Posts: 24
Offline Offline
« Reply #2 on: December 03, 2011, 10:31:57 PM »

Code: python
    def cmd_gift(self, data, client, cmd=None):
       """\
       Gives a random player a gift
       """
       guy = random.randint(0, 20)
       client.message('RANDOM CLIENT')
       if guy == client.cid:
           client.message('GUY DOES EQUAL')
           if event.client.state == b3.STATE_ALIVE:
               client.message('IS ALIVE')
               gunList = ['punish give::' + guy + '::deserteagle', 'punish give::' + guy + '::deserteaglegold', 'punish give::' + guy + '::G3', 'punish give::' + guy + '::G36', 'punish give::' + guy + '::M4', 'punish give::' + guy + '::M16', 'punish give::' + guy + '::m40a3', 'punish give::' + guy + '::usp', 'punish give::' + guy + '::ak47', 'punish give::' + guy + '::mp5', 'punish give::' + guy + '::p90', 'punish give::' + guy + '::uzi', 'punish give::' + guy + '::remington700', 'punish give::' + guy + '::M60E4_reflex']
               giftList = ['punish give::' + guy + '::deserteagle', random.choice(gunList)]
               client.message('LISTS DEFINED')
               self.console.write('%s' % (random.choice(giftList)))
               client.message('COMMAND DONE')
               self.console.say('^4Merry ^1Christmas ^7%s' % (client.exactName))
           else:
               client.message('GUY DOES ELSE')
               self.cmd_gift
       else:
           client.message('ELSE ELSE')
           self.cmd_gift

so there is my command if i can't do the random client ill make it select a random number and keep rerunning the script... but based off the debugging i have atm which is the client.message's all it does it says is ELSE ELSE... so, is there something wrong with "if guy == client.cid:"?
« Last Edit: December 03, 2011, 10:36:10 PM by Courgette » 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: December 03, 2011, 10:38:15 PM »

depending on the game client.cid may be a string representation of a number.

Give a try to
Code: python
if str(guy) == client.cid:
Logged

Jr. Member
**
OS: Windows
Type: Renting Server with B3
Gameservers: CoD4
Posts: 24
Offline Offline
« Reply #4 on: December 03, 2011, 11:05:56 PM »

that worked for the guy = client.cid and the cmd will not run over and over as i wanted before. and after it does select the client when it does select a real client it gives me a error:/ so there is something wrong with "if event.client.state == b3.STATE_ALIVE:"
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: December 03, 2011, 11:12:01 PM »

what error ? Please make it easy for us to help you by providing details
Logged

Jr. Member
**
OS: Windows
Type: Renting Server with B3
Gameservers: CoD4
Posts: 24
Offline Offline
« Reply #6 on: December 03, 2011, 11:17:15 PM »

Quote
111204 01:15:57   ERROR   "handler AdminPlugin could not handle event Say: NameError: global name 'event' is not defined [('b3\\\\parser.pyo', 973, 'handleEvents', None), ('b3\\\\plugin.pyo', 158, 'parseEvent', None), ('b3\\\\plugin.pyo', 176, 'onEvent', None), ('b3\\\\plugins\\\\admin.pyo', 223, 'handle', None), ('b3\\\\plugins\\\\admin.pyo', 368, 'OnSay', None), ('b3\\\\plugins\\\\admin.pyo', 2002, 'execute', None), ('D:\\\\UserFiles\\\\calibre\\\\GameServers\\\\TC18053272834103613401722\\\\extplugins\\\\isg.py', 252, 'cmd_gift', None)]"

this is line 252: if event.client.state == b3.STATE_ALIVE:
Logged
Senior Dev.
*
OS: Linux
Type: Home user
Posts: 3484
Offline Offline
WWW
Support Specialty: B3-Core, UrT/SmG/BFBC2 parsers, Plugin development
« Reply #7 on: December 03, 2011, 11:20:07 PM »

there is no 'event' variable defined in your code. You copy/pasted some code from a "onEvent()" method (where a 'event' parameter exists).

you want "client", not "event.client"
Logged

Jr. Member
**
OS: Windows
Type: Renting Server with B3
Gameservers: CoD4
Posts: 24
Offline Offline
« Reply #8 on: December 03, 2011, 11:26:30 PM »

oh yeah whoops:P umm is there anyway to get a list of clients have randomly select one of them so i don't have make it keep running itself and preventing lag of the commands response?
Logged
Senior Dev.
*
OS: Linux
Type: Home user
Posts: 3484
Offline Offline
WWW
Support Specialty: B3-Core, UrT/SmG/BFBC2 parsers, Plugin development
« Reply #9 on: December 04, 2011, 11:43:41 AM »

If you don't make efforts to ask understandable questions, how can we help you ?

read again your last question and ask yourself if anyone else but you can get what you mean
Logged

Jr. Member
**
OS: Windows
Type: Renting Server with B3
Gameservers: CoD4
Posts: 24
Offline Offline
« Reply #10 on: December 04, 2011, 01:52:11 PM »

is there any way to get a list of alive clients in the servers, then run the random command on that list of cids. so it will give a random client the item it selects? better?
Logged
Senior Dev.
*
OS: Linux
Type: Home user
Posts: 3484
Offline Offline
WWW
Support Specialty: B3-Core, UrT/SmG/BFBC2 parsers, Plugin development
« Reply #11 on: December 04, 2011, 03:37:43 PM »

Have a look at self.console.clients.getList()

you will find examples in different plugins such as status or stat
Logged

Jr. Member
**
OS: Windows
Type: Renting Server with B3
Gameservers: CoD4
Posts: 24
Offline Offline
« Reply #12 on: December 04, 2011, 08:14:12 PM »

can you give me a line of code for it? because i checked and i still don't know how to use it?
Logged
Senior Dev.
*
OS: Linux
Type: Home user
Posts: 3484
Offline Offline
WWW
Support Specialty: B3-Core, UrT/SmG/BFBC2 parsers, Plugin development
« Reply #13 on: December 05, 2011, 12:16:35 AM »

Quote
is there any way to get a list of alive clients in the servers
Code: python
list_of_players = self.console.clients.getList()
gives you the list of all connected players.

I don't know of any good method to know if a player is alive. There is the b3.STATE_ALIVE status but it is not reliable for most games.
Logged

Jr. Member
**
OS: Windows
Type: Renting Server with B3
Gameservers: CoD4
Posts: 24
Offline Offline
« Reply #14 on: December 05, 2011, 05:26:49 PM »

so i did this:
Code:
clients = self.console.clients.getClientsByState(b3.STATE_ALIVE)
which works but i can not select a random client from the list... it just selects the first client on it
Logged
Tags:
Pages: [1] 2   Go Up
  Print  
 
Jump to:  


Rate this page +1 at Google Search


SimplePortal 2.3.1 © 2008-2009, SimplePortal