Advertisement
Kovitikus

Roundtime Set & Check

Aug 27th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. import time
  2. from evennia import utils
  3.  
  4. def check_roundtime(owner):
  5.     if owner.db.ko == True:
  6.         owner.msg("You can't do that while unconscious!")
  7.         return False
  8.  
  9.     # Create cooldown attribute if non-existent.
  10.     if not owner.attributes.has('roundtime'):
  11.         owner.db.roundtime = 0
  12.  
  13.     # Calculate current time, total cooldown, and remaining time.
  14.     now = time.time()
  15.     lastcast = owner.attributes.get('roundtime')
  16.     cooldown = lastcast + 2
  17.     time_remaining = cooldown - now
  18.  
  19.     # Inform the attacker that they are in cooldown and exit the function.
  20.     if time_remaining > 0 or owner.db.busy == True:
  21.         if time_remaining >= 2:
  22.             message = f"You need to wait {int(time_remaining)} more seconds."
  23.         elif time_remaining >= 1 and time_remaining < 2:
  24.             message = f"You need to wait {int(time_remaining)} more second."
  25.         elif time_remaining < 1:
  26.             message = f"You are in the middle of something."
  27.         owner.msg(message)
  28.         return False
  29.     return True
  30.  
  31. def set_roundtime(owner):
  32.     now = time.time()
  33.     utils.delay(2, unbusy, owner, persistent=True)
  34.     owner.db.busy = True
  35.     owner.db.roundtime = now
  36.  
  37. def unbusy(owner):
  38.     owner.msg('|yYou are no longer busy.|n')
  39.     owner.db.busy = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement