Re: Parachute!
Posted: Tue Jan 24, 2017 12:19 am
Remove the info part.
Syntax: Select all
09:10:17 [SP] Loading plugin 'parachute'...
[SP] Caught an Exception:
Traceback (most recent call last):
File "../addons/source-python/packages/source-python/plugins/command.py", line 162, in load_plugin
plugin = self.manager.load(plugin_name)
File "../addons/source-python/packages/source-python/plugins/manager.py", line 174, in load
plugin._load()
File "../addons/source-python/packages/source-python/plugins/instance.py", line 67, in _load
self.module = import_module(self.import_name)
File "../addons/source-python/plugins/parachute/parachute.py", line 48, in <module>
configuration = ConfigManager(informations.basename)
NameError: name 'informations' is not defined
[SP] Plugin 'parachute' was unable to be loaded.
Code: Select all
[SP] Loading plugin 'parachute'...
[SP] Caught an Exception:
Traceback (most recent call last):
File "../addons/source-python/packages/source-python/plugins/command.py", line 162, in load_plugin
plugin = self.manager.load(plugin_name)
File "../addons/source-python/packages/source-python/plugins/manager.py", line 193, in load
plugin._load()
File "../addons/source-python/packages/source-python/plugins/instance.py", line 74, in _load
self.module = import_module(self.import_name)
File "../addons/source-python/plugins/parachute/parachute.py", line 67, in <module>
with open(CFG_PATH / 'parachute' / 'precache.res') as f:
FileNotFoundError: [Errno 2] No such file or directory: Path('../cfg/source-python/parachute/precache.res')
[SP] Plugin 'parachute' was unable to be loaded.
Code: Select all
FileNotFoundError: [Errno 2] No such file or directory: Path('../cfg/source-python/parachute/precache.res')
Syntax: Select all
# ../addons/source-python/plugins/parachute/parachute.py
# ============================================================================
# >> IMPORTS
# ============================================================================
# Python Imports
from random import choice
# Source.Python Imports
from cvars import ConVarFlags
from entities.constants import MoveType
from paths import CFG_PATH
from players.constants import PlayerStates
from players.constants import PlayerButtons
from mathlib import Vector
# Config
from config.manager import ConfigManager
# Core
from core import echo_console
# ConVars
from cvars import ConVar
# Models
from engines.precache import Model
# Entities
from entities.entity import Entity
# 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
from plugins.manager import plugin_manager
# Tick
from listeners import OnTick
from listeners.tick import Delay
# Stringtables
from stringtables.downloads import Downloadables
# Translations
from translations.strings import LangStrings
# ============================================================================
# >> INFORMATIONS
# ============================================================================
info = plugin_manager.get_plugin_info(__name__)
# ============================================================================
# >> GLOBAL VARIABLES
# ============================================================================
# Create and execute the configuration file...
configuration = ConfigManager(info.name)
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(info.name)
# Get a global HintText...
advert = HintText(message=translations['Advert'])
# Parse precache.res
models = []
with open(CFG_PATH / info.name / 'precache.res') as f:
for line in f:
line = line.strip()
if not line:
continue
models.append(Model(line))
# Parse downloadables.res
downloadables = Downloadables()
with open(CFG_PATH / info.name / 'downloadables.res') as f:
for line in f:
line = line.strip()
if not line:
continue
downloadables.add(line)
parachutes = {}
# ============================================================================
# >> FUNCTIONS
# ============================================================================
def open_parachute(player):
parachute = Entity.create('prop_dynamic_override')
parachutes[player.userid] = (player, parachute)
parachute.model = choice(models)
parachute.teleport(player.origin, player.angles, None)
parachute.spawn()
def close_parachute(player):
parachutes.pop(player.userid)[1].remove()
# ============================================================================
# >> LISTENER CALLBACKS
# ============================================================================
@OnTick
def tick_listener():
'''Fired each game frame...'''
try:
# Teleport existing parachutes to their owners
for player, parachute in parachutes.values():
parachute.teleport(player.origin, player.angles, None)
# Loop through all living, human players...
for player in PlayerIter(is_filters=['alive'], not_filters=['bot']):
# Is the player not falling?
if (player.fall_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.move_type & MoveType.LADDER or
# Is the player currently in water?
player.flags & PlayerStates.INWATER):
if player.userid in parachutes:
close_parachute(player)
continue
# Revert the falling velocity to slow down the player speed...
player.base_velocity = Vector(
0,
0,
player.fall_velocity + (
parachute_falling_speed.get_float() * -1)
)
if player.userid not in parachutes:
open_parachute(player)
except Exception as e:
echo_console(str(e))
# ============================================================================
# >> GAME EVENTS
# ============================================================================
@Event('round_start')
def round_start(game_event):
'''Fired at the beginning of every round...'''
# Clear entities list
parachutes.clear()
# 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,
kwargs={'button': parachute_button.get_string().lower()})
Syntax: Select all
verbose_name = "Parachute"
author = "L'In20Cible, iPlayer"
description = "You know..."
version = "1.0"
Syntax: Select all
parachute.parent = weapon
Code: Select all
Date : 2017-12-02 18:54:00.610238
OS : Linux-3.14.1-ub-100hz-x86_64-with-debian-7.11
Game : css
SP version : 621
Server plugins:
00: Source.Python, (C) 2012-2016, Source.Python Team.
SP plugins:
00: gungame, 1.1.1, https://forums.sourcepython.com/viewtopic.php?t=1621
01: map_config
02: parachute, 0.02, https://forums.sourcepython.com/viewtopic.php?f=7&p=10736#p10736
Syntax: Select all
parachute.call_input('SetParent', '!activator', activator=weapon)
L'In20Cible wrote:Interesting. Does the Entity.set_parent call itself crash on Linux, or only when you parent to a carried weapon?
L'In20Cible wrote:Does the following also crashes?Syntax: Select all
parachute.call_input('SetParent', '!activator', activator=weapon)
L'In20Cible wrote:Hmm. What if you move it after the spawn() call?
Syntax: Select all
# ../addons/source-python/plugins/parachute/parachute.py
# ============================================================================
# >> IMPORTS
# ============================================================================
# Python Imports
# Math
from math import cos
from math import radians
from math import sin
# Source.Python Imports
# Core
from core import SOURCE_ENGINE
# Engines
from engines.precache import Model
# Entities
from entities.constants import MoveType
from entities.entity import Entity
# Listeners
from listeners import OnPlayerRunCommand
from listeners.tick import Delay
# Mathlib
from mathlib import Vector
# Paths
from paths import GAME_PATH
# Players
from players.constants import PlayerButtons
from players.constants import PlayerStates
from players.entity import Player
from players.dictionary import EntityDictionary
# Stringtables
from stringtables.downloads import Downloadables
# ============================================================================
# >> CONFIGURATION
# ============================================================================
# Define the falling speed in units/s. The higher this value is, the
# faster parachutists will fall.
falling_speed = 32
# Define the speed of the steering lines in units/s. To pull a steering line,
# parachutists must use their A or D keys to gain speed into the right or left
# direction allowing them to have a better control of their landing. However,
# pulling a line come with a falling speed cost.
#
# Set to 0 to disable the ability to pull a line.
steering_lines_speed = 5
# Define the falling speed penalty multiplier when pulling a line.
# e.g. With a falling speed of 32 and a penalty of 1.5, parachutists pulling
# their lines would fall at a speed of 48 units/s.
#
# Set to 1 to disable the falling speed penalty.
steering_lines_penalty = 1.5
# Define the key players must hold to deploy their parachute.
deployment_button = PlayerButtons.SPEED
# ============================================================================
# >> GLOBALS
# ============================================================================
downloadables = Downloadables()
downloadables.add_directory(f'models/parachute/{SOURCE_ENGINE}')
downloadables.add_directory('materials/models/parachute')
parachutes = EntityDictionary()
_path = f'models/parachute/{SOURCE_ENGINE}/parachute_default.mdl'
if not (GAME_PATH / _path).isfile():
parachute_model = None
else:
parachute_model = Model(_path)
# ============================================================================
# >> FUNCTIONS
# ============================================================================
def get_player_parachute(player):
for parachute in parachutes.values():
if parachute.owner_handle != player.inthandle:
continue
return parachute
def close_parachute(player):
parachute = get_player_parachute(player)
if parachute is None:
return
parachute.remove()
# ============================================================================
# >> LISTENERS
# ============================================================================
@OnPlayerRunCommand
def _on_player_run_command(player, usercmd):
if player.is_bot():
return
if (player.dead or
player.move_type == MoveType.LADDER or
player.flags & PlayerStates.INWATER or
not usercmd.buttons & deployment_button):
close_parachute(player)
return
fall_velocity = player.fall_velocity
if fall_velocity < 1.0:
close_parachute(player)
return
side_move = usercmd.side_move
if side_move and steering_lines_speed > 1:
yaw = player.eye_angle.y
if side_move < 0:
yaw += 90
else:
yaw -= 90
yaw = radians(yaw)
vec = Vector(
x=cos(yaw) * steering_lines_speed,
y=sin(yaw) * steering_lines_speed,
z=fall_velocity + -(falling_speed * steering_lines_penalty))
else:
vec = Vector(z=fall_velocity + -falling_speed)
player.base_velocity = vec
if parachute_model is None:
return
Delay(0, parachute_check, (player,))
def parachute_check(player):
angles = Vector(y=player.eye_angle.y)
parachute = get_player_parachute(player)
if parachute is None:
parachute = Entity.create('prop_dynamic_override')
parachutes[parachute.index] = parachute
weapon = player.active_weapon
if weapon is not None:
parachute.parent = weapon
parachute.model = parachute_model
parachute.owner_handle = player.inthandle
parachute.origin = player.origin
parachute.angles = angles
parachute.model_scale = 0.7
parachute.spawn()
return
weapon = player.active_weapon
if weapon is not None:
parent = parachute.parent
if parent != weapon:
parachute.parent = weapon
origin = player.origin
else:
parachute.parent = None
view_offset = player.view_offset.copy()
view_offset.z /= 2
origin = player.origin + view_offset
parachute.origin = origin
parachute.angles = angles
if parachute.model_scale >= 1.0:
return
parachute.model_scale += 0.024
Code: Select all
[SP] Loading plugin 'parachute'...
[SP] Caught an Exception:
Traceback (most recent call last):
File "../addons/source-python/packages/source-python/plugins/command.py", line 162, in load_plugin
plugin = self.manager.load(plugin_name)
File "../addons/source-python/packages/source-python/plugins/manager.py", line 193, in load
plugin._load()
File "../addons/source-python/packages/source-python/plugins/instance.py", line 74, in _load
self.module = import_module(self.import_name)
File "../addons/source-python/plugins/parachute/parachute.py", line 65, in <module>
downloadables.add_directory(f'models/parachute/{SOURCE_ENGINE}')
File "../addons/source-python/packages/source-python/stringtables/downloads.py", line 65, in add_directory
for index, file in enumerate(GAME_PATH.joinpath(directory).walkfiles(), 1):
File "../addons/source-python/packages/site-packages/path.py", line 665, in walkfiles
childList = self.listdir()
File "../addons/source-python/packages/site-packages/path.py", line 532, in listdir
for child in map(self._always_unicode, os.listdir(self))
FileNotFoundError: [Errno 2] No such file or directory: Path('../models/parachute/bms')
[SP] Plugin 'parachute' was unable to be loaded.
Painkiller wrote:No longer work for BMSCode: Select all
[SP] Loading plugin 'parachute'...
[SP] Caught an Exception:
Traceback (most recent call last):
File "../addons/source-python/packages/source-python/plugins/command.py", line 162, in load_plugin
plugin = self.manager.load(plugin_name)
File "../addons/source-python/packages/source-python/plugins/manager.py", line 193, in load
plugin._load()
File "../addons/source-python/packages/source-python/plugins/instance.py", line 74, in _load
self.module = import_module(self.import_name)
File "../addons/source-python/plugins/parachute/parachute.py", line 65, in <module>
downloadables.add_directory(f'models/parachute/{SOURCE_ENGINE}')
File "../addons/source-python/packages/source-python/stringtables/downloads.py", line 65, in add_directory
for index, file in enumerate(GAME_PATH.joinpath(directory).walkfiles(), 1):
File "../addons/source-python/packages/site-packages/path.py", line 665, in walkfiles
childList = self.listdir()
File "../addons/source-python/packages/site-packages/path.py", line 532, in listdir
for child in map(self._always_unicode, os.listdir(self))
FileNotFoundError: [Errno 2] No such file or directory: Path('../models/parachute/bms')
[SP] Plugin 'parachute' was unable to be loaded.