[BMS] Fog Help

A place for requesting new Source.Python plugins to be made for your server.

Please request only one plugin per thread.
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

[BMS] Fog Help

Postby Painkiller » Sat Oct 08, 2016 2:50 pm

Hello, this plugin does not work with the latest SP version.

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.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: [BMS] Fog Help

Postby satoon101 » Sat Oct 08, 2016 3:32 pm

All listener decorators were changed to add the word On as a prefix. Just change LevelInit to OnLevelInit to fix that error. The same needs to be done with ClientConnect.

Also, it seems the plugin uses tick_delays.delay, which was changed to Delay some time ago.
Image
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [BMS] Fog Help

Postby Painkiller » Sat Oct 08, 2016 3:51 pm

Code: Select all

[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 15, in <module>
    from listeners.tick import delay

ImportError: cannot import name 'delay'


[SP] Plugin 'fog' was unable to be loaded.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: [BMS] Fog Help

Postby satoon101 » Sat Oct 08, 2016 3:55 pm

Image
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [BMS] Fog Help

Postby Painkiller » Sat Oct 08, 2016 4:00 pm

Iam not the best in it.

Code: Select all

[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 99, in <module>
    @LevelInit

NameError: name 'LevelInit' is not defined


[SP] Plugin 'fog' was unable to be loaded.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: [BMS] Fog Help

Postby satoon101 » Sat Oct 08, 2016 4:03 pm

When you change the import, you have to change all uses of it. Again, LevelInit needs to be OnLevelInit throughout the plugin.
Image
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [BMS] Fog Help

Postby Painkiller » Sat Oct 08, 2016 4:08 pm

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 OnLevelInit
from listeners import OnClientConnect
from cvars import cvar
from listeners.tick import Delay


# =============================================================================
# >> 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)

@OnClientConnect
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])
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [BMS] Fog Help

Postby Painkiller » Sat Oct 08, 2016 4:09 pm

i see last lines
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: [BMS] Fog Help

Postby satoon101 » Sat Oct 08, 2016 4:10 pm

@LevelInit -> @OnLevelInit
Image
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [BMS] Fog Help

Postby Painkiller » Sat Oct 08, 2016 4:10 pm

sp plugin reload fog
[SP] Unloading plugin 'fog'...
[SP] Successfully unloaded plugin 'fog'.
[SP] Loading plugin 'fog'...
[SP] Successfully loaded plugin 'fog'.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: [BMS] Fog Help

Postby satoon101 » Sat Oct 08, 2016 4:12 pm

I see the plugin still doesn't include this:
viewtopic.php?p=6334#p6334

I imagine that, with the current version, if you change maps after loading the plugin, it will work fine. Or, to avoid having to do so, add what is mentioned in that post.
Image
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [BMS] Fog Help

Postby Painkiller » Sat Oct 29, 2016 12:55 pm

All Work good Thanks

Return to “Plugin Requests”

Who is online

Users browsing this forum: No registered users and 20 guests