You are here: Big Brother Bot ForumCommunity DevelopersThe Code Bin[UrT] some handy functions for changing g_allowvote settings on the server
Pages: [1]   Go Down
  Print  
Author Topic: [UrT] some handy functions for changing g_allowvote settings on the server  (Read 3117 times) Bookmark and Share
[ www.xlrstats.com ]
Project Lead
*
OS: Linux
Type: Owner dedicated server(s)
Gameservers: CoD, CoD2, CoD5, UrT
Posts: 2022
Offline Offline
WWW
Support Specialty: B3-Core, CoD/UrT/WoP/ETPro parsers, Plugin development
« on: June 07, 2009, 08:15:09 AM »

Calculating the proper setting for the UrT g_allowVote can be tricky. Because it is all about flipping bits in a binary way (just like we define the groups in B3). I've written a short and simple example/function that does just that. It makes life easier if you intend to write a plugin that needs to handle the voting settings for UrT. If you need it, use it (you can thank me in the plugin if you want Wink ), if you don't, perhaps you can learn from it. I thought I'd share this little snippet.

First the constants list for making vote-bits readable ( usage ie.: self.VOTE_KICK ):

Code: python
### voting constants ###
VOTE_RELOAD=1
VOTE_RESTART=2
VOTE_MAP=4
VOTE_NEXTMAP=8
VOTE_KICK=16
VOTE_SWAPTEAMS=32
VOTE_SHUFFLETEAMS=64
VOTE_G_FRIENDLYFIRE=128
VOTE_G_FOLLOWSTRICT=256
VOTE_G_GAMETYPE=512
VOTE_G_WAVERESPAWNS=1024
VOTE_TIMELIMIT=2048
VOTE_FRAGLIMIT=4096
VOTE_CAPTURELIMIT=8192
VOTE_G_RESPAWNDELAY=16384
VOTE_G_REDWAVERESPAWNDELAY=32768
VOTE_G_BLUEWAVERESPAWNDELAY=65536
VOTE_G_BOMBEXPLODETIME=131072
VOTE_G_BOMBDEFUSETIME=262144
VOTE_G_SURVIVORROUNDTIME=524288
VOTE_G_CAPUTURESCORETIME=1048576
VOTE_G_WARMUP=2097152
VOTE_G_MATCHMODE=4194304
VOTE_G_TIMEOUTS=8388608
VOTE_G_TIMEOUTLENGTH=16777216
VOTE_EXEC=33554432
VOTE_G_SWAPROLES=67108864
VOTE_G_MAXROUNDS=134217728
VOTE_G_GEAR=268435456
VOTE_CYCLEMAP=536870912

If you prefer a more readable form, you can easily generate the numbers (as above) with this (example) function:
Code: python
v=1
VOTE_RELOAD=v
VOTE_RESTART=v<<1
VOTE_MAP=v<<2
VOTE_NEXTMAP=v<<3
VOTE_KICK=v<<4
...etcetera

The function that enables you to easily switch the different g_allowvote bits on or off:

Code: python
  def setVoteBit(self, bit=VOTE_KICK, state='on'):
   if self.isEnabled():
     _vote = self.console.getCvar('g_allowVote').getInt()
     if (_vote & bit) == 0:
       _currState = 'off'
     else:
       _currState = 'on'
 
     if state == _currState:
       return None
     elif _currState == 'off':
       _vote = _vote + bit
     else:
       _vote = _vote - bit
     self.console.setCvar('g_allowVote', _vote)
     return None

Ofcourse code monkeys can compress code even more. For instance:
Code: python
      if state == _currState:
       return None
     elif _currState == 'off':
       _vote = _vote + bit
     else:
       _vote = _vote - bit
Can be replaced by:
Code: python
      if state == _currState:
       return None
     else:
       _vote ^= bit

How to call this function from within your code (for instance: enabling the players to start votes for the gametype):

Code: python
self.setVoteBit(VOTE_G_GAMETYPE, 'on')
« Last Edit: October 06, 2009, 08:24:22 AM by xlr8or » Logged


Senior Dev.
*
OS: Linux
Type: Home user
Posts: 3484
Online Online
WWW
Support Specialty: B3-Core, UrT/SmG/BFBC2 parsers, Plugin development
« Reply #1 on: June 07, 2009, 12:24:01 PM »

Nice Smiley

Just a thought : if this were part of iourt41.py as a function (not a method of Urt41Parser class), would it be callable from another plugin ?
Logged

[ www.xlrstats.com ]
Project Lead
*
OS: Linux
Type: Owner dedicated server(s)
Gameservers: CoD, CoD2, CoD5, UrT
Posts: 2022
Offline Offline
WWW
Support Specialty: B3-Core, CoD/UrT/WoP/ETPro parsers, Plugin development
« Reply #2 on: June 07, 2009, 01:39:22 PM »

yes, included in the parser (if I understand you correctly) it would be callable like this:
Code: python
self.console.setVoteBit(VOTE_G_GAMETYPE, 'on')
Logged

[ www.xlrstats.com ]
Project Lead
*
OS: Linux
Type: Owner dedicated server(s)
Gameservers: CoD, CoD2, CoD5, UrT
Posts: 2022
Offline Offline
WWW
Support Specialty: B3-Core, CoD/UrT/WoP/ETPro parsers, Plugin development
« Reply #3 on: June 08, 2009, 08:52:40 AM »

or, maybe add it to function.py?
Logged

Senior Dev.
*
OS: Linux
Type: Home user
Posts: 3484
Online Online
WWW
Support Specialty: B3-Core, UrT/SmG/BFBC2 parsers, Plugin development
« Reply #4 on: June 08, 2009, 09:25:51 AM »

hum.... this is very specific to UrT
Logged

Tags: flipbit urt voting 
Pages: [1]   Go Up
  Print  
 
Jump to:  


Rate this page +1 at Google Search


SimplePortal 2.3.1 © 2008-2009, SimplePortal