Advertisement
Kovitikus

Can't call script method.

Aug 4th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.49 KB | None | 0 0
  1. '''The error.'''
  2. '''
  3. Traceback (most recent call last):
  4.  File "d:\muddev\evennia\evennia\commands\cmdhandler.py", line 591, in _run_command
  5.    ret = cmd.func()
  6.  File ".\commands\combat.py", line 28, in func
  7.    self.caller.db.combat_handler.attack(target)
  8. AttributeError: 'NoneType' object has no attribute 'attack'
  9.  
  10. An untrapped error occurred.
  11. (Traceback was logged 19-08-04 10:34:32-04).
  12. '''
  13.  
  14. '''The player's script creation.'''
  15. class Player_Character(DefaultCharacter):
  16.     def at_object_creation(self):
  17.         self.scripts.add(CombatHandler)
  18.  
  19. '''The attacking command within commands\combat.py'''
  20. class CmdStaveBash(BaseCommand):
  21.     '''
  22.    Use your staff to bash an enemy.
  23.  
  24.    Usage:
  25.        bash <target>
  26.    '''
  27.     key = 'bash'
  28.     help_category = 'combat'
  29.  
  30.     def func(self):
  31.         if not self.args:
  32.             self.caller.msg('Usage: bash <target>')
  33.             return
  34.         target = self.caller.search(self.args)
  35.         if not target:
  36.             self.caller.msg('That target does not exist!')
  37.             return
  38.         if not target.attributes.has('hp'):
  39.             self.caller.msg('You cannot attack that target!')
  40.             return
  41.         self.caller.db.combat_handler.attack(target) # LINE 28
  42.  
  43. '''The combat handler script'''
  44. class CombatHandler(DefaultScript):
  45.     key = 'combat_handler'
  46.  
  47.     def attack(self, target):  
  48.         damage = 20
  49.        
  50.         now = time.time()
  51.         lastcast = self.db.stave_bash
  52.         cooldown = lastcast + 3
  53.         time_remaining = cooldown - now
  54.  
  55.         if time_remaining > 0:
  56.             if time_remaining >= 2:
  57.                 message = f"You need to wait {int(time_remaining)} more seconds."
  58.             elif time_remaining >= 1 and time_remaining < 2:
  59.                 message = f"You need to wait {int(time_remaining)} more second."
  60.             elif time_remaining < 1:
  61.                 message = f"You are in the middle of something."
  62.             self.obj.msg(message)
  63.             return
  64.  
  65.         # roll = random.randint(1, 100)
  66.         # success = random.randint(5, 95)
  67.         roll = 100
  68.         success = 0
  69.  
  70.         if roll > success:
  71.             self.obj.msg(f'[Success: {success} Roll: {roll}] You bash {target} with your stave!')
  72.             self.take_damage(target, damage)
  73.         else:
  74.             self.obj.msg(f'[Success: {success} Roll: {roll}] You miss {target} with your stave!')
  75.         utils.delay(3, self.unbusy)
  76.         self.db.stave_bash = now
  77.  
  78.     def take_damage(self, target, damage):
  79.         mob = target.key
  80.         location = target.location
  81.        
  82.         target.db.hp -= damage
  83.         hp = target.db.hp
  84.         location.msg_contents(f'{mob} has {hp} health remaining!')
  85.         if hp >= 1:
  86.             target.db.ko = False
  87.         elif hp <= 0 and self.db.ko != True:
  88.             target.db.ko = True
  89.             location.msg_contents(f'{mob} falls unconscious!')
  90.         if hp <= -100:
  91.             okay = target.delete()
  92.             if not okay:
  93.                 location.msg_contents(f'\nERROR: {mob} not deleted, probably because delete() returned False.')
  94.             else:
  95.                 location.msg_contents(f'{mob} breathes a final breath and expires.')
  96.         return
  97.    
  98.     def unbusy(self):
  99.             self.obj.msg('|yYou are no longer busy.|n')
  100.  
  101. '''Puppeted character's examine'''
  102. '''
  103. ------------------------------------------------------------------------------
  104. Name/key: Bobby (#25)
  105. Aliases: a bobby(#25),one bobby(#25)s
  106. Session id(s): #4
  107. Account: Kovitikus
  108. Account Perms: <Superuser>
  109. Typeclass: Player_Character (typeclasses.characters.Player_Character)
  110. Location: Hoff's Bar (#7)
  111. Home: Limbo (#2)
  112. Permissions: <None> [Superuser]
  113. Locks:      call:false(); control:perm(Developer); delete:perm(Admin);
  114.      edit:perm(Admin); examine:perm(Builder); get:false();
  115.      puppet:pperm(Developer); tell:perm(Admin); view:all()
  116. Stored Cmdset(s):
  117. commands.default_cmdsets.CharacterCmdSet [DefaultCharacter] (Union, prio 0)
  118. Merged Cmdset(s):
  119. evennia.commands.cmdset.CmdSet [ChannelCmdSet] (Union, prio 101)
  120. commands.default_cmdsets.CharacterCmdSet [DefaultCharacter] (Union, prio 0)
  121. commands.default_cmdsets.AccountCmdSet [DefaultAccount] (Union, prio -10)
  122. commands.default_cmdsets.SessionCmdSet [DefaultSession] (Union, prio -20)
  123. Commands available to Bobby (result of Merged CmdSets):
  124.   about, access, accounts, addcom, alias, allcom, ban, bash, batchcode,
  125.  batchcommands, boot, cboot, ccreate, cdesc, cdestroy, cemit, channels,
  126.  charcreate, chardelete, chargen, clock, cmdsets, color, copy, cpattr,
  127.  create, cwho, delcom, desc, destroy, dig, drop, emit, examine, find, force,
  128.  get, give, grapevine2chan, help, home, ic, inventory, irc2chan, ircstatus,
  129.  link, lock, look, mudinfo, mvattr, name, nick, objects, open, option, page,
  130.  password, perm, pose, public, py, quell, quit, reload, reset, rss2chan, say,
  131.  script, scripts, server, service, sessions, set, setdesc, sethelp, sethome,
  132.  shutdown, south, spawn, style, tag, tel, tickers, time, tunnel, typeclass,
  133.  unban, unlink, userpassword, wall, whisper, who, wipe
  134. Scripts:
  135. 'combat_handler' (inf/inf, inf repeats):
  136. Persistent attributes:
  137. figure = {'gender': 'male', 'height': 'very tall', 'build': 'ample'}
  138. facial = {'face': 'freckled', 'eye_color': 'light grey', 'nose': 'hooked', 'lips':[...]
  139. hair = {'hair_color': None, 'texture': None, 'length': 'bald', 'style': None}
  140. prelogout_location = Hoff's Bar
  141. ------------------------------------------------------------------------------
  142. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement