Skip to content

CSS Sound class duration #514

Closed
Closed
@srpg

Description

@srpg

In my zombie riot plugin that i have it uses background and sound class duration to play correctly sound, but after SP update to latest python it started give these errors
`

[SP] Caught an Exception:
Traceback (most recent call last):
  File "../addons/source-python/packages/source-python/listeners/tick.py", line 79, in _tick
    self.pop(0).execute()
    ~~~~~~~~~~~~~~~~~~~^^
  File "../addons/source-python/packages/source-python/listeners/tick.py", line 160, in execute
    return self.callback(*self.args, **self.kwargs)
           ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "../addons/source-python/packages/source-python/listeners/tick.py", line 605, in _execute
    self.callback(*self.args, **self.kwargs)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "../addons/source-python/plugins/rpg/addons/zombie_riot/zombie_riot.py", line 747, in background_sound_repeat
    duration = float(sound.duration)
                     ^^^^^^^^^^^^^^
  File "../addons/source-python/packages/source-python/engines/sound.py", line 269, in duration
    if self.extension == 'ogg':
       ^^^^^^^^^^^^^^
  File "../addons/source-python/packages/source-python/engines/sound.py", line 241, in extension
    return self.full_path.ext[1:]
           ^^^^^^^^^^^^^^^^^^

AttributeError: 'Path' object has no attribute 'ext'
@Repeat
def background_sound_repeat():
    global background_play
    sounds_list = listdir(sounds_folder_path)
    _sounds = []
    for play_sound in filter(lambda x: x.endswith('.mp3') and not x.startswith('zombie') and not x.startswith('death') or x.endswith('.wav') and not x.startswith('zombie') and not x.startswith('death'), sounds_list):
         _sounds.append(play_sound)

    if len(_sounds):

        if background_play is not None:
            background_play.stop()

        sound_to_play = choice(_sounds)
        engine_sound.precache_sound(f'new_ambient/zr/{sound_to_play}')
        sound = Sound(f'new_ambient/zr/{sound_to_play}')
        duration = float(sound.duration)
        background_play = sound

        for player in filter(lambda x: get_background_sound_status(x.steamid.replace('[', '').replace(']', '')) == 1, PlayerIter('human')):
            sound.play(player.index)

        background_sound_repeat.stop()
        background_sound_repeat.start(duration)

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions