Advertisement
Brainsucker

Untitled

Jan 27th, 2013
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.32 KB | None | 0 0
  1. import threading
  2. import time
  3.  
  4. import usermsg
  5. # import popuplib
  6. import es
  7.  
  8.  
  9.  
  10. class TimeCounter(threading.Thread):
  11.     round_ended = False
  12.     def __init__(self):
  13.         threading.Thread.__init__(self)
  14.        
  15.         self.lock = threading.Lock()
  16.  
  17.  
  18.     def run(self):
  19.         start_time = time.time()
  20.         es.msg('#multi', 'Thread has been started')
  21.         while True:
  22.        
  23.             self.lock.acquire()
  24.            
  25.             if TimeCounter.round_ended:
  26.                 break
  27.            
  28.             self.lock.release()
  29.            
  30.                
  31.             tdiff = time.time() - start_time
  32.            
  33.             round_time = es.ServerVar('mp_roundtime')
  34.             round_time_int = int(round_time)
  35.             round_time_seconds = round_time_int * 60
  36.            
  37.             remaining_time = round_time_seconds - tdiff
  38.            
  39.             for player in es.getUseridList():
  40.                 usermsg.hudhint(player, 'Time elapsed: %.2f\nTime remaining: %.2f' % (tdiff, remaining_time))
  41.                 # popuplib.quicksend(0,
  42.                
  43.         es.msg('#multi', 'Thread has been stopped')
  44.            
  45.    
  46. def round_start(ev):
  47.     TimeCounter.round_ended = False
  48.    
  49.     tc = TimeCounter()
  50.     tc.start()
  51.    
  52.    
  53. def round_end(ev):
  54.     TimeCounter.round_ended = True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement