 |
Server Help Community forums for Subgame, ASSS, and bots
|
Author |
Message |
-Smong- Guest
Offline
|
Posted: Sun Nov 14, 2004 5:28 pm Post subject: any python examples? |
 |
|
|
|
Can you give some examples of how to do things in Python?
Here is what I know:
# callbacks
from asss import *
chat = get_interface(I_CHAT)
def goal(arena, p, bid, x, y):
chat.SendArenaMessage(arena, "goal.")
cb1 = reg_callback(CB_GOAL, goal)
...
# commands
from asss import *
chat = get_interface(I_CHAT)
def c_mycmd(cmd, params, p, targ):
"""\
some help text
"""
chat.SendMessage(p, "moo.")
cmd1 = add_command("t1", c_mycmd) |
Here is a list of things I want to know how to do:
* attach modules
* looping players
* packet callbacks and how to read the data (like energy or weapon fired)
I'll probably add more to this thread when I think of it. |
|
Back to top |
|
 |
D1st0rt Miss Directed Wannabe

Age:37 Gender: Joined: Aug 31 2003 Posts: 2247 Location: Blacksburg, VA Offline
|
Posted: Sun Nov 14, 2004 11:13 pm Post subject: |
 |
|
|
|
how about adding python support in custom c modules? _________________
 |
|
Back to top |
|
 |
Grelminar Creator of Asss
Joined: Feb 26 2003 Posts: 378 Offline
|
Posted: Mon Nov 15, 2004 12:43 am Post subject: |
 |
|
|
|
I just started adding some of this stuff to the developer's guide last week, but I can't publish stuff for now because of sscx server problems. Here are some quick answers, but I forgot how much of this is in 1.3.2 and how much has been added since then:
To attach/detach, define fuctions:
def mm_attach(arena):
# do stuff with arena
def mm_detach(arena):
# undo stuff |
To do stuff to all players:
def blah(p):
# do stuff to p
asss.for_each_player(blah) |
asss.for_each_arena also exists. You currently can't play with raw packets from python, and there is no callback that gets called on every position packet. For most purposes, you can use CB_SAFEZONE and CB_REGION, and read the data in p.position, which is a tuple of (x, y, xspeed, yspeed, rotation, bounty, statusbits). Tell me what you want to do with position data and I'll try to figure out a good way to support it. |
|
Back to top |
|
 |
Smong Server Help Squatter

Joined: 1043048991 Posts: 0x91E Offline
|
Posted: Mon Nov 15, 2004 6:36 am Post subject: |
 |
|
|
|
Can you add python support to the objects module? This would be good for the rPYC segment or when CB_REGION support is added to python.
With the position thing I want to know when someone fires a weapon and what weapon it was. This is so I can convert my ammo module to python.
I noticed on windows with pymod loaded ctrl+c stops working.
@D1
You mean like some kind of proxy function to allow callbacks and stuff?
I think if you recompile pymod yourself it will scan your source and make the callbacks available. (I never got it to compile though). |
|
Back to top |
|
 |
D1st0rt Miss Directed Wannabe

Age:37 Gender: Joined: Aug 31 2003 Posts: 2247 Location: Blacksburg, VA Offline
|
Posted: Mon Nov 15, 2004 4:59 pm Post subject: |
 |
|
|
|
just an example of what I was getting at:
In the hyperspace package, theres an interface that deals with money, using addMoney(player,amount) or something along those lines. Is there anything you need to set up to be able to access that function in a python module? |
|
Back to top |
|
 |
-Smong- Guest
Offline
|
|
Back to top |
|
 |
Grelminar Creator of Asss
Joined: Feb 26 2003 Posts: 378 Offline
|
Posted: Tue Nov 16, 2004 12:53 am Post subject: |
 |
|
|
|
Ok, I just added support for objects, and support for mapdata/regions already exists, though I'm not sure when I'll be able to release a version with this stuff in it. And I'll try to write a little shipreset function soon.
You can use the nested stuff to return values, though it's a little messy. I think both of these will work:
# method 1
def count_players(condition):
count = [0]
def blah(p):
if condition(p):
count[0] += 1
asss.for_each_player(blah)
return count[0]
# method 2
class ConditionCounter:
def __init__(me, condition):
me.count = 0
me.condition = me.condition
def __call__(me, p):
if me.condition(p):
me.count += 1
c = ConditionCounter(condition)
asss.for_each_player(c)
# do stuff with c.count |
In the first one, count has to be a list because you can't mutate variables in anything but the innermost scope. I have an idea for making this (and similar things) easier to do (using iterators), but I don't know when I'll get to it.
About adding python support to custom C modules: this isn't as easy as I'd like it to be, but it should be possible. You have to add your own declarations in comments, and then recompile pymod. You can use the existing modules as examples of the syntax. Or try to look at pymod-process.py, which is what interprets those declarations, but I wouldn't advise that. When recompiling, your header files at least should be in the same directory as the rest of the source, or (probably a better idea) you can edit the line in the Makefile to add the directory that contains your header files. |
|
Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
Software by php BB © php BB Group Server Load: 34 page(s) served in previous 5 minutes.
|