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
python module experts?

 
Post new topic   Reply to topic Printable version
 View previous topic  Debugging deadlocks Post :: Post lvz  View next topic  
Author Message
Snuka
Newbie


Joined: Feb 28 2011
Posts: 2
Offline

PostPosted: Tue Mar 01, 2011 12:25 am    Post subject: python module experts? Reply to topic Reply with quote

Addicted to as3 now, just starting to figure things out, never worked with python before.

Decided to mess around with some soccer ball stuff. We have a goal and 4 soccer balls each with there own spawnXY in balls.conf. The first module was just to send arena message on player pick, fire, goal. The next part was a bit more challenging. The ball would respawn back to its original position if not picked up within 7 seconds. This involved setting/clearing timers, moving the ball back. Was using a tuple to pass extra params threw the timers (cool stuff), but relized it wasnt needed. useful info: http://docs.python.org/library/functions.html

The module functions without errors, but someone with more as3/python experience could maybe point out the obvious or better methods.

gball.py
Code: Show/Hide

BALL_SPAWN = (
   # x, y
   (503, 503),
   (503, 521),
   (521, 503),
   (521, 521))

from asss import *

chat = get_interface(I_CHAT)
balls = get_interface(I_BALLS)

def make_drop_timer(initial, interval, arena, bid):
    def drop_timer():
      chat.SendArenaMessage(arena, "Ball returned (not picked up within limit) - Ball ID: %s" % bid)
      move_ball(arena, bid)
    return set_timer(drop_timer, initial, interval)

def pick(arena, p, bid):
   chat.SendArenaMessage(arena, "Ball picked up by " + p.name + " - Ball ID: %s" % bid)
   arena.mytimer[bid] = None

def fire(arena, p, bid):
   chat.SendArenaMessage(arena, "Ball fired by " + p.name + " - Ball ID: %s" % bid)
   arena.mytimer[bid] = make_drop_timer(700, 0, arena, bid)   

def goal(arena, p, bid, x, y):
   chat.SendArenaSoundMessage(arena, SOUND_OOO, "Goal scored by " + p.name + " - Ball ID: %s" % bid)
   arena.mytimer[bid] = None
   
def move_ball(arena, bid):
   bd = balldata()
   bd.state = BALL_ONMAP
   bd.x = BALL_SPAWN[bid][0] * 16
   bd.y = BALL_SPAWN[bid][1] * 16
   bd.xspeed = bd.yspeed = 0
   bd.carrier = None
   bd.freq = -1
   bd.time = current_ticks()
   balls.PlaceBall(arena, bid, bd)
   
def mm_attach(arena):
   arena.cb1 = reg_callback(CB_BALLPICKUP, pick)
   arena.cb2 = reg_callback(CB_BALLFIRE, fire)
   arena.cb3 = reg_callback(CB_GOAL, goal)
   arena.mytimer = [None, None, None, None]

def mm_detach(arena):
   arena.cb1  = None
   arena.cb2  = None
   arena.cb3  = None
   arena.mytimer = [None, None, None, None]


Last edited by Snuka on Tue Mar 01, 2011 2:35 am, edited 2 times in total
Back to top
View users profile Send private message Add User to Ignore List
Snuka
Newbie


Joined: Feb 28 2011
Posts: 2
Offline

PostPosted: Tue Mar 01, 2011 12:26 am    Post subject: Reply to topic Reply with quote

On a side note, wth is the ball not placed exactly where you want it?

ex: x = y = 500

The tile number is * by 16 to get the pixel number, but is always randomly placed a little off? new_evil.gif
Back to top
View users profile Send private message Add User to Ignore List
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: 818 page(s) served in previous 5 minutes.

phpBB Created this page in 0.656906 seconds : 27 queries executed (87.0%): GZIP compression disabled