Getting a PlayerEntity from player_connect?

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Mahi
Senior Member
Posts: 236
Joined: Wed Aug 29, 2012 8:39 pm
Location: Finland

Getting a PlayerEntity from player_connect?

Postby Mahi » Sun Jan 25, 2015 11:11 am

Hey! I'm attempting to get a PlayerEntity object when the player is connecting:

Syntax: Select all

from events import Event
from players.entity import PlayerEntity

players = []

@Event
def player_connect(game_event):
player = PlayerEntity(game_event.get_int('index'))
players.append(player)

However, I run into an error:

Code: Select all

Client "Mahi" connected (192.168.1.202:27006).

[SP] Caught an Exception:
Traceback (most recent call last):
  File '..\addons\source-python\packages\source-python\events\listener.py', line
 90, in fire_game_event
    callback(game_event)
  File '..\addons\source-python\plugins\test\test.py', line 8, in playe
r_connect
    player = PlayerEntity(game_event.get_int('index'))
  File '..\addons\source-python\packages\source-python\players\entity.py', line
40, in __new__
    self._playerinfo = playerinfo_from_index(self.index)

ValueError: Conversion failed...


Ayuto suggested me to use @ClientConnect:

Syntax: Select all

from listeners import ClientConnect
from players.entity import PlayerEntity

players = []

@ClientConnect
def client_connect(index):
player = PlayerEntity(index)
players.append(player)

And it gave me an error like so:

Code: Select all

Client "Mahi" connected (192.168.1.202:27006).

[SP] Caught an Exception:

TypeError: No to_python (by-value) converter found for C++ type: char


How can I get a PlayerEntiy object when the client connects?
User avatar
Ayuto
Project Leader
Posts: 2209
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sun Jan 25, 2015 11:35 am

Oh, this is my fault. ClientConnect listeners require more parameters. http://forums.sourcepython.com/showthread.php?670-Custom-params-in-event&p=3708&viewfull=1#post3708

ClientDisconnect requires only an index.
User avatar
Mahi
Senior Member
Posts: 236
Joined: Wed Aug 29, 2012 8:39 pm
Location: Finland

Postby Mahi » Sun Jan 25, 2015 11:37 am

Ayuto wrote:Oh, this is my fault. ClientConnect listeners require more parameters. http://forums.sourcepython.com/showthread.php?670-Custom-params-in-event&p=3708&viewfull=1#post3708

ClientDisconnect requires only an index.


Ahh okay sry, I should've figured that myself, the error just didn't tell me anything at all.

Edit: Nope, still not working

Code: Select all

[SP] Caught an Exception:
Traceback (most recent call last):
  File '..\addons\source-python\plugins\test\test.py', line 7, in on_cl
ient_connect
    player = Player(player_index)
  File '..\addons\source-python\packages\source-python\players\entity.py', line
56, in __new__
    self = super(PlayerEntity, cls).__new__(cls, index)
  File '..\addons\source-python\packages\source-python\entities\entity.py', line
 41, in __new__
    edict = edict_from_index(index)

ValueError: Conversion failed...
User avatar
L'In20Cible
Project Leader
Posts: 1536
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Sun Jan 25, 2015 11:47 am

You cannot get a PlayerEntity instance from that event/listener. The index is not linked to the other player's objects at this point. Try with the player_activate event, instead.
User avatar
Mahi
Senior Member
Posts: 236
Joined: Wed Aug 29, 2012 8:39 pm
Location: Finland

Postby Mahi » Sun Jan 25, 2015 11:57 am

L'In20Cible wrote:You cannot get a PlayerEntity instance from that event/listener. The index is not linked to the other player's objects at this point. Try with the player_activate event, instead.

Still giving me the same error:

Code: Select all

[SP] Caught an Exception:
Traceback (most recent call last):
  File '..\addons\source-python\packages\source-python\events\listener.py', line
 90, in fire_game_event
    callback(game_event)
  File '..\addons\source-python\plugins\test\test.py', line 7, in playe
r_activate
    player = Player(game_event.get_int('index'))
  File '..\addons\source-python\packages\source-python\players\entity.py', line
59, in __new__
    self._playerinfo = playerinfo_from_index(self.index)

ValueError: Conversion failed...
User avatar
L'In20Cible
Project Leader
Posts: 1536
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Sun Jan 25, 2015 11:59 am

Well, that event doesn't provide an "index" field.

Syntax: Select all

from events import Event
from players.entity import PlayerEntity
from players.helpers import index_from_userid

@Event
def player_activate(game_event):
player = PlayerEntity(index_from_userid(game_event.get_int('userid')))
...
User avatar
Mahi
Senior Member
Posts: 236
Joined: Wed Aug 29, 2012 8:39 pm
Location: Finland

Postby Mahi » Sun Jan 25, 2015 12:03 pm

L'In20Cible wrote:Well, that event doesn't provide an "index" field.

Syntax: Select all

from events import Event
from players.entity import PlayerEntity
from players.helpers import index_from_userid

@Event
def player_activate(game_event):
player = PlayerEntity(index_from_userid(game_event.get_int('userid')))
...


Ahh seems right, thanks... That'll do :P
User avatar
satoon101
Project Leader
Posts: 2703
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Mon Jan 26, 2015 6:14 am

For reference on the event variables of player_activate, we do have most of the CS:S and CS:GO event pages completed:
Events
CS:GO Events
CS:GO player_activate
CS:S Events
CS:S player_activate
Image

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 149 guests