Page 1 of 1

Is client in game

Posted: Fri Aug 26, 2022 11:36 pm
by ghetto_life
Hello!
I am a new user of source.python.
SourceMod has functions: IsClientConnected and IsClientInGame.
In Source.Python I found only the is_connected method in the Player class. Does it include an in-game check?

Posted: Sat Aug 27, 2022 6:57 pm
by Articha
Why do you need it? Use listeners OnClientConnect, OnClientFullyConnect, OnClientPutInServer. If this is not solution for your problem, write more information about what/when you want something to do

Re: Is client in game

Posted: Sun Aug 28, 2022 9:02 am
by ghetto_life
For example select a random player and spawn him. If the player is not yet in the game - there will be an error.

Re: Is client in game

Posted: Sun Aug 28, 2022 10:21 am
by cssbestrpg
ghetto_life wrote:For example select a random player and spawn him. If the player is not yet in the game - there will be an error.


In that case try something like this:

Syntax: Select all

from events import Event
from players.entity import Player

@Event('player_say')
def player_say(args):
userid = args.get_int('userid')
text = args.get_string('text')
if text == 'respawn':
respawn(userid)

def respawn(userid):
try:
player = Player.from_userid(userid)
player.delay(1, player.spawn)
except ValueError:
# The userid was invalid
return

Re: Is client in game

Posted: Sun Aug 28, 2022 10:31 am
by ghetto_life
cssbestrpg wrote:
ghetto_life wrote:For example select a random player and spawn him. If the player is not yet in the game - there will be an error.


In that case try something like this:

Syntax: Select all

from events import Event
from players.entity import Player

@Event('player_say')
def player_say(args):
userid = args.get_int('userid')
text = args.get_string('text')
if text == 'respawn':
respawn(userid)

def respawn(userid):
try:
player = Player.from_userid(userid)
player.delay(1, player.spawn)
except ValueError:
# The userid was invalid
return


That sounds like just the thing. Thank you!