Is client in game

All other Source.Python topics and issues.
ghetto_life
Junior Member
Posts: 15
Joined: Fri Aug 26, 2022 11:06 pm

Is client in game

Postby ghetto_life » Fri Aug 26, 2022 11:36 pm

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?
User avatar
Articha
Member
Posts: 32
Joined: Tue Sep 21, 2021 12:13 pm
Location: Russia

Postby Articha » Sat Aug 27, 2022 6:57 pm

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
ghetto_life
Junior Member
Posts: 15
Joined: Fri Aug 26, 2022 11:06 pm

Re: Is client in game

Postby ghetto_life » Sun Aug 28, 2022 9:02 am

For example select a random player and spawn him. If the player is not yet in the game - there will be an error.
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: Is client in game

Postby cssbestrpg » Sun Aug 28, 2022 10:21 am

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
ghetto_life
Junior Member
Posts: 15
Joined: Fri Aug 26, 2022 11:06 pm

Re: Is client in game

Postby ghetto_life » Sun Aug 28, 2022 10:31 am

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!

Return to “General Discussion”

Who is online

Users browsing this forum: Bing [Bot] and 21 guests