Page 1 of 1

kick player, send message

Posted: Fri Dec 20, 2013 12:33 am
by edcolmar
Hey Guys.

Thanks for all the help recently.

Could you give me code examples for:

how to kick a player from the server
how to send a text message to a player in the chat window

Thanks so much.

Posted: Fri Dec 20, 2013 1:51 am
by satoon101
For kicking:
http://www.sourcepython.com/showwiki.php?title=Wiki:CEngineServer#server_command

Syntax: Select all

from engine_c import CEngineServer

CEngineServer.server_command('kickid %s %s' % (userid, reason))


For SayText2 (chat area):
http://www.sourcepython.com/showwiki.php?title=Wiki:messages#SayText2

I'm not certain if that one works, though, as I never got around to testing the messaging system myself.

Satoon

Posted: Fri Dec 20, 2013 8:24 am
by Omega_K2
satoon101 wrote:For kicking:
http://www.sourcepython.com/showwiki.php?title=Wiki:CEngineServer#server_command

Syntax: Select all

from engine_c import CEngineServer

CEngineServer.server_command('kickid %s %s' % (userid, reason))


For SayText2 (chat area):
http://www.sourcepython.com/showwiki.php?title=Wiki:messages#SayText2

I'm not certain if that one works, though, as I never got around to testing the messaging system myself.

Satoon


server command needs to be terminated with a ; or \n as far as I renember, i.e.

Syntax: Select all

CEngineServer.server_command('kickid %s %s;' % (userid, reason))


Also SayText2 used to work on both engines, dunno whether any of the updates broke anything though. I posted a thread somewhere with the usermessages that don't.

Posted: Fri Dec 20, 2013 6:34 pm
by edcolmar
Working on kick...

both with and without the ";" I am seeing:

CEngineServer.server_command('kickid %s %s' % (userid, message))
Boost.Python.ArgumentError: Python argument types in
CEngineServer.server_command(str)
did not match C++ signature:
server_command(CEngineServer {lvalue}, char const* command)

Posted: Fri Dec 20, 2013 6:56 pm
by Ayuto
CEngineServer is the class object, but you need an instance of it.

Syntax: Select all

engine = engine_c.get_engine_interface()
engine.server_command('kickid %s %s;'% (userid, reason))

Posted: Fri Dec 20, 2013 7:30 pm
by edcolmar
An error occurred importing SayText2. Is there a workaround for this?

[SP] Caught an Exception:
Traceback (most recent call last):
File '../addons/source-python/packages/source-python/addons/manager.py', line 48, in __missing__
instance = _LoadedAddon(addon_name)
File '../addons/source-python/packages/source-python/addons/manager.py', line 237, in __init__
self._addon = __import__(addon_name + '.' + addon_name)
File '../addons/source-python/plugins/leetcoin/leetcoin.py', line 44, in <module>
from messages import SayText2
File '../addons/source-python/packages/source-python/messages/__init__.py', line 9, in <module>
from paths import DATA_PATH


ImportError: cannot import name DATA_PATH

Posted: Fri Dec 20, 2013 7:38 pm
by edcolmar
Thank you Ayuto. It is kicking now, but not displaying the reason, only giving a default reason.

Posted: Fri Dec 20, 2013 8:24 pm
by Ayuto
Regarding the error: you have to change all DATA_PATH occurences to SP_DATA_PATH. Take a look at this revision. I'm currenctly not sure if it's included in the latest build.

Posted: Sat Dec 21, 2013 2:23 am
by edcolmar
Thanks again Ayuto!