Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
any python examples?

 
Post new topic   Reply to topic Printable version
 View previous topic  undefined reference Post :: Post SetFreq  View next topic  
Author Message
-Smong-
Guest


Offline

PostPosted: Sun Nov 14, 2004 5:28 pm    Post subject: any python examples? Reply to topic Reply with quote

Can you give some examples of how to do things in Python?
Here is what I know:
Code: Show/Hide
# 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:Gender:Male
Joined: Aug 31 2003
Posts: 2247
Location: Blacksburg, VA
Offline

PostPosted: Sun Nov 14, 2004 11:13 pm    Post subject: Reply to topic Reply with quote

how about adding python support in custom c modules?
_________________

Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Grelminar
Creator of Asss


Joined: Feb 26 2003
Posts: 378
Offline

PostPosted: Mon Nov 15, 2004 12:43 am    Post subject: Reply to topic Reply with quote

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:

Code: Show/Hide
def mm_attach(arena):
    # do stuff with arena
def mm_detach(arena):
    # undo stuff


To do stuff to all players:
Code: Show/Hide
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
View users profile Send private message Add User to Ignore List Send email Visit posters website
Smong
Server Help Squatter


Joined: 1043048991
Posts: 0x91E
Offline

PostPosted: Mon Nov 15, 2004 6:36 am    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Visit posters website MSN Messenger
D1st0rt
Miss Directed Wannabe


Age:37
Gender:Gender:Male
Joined: Aug 31 2003
Posts: 2247
Location: Blacksburg, VA
Offline

PostPosted: Mon Nov 15, 2004 4:59 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Visit posters website
-Smong-
Guest


Offline

PostPosted: Mon Nov 15, 2004 5:35 pm    Post subject: Reply to topic Reply with quote

Just look at the other header files. Looks something like:
Code: Show/Hide
typedef struct Imoney
{
...
   void (*addMoney)(Player *player, int amount);
   /* pyint: player, int -> void */
...
}


Something you can't do without net is sending shipreset, can you make an interface for that please?

And with the for for_each_player(func), do you use that nested magic to return stuff? Suppose I wanted to count the number of players that had a certain thing in their per player data.
Back to top
Grelminar
Creator of Asss


Joined: Feb 26 2003
Posts: 378
Offline

PostPosted: Tue Nov 16, 2004 12:53 am    Post subject: Reply to topic Reply with quote

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:
Code: Show/Hide
# 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
View users profile Send private message Add User to Ignore List Send email Visit posters website
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> ASSS Questions All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
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
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 34 page(s) served in previous 5 minutes.

phpBB Created this page in 0.522095 seconds : 32 queries executed (91.2%): GZIP compression disabled