Could someone help me to repair?
Syntax: Select all
# =============================================================================
# >> IMPORTS
# =============================================================================
# Python
import random
# Source.Python
from entities.entity import Entity
from filters.entities import EntityIter
from colors import Color
from mathlib import Vector
from listeners import LevelInit
from listeners import ClientConnect
from cvars import cvar
from listeners.tick import tick_delays
# =============================================================================
# >> CONSTANTS
# =============================================================================
FOG_TYPES = [
# tricolor 4
(Color(255, 255, 0), Color(0, 255, 255), 'sky_borealis01'),
# tricolor 3
(Color(255, 0, 0), Color(0, 0, 255), 'sky_day03_06'),
# tricolor 2
(Color(0, 0, 255), Color(255, 0, 0), 'sky_day02_09'),
# tricolor 1
(Color(0, 255, 255), Color(255, 255, 0), 'sky_day01_09'),
# yellow
#(Color(255, 255, 0), Color(255, 255, 0), 'sky_borealis01'),
# white
#(Color(255, 255, 255), Color(255, 255, 255), 'sky_day03_06'),
# violet
#(Color(255, 0, 255), Color(255, 0, 255), 'sky_day02_09'),
# red
#(Color(255, 0, 0), Color(255, 0, 0), 'sky_day01_09'),
# green
#(Color(0, 255, 0), Color(0, 255, 0), 'sky_borealis01'),
# gray
#(Color(127, 128, 127), Color(128, 127, 128), 'sky_day03_06'),
# blue
#(Color(0, 0, 255), Color(0, 0, 255), 'sky_day02_09'),
# black
#(Color(255, 255, 255), Color(255, 255, 255), 'sky_day01_09'),
# aqua
#(Color(0, 255, 255), Color(0, 255, 255), 'sky_borealis01'),
]
if not FOG_TYPES:
raise ValueError('There are no fog types.')
sv_skyname = cvar.find_var('sv_skyname')
if sv_skyname is None:
raise ValueError('"sv_skyname" not found.')
# =============================================================================
# >> FUNCTIONS
# =============================================================================
def find_or_create(classname):
for entity in EntityIter(classname):
break
else:
entity = Entity.create(classname)
return entity
def set_fog(color1, color2):
entity = find_or_create('env_fog_controller')
entity.set_key_value_color('fogcolor', color1)
entity.set_key_value_color('fogcolor2', color2)
entity.set_key_value_vector('fogdir', Vector(1, 0, 0))
entity.set_key_value_int('farz', -1)
entity.set_key_value_int('fogenable', 1)
entity.set_key_value_int('fogblend', 10)
entity.set_key_value_int('use_angles', 0)
entity.set_key_value_int('foglerptime', 10)
entity.set_key_value_int('fogstart', 100)
entity.set_key_value_int('fogend', 5000)
entity.call_input('TurnOn')
# =============================================================================
# >> LISTENERS
# =============================================================================
@LevelInit
def on_level_init(map_name):
random.shuffle(FOG_TYPES)
color1, color2, sky_name = FOG_TYPES[0]
set_fog(color1, color2)
@ClientConnect
def on_client_connect(allow_ptr, index, name, address, reject_ptr, reject_len):
# The sky name can't be set in the LevelInit listener, because at that
# point the map hasn't been fully initialized yet and the server will
# overwrite the sky name. We can't delay it in LevelInit, because on a map
# change players might already connect again, although the delay is still
# running. So, this would result in setting the sky name after the player
# has connected and that doesn't work either.
# Solution:
# Set it when a player asks to connect. Actually, we only need to set it
# once per map, but setting it multiple times is much easier. :D
sv_skyname.set_string(FOG_TYPES[0][2])
Code: Select all
sp plugin reload fog
[SP] Unable to unload plugin 'fog' as it is not currently loaded.
[SP] Loading plugin 'fog'...
[SP] Caught an Exception:
Traceback (most recent call last):
File "../addons/source-python/packages/source-python/plugins/manager.py", line 75, in __missing__
instance = self.instance(plugin_name, self.base_import)
File "../addons/source-python/packages/source-python/plugins/instance.py", line 82, in __init__
self._plugin = import_module(import_name)
File "../addons/source-python/plugins/fog/fog.py", line 12, in <module>
from listeners import LevelInit
ImportError: cannot import name 'LevelInit'
[SP] Plugin 'fog' was unable to be loaded.