Advertisement
KirillMysnik

Parachute

Apr 15th, 2016
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.51 KB | None | 0 0
  1. # ../addons/source-python/plugins/parachute/parachute.py
  2.  
  3.  
  4. # ============================================================================
  5. # >> IMPORTS
  6. # ============================================================================
  7. # Source.Python Imports
  8. from entities.constants import MoveType
  9. from players.constants import PlayerStates
  10. from players.constants import PlayerButtons
  11.  
  12. from mathlib import Vector
  13. #   Config
  14. from config.manager import ConfigManager
  15. #   ConVars
  16. from cvars.public import PublicConVar
  17. #   Events
  18. from events import Event
  19. #   Filters
  20. from filters.players import PlayerIter
  21. #   Messages
  22. from messages import HintText
  23. #   Players
  24. from players.entity import Player
  25. #   Plugins
  26. from plugins.info import PluginInfo
  27. #   Tick
  28. from listeners import OnTick
  29. from listeners.tick import Delay
  30. #   Translations
  31. from translations.strings import LangStrings
  32.  
  33.  
  34. # ============================================================================
  35. # >> INFORMATIONS
  36. # ============================================================================
  37. informations = PluginInfo()
  38. informations.author = 'L\'In20Cible'
  39. informations.basename = __name__.rsplit('.')[~0]
  40. informations.description = 'You know...'
  41. informations.name = informations.basename.title()
  42. informations.version = '0.01'
  43. informations.url = 'http://www.sourcepython.com/index.php'
  44.  
  45. PublicConVar('parachute_version', informations.version,
  46.     informations.description)
  47.    
  48.    
  49. # ============================================================================
  50. # >> GLOBAL VARIABLES
  51. # ============================================================================
  52. # Create and execute the configuration file...
  53. configuration = ConfigManager(informations.basename)
  54. parachute_advert = configuration.cvar('parachute_advert', '1',
  55.     description='Enable/Disable the advert every round start.')
  56. parachute_button = configuration.cvar('parachute_button', 'SPEED',
  57.     description='Defines the button to use the parachute.')
  58. parachute_falling_speed = configuration.cvar('parachute_falling_speed', '10',
  59.     description='Defines the falling speed of the parachute.')
  60. configuration.write()
  61. configuration.execute()
  62.  
  63. # Parse the translations files...
  64. translations = LangStrings(informations.basename)
  65.  
  66. # Get a global HintText...
  67. advert = HintText(message=translations['Advert'])
  68.  
  69.  
  70. # ============================================================================
  71. # >> LISTENER CALLBACKS
  72. # ============================================================================
  73. @OnTick
  74. def tick_listener():
  75.     '''Fired each game frame...'''
  76.  
  77.     try:
  78.    
  79.         # Loop through all living, human players...
  80.         for player in PlayerIter(is_filters=['alive'], not_filters=['bot']):
  81.  
  82.             # Get the player falling velocity...
  83.             velocity = player.get_property_float('m_Local.m_flFallVelocity')
  84.            
  85.             # Is the player not falling?
  86.             if (velocity < 1.0 or
  87.            
  88.             # Is the player not holding his parachute key?
  89.             not player.buttons & getattr(PlayerButtons,
  90.                 parachute_button.get_string().upper()) or
  91.                
  92.             # Is the player currently in a ladder?
  93.             player.get_property_int('movetype') & MoveType.LADDER or
  94.            
  95.             # Is the player currently in water?
  96.             player.get_property_int('m_fFlags') & PlayerStates.INWATER):
  97.                
  98.                 # If any of the check above was True, no need to go further...
  99.                 continue
  100.                
  101.             # Revert the falling velocity to slow down the player speed...
  102.             player.set_property_vector('localdata.m_vecBaseVelocity',
  103.                 Vector(0, 0, velocity + (
  104.                     parachute_falling_speed.get_float() * -1)))
  105.     except Exception as e:
  106.         print(e)
  107.                
  108.                
  109. # ============================================================================
  110. # >> GAME EVENTS
  111. # ============================================================================
  112. @Event('round_start')
  113. def round_start(game_event):
  114.     '''Fired at the beginning of every round...'''
  115.    
  116.     # Is the advert disabled?
  117.     if not parachute_advert.get_bool():
  118.        
  119.         # No need to go further...
  120.         return
  121.        
  122.     # Send the advert...
  123.     # NOTE: Since ResetHud is sent every round, we need to wait a bit before
  124.     #   sending a HintText message...
  125.     Delay(0.5, advert.send,
  126.         button=parachute_button.get_string().lower())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement