Event Error

Please post any questions about developing your plugin here. Please use the search function before posting!
SkinN
Junior Member
Posts: 25
Joined: Fri Jul 19, 2013 7:29 am

Event Error

Postby SkinN » Tue Oct 27, 2015 7:01 pm

Hi,

I can't seem to figure this error, I am just trying to get familiar with Source Python and I'm starting by practicing with small stuff before I get started on projects I have in mind and I tried this code:

Syntax: Select all

# Python Imports

# SourcePython imports
from players.entity import PlayerEntity


from players.helpers import userid_from_index
from players.helpers import index_from_userid


from events import Event


from messages import SayText2


from cvars.public import PublicConVar
from plugins.info import PluginInfo


info = PluginInfo()
info.name = "Tests Plugin"
info.author = "SkinN"
info.version = "1.0"
info.basename = "test"
info.variable = info.basename + "_version"
info.convar = PublicConVar(info.variable, info.version, 0, info.name + " Version")


@Event
def player_footstep(game_event):


uid = game_event.get_int('userid')
idx = index_from_userid(userid)


SayText2('User: %s' % uid).send(uid)


And returns this error:

Code: Select all

[SP] Caught an Exception:Traceback (most recent call last):
  File '..\addons\source-python\packages\source-python\plugins\manager.py', line 71, 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\test\test.py', line 24, in <module>
    @Event
  File '..\addons\source-python\packages\source-python\events\__init__.py', line 54, in __init__
    raise ValueError('Event name must be a string.')


ValueError: Event name must be a string.


Thanks in advance
SkinN
Junior Member
Posts: 25
Joined: Fri Jul 19, 2013 7:29 am

Postby SkinN » Tue Oct 27, 2015 7:11 pm

Nevermind, I just figured it out. Also there were some errors still.

Syntax: Select all

# Python Imports

# SourcePython imports
from players.entity import PlayerEntity


from players.helpers import userid_from_index
from players.helpers import index_from_userid


from events import Event


from messages import SayText2


from cvars.public import PublicConVar
from plugins.info import PluginInfo


info = PluginInfo()
info.name = "Tests Plugin"
info.author = "SkinN"
info.version = "1.0"
info.basename = "test"
info.variable = info.basename + "_version"
info.convar = PublicConVar(info.variable, info.version, 0, info.name + " Version")


@Event('player_footstep')
def player_footstep(game_event):


uid = game_event.get_int('userid')
idx = index_from_userid(uid)


SayText2('User: %s' % uid).send(idx)
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Tue Oct 27, 2015 7:14 pm

We changed the Event decorator some months ago. http://forums.sourcepython.com/showthread.php?888-PreEvent-and-changes-to-Event

Syntax: Select all

@Event('player_footstep')
def player_footstep(game_event):
# Your code...

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 115 guests