thankyou
Donate to the B3 fund!

"even a small donation helps!"
Donate with PayPal!

Author Topic: [UrT] some handy functions for changing g_allowvote settings on the server  (Read 6208 times)

Offline xlr8or

  • [ www.xlrstats.com ]
  • Project Lead
  • Hero Member
  • *
  • Posts: 2057
    • The Art of Tactical Gaming
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 ;) ), 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 [Select]
### 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 [Select]
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 [Select]
  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 [Select]
      if state == _currState:
        return None
      elif _currState == 'off':
        _vote = _vote + bit
      else:
        _vote = _vote - bit

Can be replaced by:
Code: python [Select]
      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 [Select]
self.setVoteBit(VOTE_G_GAMETYPE, 'on')
« Last Edit: October 06, 2009, 06:24:22 PM by xlr8or »

Offline Courgette

  • Senior Dev.
  • Hero Member
  • *
  • Posts: 4883
    • Github repository
Nice :)

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 ?

Offline xlr8or

  • [ www.xlrstats.com ]
  • Project Lead
  • Hero Member
  • *
  • Posts: 2057
    • The Art of Tactical Gaming
yes, included in the parser (if I understand you correctly) it would be callable like this:
Code: python [Select]
self.console.setVoteBit(VOTE_G_GAMETYPE, 'on')

Offline xlr8or

  • [ www.xlrstats.com ]
  • Project Lead
  • Hero Member
  • *
  • Posts: 2057
    • The Art of Tactical Gaming
or, maybe add it to function.py?

Offline Courgette

  • Senior Dev.
  • Hero Member
  • *
  • Posts: 4883
    • Github repository
hum.... this is very specific to UrT

 


Rate this page +1 at Google Search

anything