say hook and a 2 questions

Please post any questions about developing your plugin here. Please use the search function before posting!
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

say hook and a 2 questions

Postby decompile » Sun Dec 13, 2015 1:57 am

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

Postby satoon101 » Sun Dec 13, 2015 2:08 am

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
Image
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Postby decompile » Sun Dec 13, 2015 2:21 am

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

Postby satoon101 » Sun Dec 13, 2015 2:40 am

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
Image
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Sun Dec 13, 2015 4:09 am

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.
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Postby decompile » Sun Dec 13, 2015 11:21 am

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
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Sun Dec 13, 2015 12:30 pm

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.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 128 guests