Page 1 of 1

Custom params in event

Posted: Wed Nov 12, 2014 7:19 am
by nullable
Hello,

How can I get custom variable from client console in connect. I mean next:
In client console I am typing:

Code: Select all

name test1; setinfo var1 test2; connect 111.111.111.111


I want to get name and var1 variables in player_connect event. How can I get them?

Syntax: Select all

from events import Event

@Event
def player_connect(game_event):
pass

Posted: Wed Nov 12, 2014 7:26 am
by satoon101

Syntax: Select all

from engines.server import engine_server
from events import Event

@Event
def player_connect(game_event):
name = game_event.get_string('name')

index = game_event.get_int('index')

var1 = engine_server.get_client_convar_value(index, 'var1')


You can also get 'name' using engine_server.get_client_convar_value, but I don't think that matters, as 'name' is an event variable in player_connect.

Posted: Wed Nov 12, 2014 7:36 am
by nullable
Hmm, var1 is printing empty string but index = 0

Posted: Wed Nov 12, 2014 7:52 am
by satoon101
Yeah, seems that player_connect is too early. I tried using the listeners.ClientConnect decorator, but I am receiving a to_python error with that, currently. Once we have that fixed, that will likely be the route you would want to take. For now, you will have to use either player_spawn (check for team=0) or player_activate.

Posted: Wed Nov 12, 2014 7:44 pm
by Ayuto
Fixed the error. https://github.com/Source-Python-Dev-Team/Source.Python/commit/cabf965e68bd69f5d1fd4ca262d04d8039cf2221

Example:

Syntax: Select all

from listeners import ClientConnect

@ClientConnect
def on_client_connect(allow_connect_ptr, player_index, player_name, ip_port,
reject_msg_ptr, max_reject_length):

# Disallow every connection
allow_connect_ptr.set_bool(False)
reject_msg_ptr.set_string_array('You shall not pass'[:max_reject_length])

Posted: Thu Nov 13, 2014 9:14 am
by nullable
I tried to use your code in an event player_activate but the same result.

Posted: Thu Nov 13, 2014 2:45 pm
by satoon101
If you mean that you just changed player_connect to player_activate, of course that wouldn't work. There is no event variable 'index' in that event. You need to get the index via the userid event variable with index_from_userid. Also, if you build a new build yourself with Ayuto's fix, you can use the ClientConnect listener.

Posted: Thu Nov 13, 2014 3:14 pm
by Doldol
satoon101 wrote:you can use the ClientConnect listener.


Why would that be preferred to player_activate? It doesn't get called on a map change and has different arguments? (And you can return False to disallow a player to join!? That's nice.)

Posted: Thu Nov 13, 2014 4:43 pm
by satoon101
It depends on what you need to do. ClientConnect, as Ayuto mentioned, allows you to disallow the player from joining.

Posted: Thu Nov 13, 2014 9:04 pm
by nullable
The same:

Syntax: Select all

@Event
def player_activate(game_event):
userid = game_event.get_int('userid')
index = index_from_userid(userid)
name = game_event.get_string('name')
print("gameevent_name: %s" % name) # Empty
name = engine_server.get_client_convar_value(index, 'name')
print("convar_name: %s" % name) # Steam account
var1 = engine_server.get_client_convar_value(index, 'var1')
print("var1: %s" % var1) # Empty

Posted: Thu Nov 13, 2014 9:10 pm
by Ayuto
player_activate doesn't have a "name" variable.

Your last line contains an error.

Posted: Thu Nov 13, 2014 9:34 pm
by nullable
I mean I can't get var1 variable. Please help me to get it.

Posted: Thu Nov 13, 2014 10:52 pm
by satoon101
Strange, it worked for me when I tested last night, as did player_spawn.

Posted: Thu Nov 13, 2014 11:27 pm
by L'In20Cible
Same, just tested the exact same code you gave on CS:S and CS:GO - works on both game.

Posted: Sun Nov 16, 2014 10:23 am
by nullable
If I connect through steam the name is not override. Is it normal case?

Posted: Sun Nov 16, 2014 7:29 pm
by Ayuto
"name" is set to the name you use in Steam and you can't change this variable. Did you use a cracked game previously?

Posted: Mon Nov 17, 2014 5:58 am
by nullable
I have never used the cracked version before. The idea is to change nick after player activated. Is it possible?

Posted: Mon Nov 17, 2014 1:59 pm
by satoon101
No, you can only change your name via Steam. It has been this way for a very long time.