Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ../addons/source-python/plugins/parachute/parachute.py
- # ============================================================================
- # >> IMPORTS
- # ============================================================================
- # Source.Python Imports
- from entities.constants import MoveType
- from players.constants import PlayerStates
- from players.constants import PlayerButtons
- from mathlib import Vector
- # Config
- from config.manager import ConfigManager
- # ConVars
- from cvars.public import PublicConVar
- # Events
- from events import Event
- # Filters
- from filters.players import PlayerIter
- # Messages
- from messages import HintText
- # Players
- from players.entity import Player
- # Plugins
- from plugins.info import PluginInfo
- # Tick
- from listeners import OnTick
- from listeners.tick import Delay
- # Translations
- from translations.strings import LangStrings
- # ============================================================================
- # >> INFORMATIONS
- # ============================================================================
- informations = PluginInfo()
- informations.author = 'L\'In20Cible'
- informations.basename = __name__.rsplit('.')[~0]
- informations.description = 'You know...'
- informations.name = informations.basename.title()
- informations.version = '0.01'
- informations.url = 'http://www.sourcepython.com/index.php'
- PublicConVar('parachute_version', informations.version,
- informations.description)
- # ============================================================================
- # >> GLOBAL VARIABLES
- # ============================================================================
- # Create and execute the configuration file...
- configuration = ConfigManager(informations.basename)
- parachute_advert = configuration.cvar('parachute_advert', '1',
- description='Enable/Disable the advert every round start.')
- parachute_button = configuration.cvar('parachute_button', 'SPEED',
- description='Defines the button to use the parachute.')
- parachute_falling_speed = configuration.cvar('parachute_falling_speed', '10',
- description='Defines the falling speed of the parachute.')
- configuration.write()
- configuration.execute()
- # Parse the translations files...
- translations = LangStrings(informations.basename)
- # Get a global HintText...
- advert = HintText(message=translations['Advert'])
- # ============================================================================
- # >> LISTENER CALLBACKS
- # ============================================================================
- @OnTick
- def tick_listener():
- '''Fired each game frame...'''
- try:
- # Loop through all living, human players...
- for player in PlayerIter(is_filters=['alive'], not_filters=['bot']):
- # Get the player falling velocity...
- velocity = player.get_property_float('m_Local.m_flFallVelocity')
- # Is the player not falling?
- if (velocity < 1.0 or
- # Is the player not holding his parachute key?
- not player.buttons & getattr(PlayerButtons,
- parachute_button.get_string().upper()) or
- # Is the player currently in a ladder?
- player.get_property_int('movetype') & MoveType.LADDER or
- # Is the player currently in water?
- player.get_property_int('m_fFlags') & PlayerStates.INWATER):
- # If any of the check above was True, no need to go further...
- continue
- # Revert the falling velocity to slow down the player speed...
- player.set_property_vector('localdata.m_vecBaseVelocity',
- Vector(0, 0, velocity + (
- parachute_falling_speed.get_float() * -1)))
- except Exception as e:
- print(e)
- # ============================================================================
- # >> GAME EVENTS
- # ============================================================================
- @Event('round_start')
- def round_start(game_event):
- '''Fired at the beginning of every round...'''
- # Is the advert disabled?
- if not parachute_advert.get_bool():
- # No need to go further...
- return
- # Send the advert...
- # NOTE: Since ResetHud is sent every round, we need to wait a bit before
- # sending a HintText message...
- Delay(0.5, advert.send,
- button=parachute_button.get_string().lower())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement