Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #forced_attack.py
  2. from players.constants import PlayerButtons
  3. from players.helpers import index_from_userid
  4.  
  5. from listeners import OnPlayerRunCommand
  6.  
  7. from commands import CommandReturn
  8. from commands.client import ClientCommand
  9.  
  10.  
  11. forced_players = []
  12.  
  13. @OnPlayerRunCommand
  14. def player_run_cmd(player, cmd):
  15.     if player.userid not in forced_players:
  16.         return
  17.  
  18.     if player.dead:
  19.         return
  20.  
  21.     # force the player to attack
  22.     # this is basically like typing +attack in console
  23.     cmd.buttons |= PlayerButtons.ATTACK
  24.  
  25.  
  26. def toggle_forced_attack(userid):
  27.     # does this userid exist?
  28.     try:
  29.         index = index_from_userid(userid)
  30.     except:
  31.         print('toggle_forced_attack: invalid userid > {0}'.format(userid))
  32.         return
  33.  
  34.     # is the userid already in the list?
  35.     if userid in forced_players:
  36.         # if it is, remove it
  37.         forced_players.remove(userid)
  38.         return
  39.  
  40.     # add the userid to the list
  41.     forced_players.append(userid)
  42.  
  43.  
  44. # toggle_forced_attack <userid>
  45. @ClientCommand('toggle_forced_attack')
  46. def _toggle_forced_attack(command, index):
  47.     try:
  48.         userid = int(command[1])
  49.     except:
  50.         print('toggle_forced_attack: bad argument > {0}'.format(command.arg_string))
  51.         return CommandReturn.BLOCK
  52.  
  53.     toggle_forced_attack(userid)
  54.     return CommandReturn.BLOCK
  55.  
  56. @ClientCommand('stop_forcing_all')
  57. def _stop_forcing_all(command, index):
  58.     forced_players.clear()
  59.     return CommandReturn.BLOCK