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
<py> turretwar

 
Post new topic   Reply to topic Printable version
 View previous topic  MySQL module in PY Post :: Post Would it be possible for staff to caus...  View next topic  
Author Message
D1st0rt
Miss Directed Wannabe


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

PostPosted: Wed Nov 09, 2005 10:55 pm    Post subject: <py> turretwar Reply to topic Reply with quote

Can somebody tell me why this fails to insmod?

Code: Show/Hide
import asss

chat = asss.getInterface(asss.I_CHAT)
game = asss.getInterface(asss.I_GAME)

#############
# callbacks #
#############

def kill(arena, killer, killed, bty, flags, pts, green):
    pts = scores.get(killer, 0)
    pts += bty   
    scores[killer] = pts
   
def shipchange(p, ship, freq):
    if ship == asss.SHIP_LANCASTER and p.name not in tw_caps:
        game.SetShip(p, asss.SHIP_SPIDER)

############
# commands #
############

def c_start(tc, params, p, target):
    """\
Module: turretwar
Targets: none
Args: none
Starts a new TurretWar game
    """
    a.tw_scores.clear()       
    chat.SendArenaSoundMessage(p.arena, 104, "GOGOGOGOGOOOOOO!")
   
def c_addcap(tc, params, p, target):
    """\
Module: turretwar
Targets: Player
Args: none
Starts a new TurretWar game
    """
    if type(target) == asss.PlayerType:
        if target.p.name not in a.tw_caps:
            a.tw_caps.add(target.p.name)
            game.SetShip(target.p, asss.SHIP_LANCASTER)
        else:
            a.tw_caps.remove(target.p.name)
            game.SetShip(target.p, asss.SHIP_SPIDER)

def c_score(tc, params, p, target):
    """\
Module: turretwar
Targets: none
Args: none
Displays current TurretWar game score
    """
    freq = [0, 0]
    for s in a.tw_scores.keys():
        freq[s.freq] += a.tw_scores[s]

    chat.SendArenaMessage(p.arena, "Scores: Team 0="+ freq[0] +"Team 1="+ freq[1])

def c_end(tc, params, p, target):
    """\
Module: turretwar   
Target: none
Args: none
Ends the current game of TurretWar
    """
    freq = [0, 0]
    mvp = p
    mvpscore = 0
    chat.SendArenaMessage(p.arena, "Game Over!")
    chat.SendArenaMessage(p.arena, "-------------------------------------")
    chat.SendArenaMessage(p.arena, "Player Scores:")
    for s in a.tw_scores.keys():
        score = a.tw_scores[s]
        if score > mvpscore:
            mvp = s
            mvpscore = score
        freq[s.freq] += score
        chat.SendArenaMessage(p.arena, s.name +"("+ s.freq +") - "+ score)
    chat.SendArenaMessage(p.arena, "-------------------------------------")
    chat.SendArenaMessage(p.arena, "Team Scores:")
    for x in range(2):
        chat.SendArenaMessage(p.arena, "Team "+ x +" - "+ freq[x])
    chat.SendArenaMessage(p.arena, "-------------------------------------")
    if freq[0] > freq[1]:
        chat.SendArenaMessage(p.arena, "Team 0 Wins!")
    elif freq[1] > freq[0]:
        chat.SendArenaMessage(p.arena, "Team 1 Wins!")
    else:
        chat.SendArenaMessage(p.arena, "OMG TIE!")
    chat.SendArenaMessage(p.arena, "MVP: "+ mvp.name)

#############
# attaching #
#############

def mm_attach(a):
    #commands
    a.tw_Cstart = asss.add_command("start", c_start, a)
    a.tw_Csetcap = asss.add_command("addcap", c_addcap, a)
    a.tw_Cscore = asss.add_command("score", c_score, a)
    a.tw_Cend = asss.add_command("end", c_end, a)
   
    #callbacks
    cb1 = reg_callback(CB_KILL, kill)
    cb2 = reg_callback(CB_SHIPCHANGE, shipchange)
   
    #data
    a.tw_caps = []
    a.tw_freq0 = []
    a.tw_freq1 = []
    a.tw_scores = {'key':'value'}
   
def mm_detach(a):
        for attr in ['Cstart', 'Csetcap', 'caps', 'scores', 'Cscore', 'Cend',
                     'freq0', 'freq1']:
            try: delattr(a, 'tw_' + attr)
            except: pass
               

_________________





turretwar.py.txt - 3.38 KB
File downloaded or viewed 43 time(s)
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: Thu Nov 10, 2005 3:13 am    Post subject: Reply to topic Reply with quote

You spelled "asss.get_interface" wrong? There may be more, but that caught my eye.
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website
Grelminar
Creator of Asss


Joined: Feb 26 2003
Posts: 378
Offline

PostPosted: Thu Nov 10, 2005 3:19 am    Post subject: Reply to topic Reply with quote

More: "target.p" isn't going to work. If target is a player, then just use it as a player. The ugly Target union stuff in C isn't used in Python.

cb1 and cb2 in mm_attach are local variables, and thus will get deleted at the end of the function. Either register arena-specific callbacks and put the references in the arena object, or register global callbacks, and have the references be global variables.

The shipchange thing could be implemented with a freqmanager, but I guess the callback is simpler.
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website
Chambahs
Power attack
Power attack


Joined: Jun 19 2005
Posts: 820
Offline

PostPosted: Sat Nov 12, 2005 11:14 am    Post subject: Reply to topic Reply with quote

chat = asss.getInterface(asss.I_CHAT)
game = asss.getInterface(asss.I_GAME)


is it from me not trying to code in python since 1.3.5. or is it that the coding changed, but do you have to use that asss. in front of everything? i never did
Back to top
View users profile Send private message Add User to Ignore List
Cyan~Fire
I'll count you!
I'll count you!


Age:36
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Sun Nov 13, 2005 12:53 am    Post subject: Reply to topic Reply with quote

It depends on whether you use "import asss" or "from asss import *" I think.
_________________
This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Chambahs
Power attack
Power attack


Joined: Jun 19 2005
Posts: 820
Offline

PostPosted: Sun Nov 13, 2005 1:11 am    Post subject: Reply to topic Reply with quote

i always used from asss import *
Back to top
View users profile Send private message Add User to Ignore List
D1st0rt
Miss Directed Wannabe


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

PostPosted: Mon Nov 14, 2005 1:31 pm    Post subject: Reply to topic Reply with quote

I changed what you said and it insmods now but won't attach icon_sad.gif
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Cyan~Fire
I'll count you!
I'll count you!


Age:36
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Mon Nov 14, 2005 2:34 pm    Post subject: Reply to topic Reply with quote

asss.reg_callback?
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
D1st0rt
Miss Directed Wannabe


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

PostPosted: Tue Nov 15, 2005 2:24 am    Post subject: Reply to topic Reply with quote

Ok, fixed it biggrin.gif



turretwar.py - 3.75 KB
File downloaded or viewed 96 time(s)
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> ASSS Custom Projects 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: 632 page(s) served in previous 5 minutes.

phpBB Created this page in 0.698156 seconds : 36 queries executed (86.3%): GZIP compression disabled