Custom params in event

Please post any questions about developing your plugin here. Please use the search function before posting!
nullable
Senior Member
Posts: 137
Joined: Sat Nov 08, 2014 7:22 pm

Custom params in event

Postby nullable » Wed Nov 12, 2014 7:19 am

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
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Wed Nov 12, 2014 7:26 am

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.
Image
nullable
Senior Member
Posts: 137
Joined: Sat Nov 08, 2014 7:22 pm

Postby nullable » Wed Nov 12, 2014 7:36 am

Hmm, var1 is printing empty string but index = 0
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Wed Nov 12, 2014 7:52 am

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.
Image
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Wed Nov 12, 2014 7:44 pm

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])
nullable
Senior Member
Posts: 137
Joined: Sat Nov 08, 2014 7:22 pm

Postby nullable » Thu Nov 13, 2014 9:14 am

I tried to use your code in an event player_activate but the same result.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Thu Nov 13, 2014 2:45 pm

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.
Image
User avatar
Doldol
Senior Member
Posts: 200
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

Postby Doldol » Thu Nov 13, 2014 3:14 pm

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.)
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Thu Nov 13, 2014 4:43 pm

It depends on what you need to do. ClientConnect, as Ayuto mentioned, allows you to disallow the player from joining.
Image
nullable
Senior Member
Posts: 137
Joined: Sat Nov 08, 2014 7:22 pm

Postby nullable » Thu Nov 13, 2014 9:04 pm

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
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Thu Nov 13, 2014 9:10 pm

player_activate doesn't have a "name" variable.

Your last line contains an error.
nullable
Senior Member
Posts: 137
Joined: Sat Nov 08, 2014 7:22 pm

Postby nullable » Thu Nov 13, 2014 9:34 pm

I mean I can't get var1 variable. Please help me to get it.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Thu Nov 13, 2014 10:52 pm

Strange, it worked for me when I tested last night, as did player_spawn.
Image
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Thu Nov 13, 2014 11:27 pm

Same, just tested the exact same code you gave on CS:S and CS:GO - works on both game.
nullable
Senior Member
Posts: 137
Joined: Sat Nov 08, 2014 7:22 pm

Postby nullable » Sun Nov 16, 2014 10:23 am

If I connect through steam the name is not override. Is it normal case?
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sun Nov 16, 2014 7:29 pm

"name" is set to the name you use in Steam and you can't change this variable. Did you use a cracked game previously?
nullable
Senior Member
Posts: 137
Joined: Sat Nov 08, 2014 7:22 pm

Postby nullable » Mon Nov 17, 2014 5:58 am

I have never used the cracked version before. The idea is to change nick after player activated. Is it possible?
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Mon Nov 17, 2014 1:59 pm

No, you can only change your name via Steam. It has been this way for a very long time.
Image

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 117 guests