Page 1 of 1

say hook and a 2 questions

Posted: Sun Dec 13, 2015 1:57 am
by decompile
Hey, im kinda starting to port es to SP and having the first troubles.

How could you create a sayhook with sp?

Code: Select all

_sayHooks = {}

def addSayHook(userid, function):
    userid = int(userid)
    if not callable(function):
        es.dbmsg(0, "ERROR: Tried to add sayhook on userid '%s' but function is not callable" % userid)
        return
    _sayHooks[userid] = function

def removeSayHook(userid):
    if userid in _sayHooks:
        del _sayHooks[userid]

def sayFilter(userid, oltext, teamonly):
    if userid in _sayHooks:
        text = oltext.strip('"')
        _fu = _sayHooks[userid]
        removeSayHook(userid)
        _fu(userid, text)
        return 0,0,0
    return userid, oltext, teamonly

@Event
def es_map_start(event):
    _sayHooks.clear()

Thats what i have written in es.

To my questions:
What is the event called which executes every time the map changes? Also how can i get the current mapname?

On Es it was es_map_start and es.ServerVar('eventscripts_currentmap')

Im sorry i didnt checked the forums/wiki too often :(

Posted: Sun Dec 13, 2015 2:08 am
by satoon101

Syntax: Select all

from listeners import OnLevelInit
from engines.server import global_vars


@OnLevelInit
def level_init(map_name):
print('Map initialized:', map_name)


def something():
print('Current map:', global_vars.map_name)


For say filters:

Syntax: Select all

from commands.say import SayFilter


@SayFilter
def say_filter(command, index, team_only):
pass

Posted: Sun Dec 13, 2015 2:21 am
by decompile
Thank you so far!

I dont know if i should do for every few questions a new thread or just create a collection thread for all of my questions but anyway i just ask that fast here:

from listeners import Tick

# Usage
# @Tick
# def <function>():


@Tick
def tick_listener():
pass


Always when i try to use that it says cannot import Tick (copy&pasted from official wiki)

Posted: Sun Dec 13, 2015 2:40 am
by satoon101
We recently changed all of the listener decorators to have the prefix "On", so it is now OnTick. The current wiki will not be the wiki going forward, so we have not been keeping it up to date. We started using Sphinx some time ago, but do not officially have a page for that setup. That should all change in the coming weeks, just not 100% sure when. For now, to use the new wiki, you can either use the following locally on your server to create the pages offline:

Code: Select all

sp docs build source-python

or use the following link:
http://build.affecta.net/job/Source.Python%20-%20Documentation/lastSuccessfulBuild/artifact/cstrike/addons/source-python/docs/source-python/build/index.html

Posted: Sun Dec 13, 2015 4:09 am
by L'In20Cible
In most case, you should avoid using a tick listener and use a hook that brings the info you need to you instead of you querying it every frame. Tell us more, I'm sure there is a better solution.

Posted: Sun Dec 13, 2015 11:21 am
by decompile
I'm not using the ticklistener for the say hook. Im just checking the userid's next message with the userid from the dict.


Thank you

Posted: Sun Dec 13, 2015 12:30 pm
by L'In20Cible
Well, I was talking in general. Tick listeners should only be used for time based tasks and will be costly if you interact with the engine (entities, players and stuff...). Since you asked about it, I thought I'd mention.