Syntax: Select all
from events import Event
from entities.entity import Entity
from players.entity import Player
from players.helpers import index_from_userid
from filters.entities import EntityIter
from messages import SayText2
def load():
SayText2('\x07Debug loaded!').send()
def unload():
SayText2('\x07Debug unloaded!').send()
@Event('player_disconnect')
def on_player_disconnect(game_event):
userid = game_event['userid']
print("UserID is: ", userid)
print("index for userid is: ", index_from_userid(userid))
When I disconnect "normally" then the code runs fine, no problems.
But If I enter 'exit' in the server console then the server disconnects the players to shut itself down.
So the 'player_diconnect' event gets triggered but an error is thrown:
Code: Select all
[SP] Caught an Exception:
Traceback (most recent call last):
File "../addons/source-python/packages/source-python/events/listener.py", line 92, in fire_game_event
callback(game_event)
File "../addons/source-python/plugins/test/test.py", line 23, in on_player_disconnect
print("index for userid is: ", index_from_userid(userid))
ValueError: Conversion from "Userid" (3) to "Index" failed.
My guess is that there are no player-objects anymore. Why is it working when disconnecting manually and not when the server exits ?
Also I cannot find where index_from_userid() is defined originally. i looked in here https://github.com/Source-Python-Dev-Team/Source.Python/blob/92b3adfaaaf1bb9ecd2be1ddad55bc68589b4152/addons/source-python/packages/source-python/players/helpers.py but it just links to _players._helpers and I don't know where to find that. if anyone knows where to find it, I'd appreciate it.