A few questions according for scripts

All other Source.Python topics and issues.
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

A few questions according for scripts

Postby Tuck » Sun Jul 15, 2012 5:24 pm

I've read a few topics with scripts etc,

Does all the events that were in ES apply here to? and i saw somewhere a script that imported es are there es functions implented and if so witch once ?
-Tuck
User avatar
Monday
Administrator
Posts: 98
Joined: Thu Jul 12, 2012 4:15 am

Postby Monday » Sun Jul 15, 2012 5:38 pm

We plan to provide all the events that are currently included with eventscripts. As for the es functions, we have since renamed the project to Source.Python so it will be sp now. We plan to provide libraries to mimic a lot of the es functionality in time, however we cannot guarantee that everything will be available right away.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Jul 15, 2012 5:52 pm

The script that imports es is broken. es is not a module within Source.Python.

All of the events are definitely still available. Whenever the Engine itself calls an event, Source.Python calls the function within ../addons/source-python/sp.py called "event_fire". The API then uses this to check if any modules have registered for that event, and if so, call them.

To register for an event, you can do one of 2 things. First (and highly recommended for all scripts), is to use the Event Decorator system:

Syntax: Select all

# Import the decorator class
from events.decorator import event

# Declare the function as an event
@event
def some_event_name(game_event):
print('This event just fired!!!')
Using this method, when your addon is unloaded, all instances of the "event" class within your script (including any other modules within the script) will automatically be unregistered for their given events.


The second option is using the Event Registration directly. If you choose to use this, you will need to unregister the events directly when the script is unloaded:

Syntax: Select all

from events.manager import EventRegistry

def some_event_name_function(game_event):
print('This event just fired!!!')

# Register the "some_event_name" event to the function some_event_name_function
EventRegistry.register_for_event('some_event_name', some_event_name_function)

# Unregister the event on unload
def unload():
EventRegistry.register_for_event('some_event_name', some_event_name_function)
Satoon
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Sun Jul 15, 2012 6:01 pm

What about console commands with sp ?, is there a load / reload or unload command?

And what path should i put my scripts in :/ , engines, bin, _libs, __pycache__ or another sub folder ?
-Tuck
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Jul 15, 2012 6:03 pm

Commands to load/unload/reload are:
  • sp_load <scriptname>
  • sp_unload <scriptname>
  • sp_reload <scriptname>
Using sp_load without any scriptname will print out all addons that Source.Python has loaded on the server.

The path to a script should be ../addons/source-python/<scriptname>/<scriptname>.py That is for the "main" file for the script. All other (Python) files for the given script should be within that directory as well.

Satoon
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Jul 15, 2012 6:08 pm

The "engines" folder houses all of the Python3.3 included modules. The "bin" folder houses the "core.dll" file. The "_libs" folder is where the API is going to be housed (currently already has addons and events base modules). The __pycache__ is a folder that Python creates when a Python module within that folder is loaded into memory. Python2 created compiled (.pyc) files within the original directory, which caused those directories to become very cluttered.

Satoon
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Sun Jul 15, 2012 6:40 pm

Thanks that cleared all my questions for now :)
-Tuck
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Sun Jul 15, 2012 7:14 pm

For some reason i can't get it to load or show any errors O_o

Code: Select all

def load()
    print('Plugin, Loaded.')

def unload()
    print('Plugin, Unloaded.')

def player_disconnect(ev):
    # Get the player's steam ID
    steamid = ev.GetString('networkid')
    # Set the reason to the steam ID
    ev.SetString('reason', steamid)

def player_say(ev):
    if not ev.IsEmpty('text'):
        text = ev.GetString('text')
        print('player (%s) :: \'%s\'' % (ev.GetInt('userid'), text))


Image
-Tuck
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Jul 15, 2012 8:04 pm

Well, the addon system is still a work in progress. The error is being encountered, but no message is being sent. I'll look into why that is in a few. The error you are getting is that you are missing : at the end of your load and unload functions.

Also, you might take a look again at this post:
http://www.sourcepython.com/forums/showthread.php?29-A-few-questions-according-for-scripts&p=141&viewfull=1#post141

You are not registering your events.

Satoon
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Sun Jul 15, 2012 8:14 pm

ah :) , though i just saw another script using the events without registering events, can you come with a example for player_say register?
-Tuck
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sun Jul 15, 2012 8:35 pm

Source.Python is still in developement, so some things may change with a new revision. I guess the script you saw was made before the idea with decorators. However here is an example.

Syntax: Select all

from events.decorators import event

@event
def player_say(game_event):
pass
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Jul 15, 2012 9:00 pm

Yeah, you register it the same way as the example i posted above.

Satoon
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Sun Jul 15, 2012 10:48 pm

I dont see how the core / the thing that runs the script will ever know what type of event i want since i only want the void/function to trigger when a player says something ?
Looks to me it will run on every event O_o :/
-Tuck
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Jul 15, 2012 10:58 pm

The "name" of the event is player_say. Using @event prior to a function will cause that function to be registered for the event with the same name as it. Therefor, when using:

Syntax: Select all

from events.decorator import event

@event
def player_say(game_event):
pass

We are registering the "player_say" event to call our "player_say" function. So, when the game engine calls player_say, all functions registered for the player_say event will be fired.

For a list of events within CS:S (we need to get a page going on here for CS:GO), look at this page:
http://www.eventscripts.com/pages/Category:Valve_Events

You can use any of those, as long as they are called by the engine, along with a number of new one's for CS:GO. Some of those events (like player_score and player_shoot, both of which I "believe" might work on HL2:DM) are not fired for CS:GO, so you would not want to use them.

Satoon
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Mon Jul 16, 2012 2:37 am

okay that made more sense :) , thanks
-Tuck
DreTaX14
Junior Member
Posts: 15
Joined: Fri Aug 17, 2012 5:05 pm

Postby DreTaX14 » Sat Aug 18, 2012 8:48 am

Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Sat Aug 18, 2012 8:49 am

print will only print on the console it self locally it will not be visible over hlsw

The approach u need to do is adding a run parameter to your server so it will create a log file of all thats written in the console locally :)

add "-condebug" in your startup script,
-Tuck
DreTaX14
Junior Member
Posts: 15
Joined: Fri Aug 17, 2012 5:05 pm

Postby DreTaX14 » Sat Aug 18, 2012 8:50 am

Hmm... That bad :D
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Sat Aug 18, 2012 8:53 am

-Tuck
User avatar
Monday
Administrator
Posts: 98
Joined: Thu Jul 12, 2012 4:15 am

Postby Monday » Sat Aug 18, 2012 9:00 am

You might be able to use something like this: (not sure if this will work)

Syntax: Select all

IVEngineServer.ServerCommand('echo We loaded our first addon! (Hello World!)')

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 18 guests