|
Server Help Community forums for Subgame, ASSS, and bots
|
Author |
Message |
D1st0rt Miss Directed Wannabe
Age:36 Gender: Joined: Aug 31 2003 Posts: 2247 Location: Blacksburg, VA Offline
|
Posted: Wed Nov 09, 2005 10:55 pm Post subject: <py> turretwar |
|
|
|
|
Can somebody tell me why this fails to insmod?
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 51 time(s)
|
|
Back to top |
|
|
Grelminar Creator of Asss
Joined: Feb 26 2003 Posts: 378 Offline
|
Posted: Thu Nov 10, 2005 3:13 am Post subject: |
|
|
|
|
You spelled "asss.get_interface" wrong? There may be more, but that caught my eye.
|
|
Back to top |
|
|
Grelminar Creator of Asss
Joined: Feb 26 2003 Posts: 378 Offline
|
Posted: Thu Nov 10, 2005 3:19 am Post subject: |
|
|
|
|
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 |
|
|
Chambahs Power attack
Joined: Jun 19 2005 Posts: 820 Offline
|
Posted: Sat Nov 12, 2005 11:14 am Post subject: |
|
|
|
|
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 |
|
|
Cyan~Fire I'll count you!
Age:36 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Sun Nov 13, 2005 12:53 am Post subject: |
|
|
|
|
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 |
|
|
Chambahs Power attack
Joined: Jun 19 2005 Posts: 820 Offline
|
Posted: Sun Nov 13, 2005 1:11 am Post subject: |
|
|
|
|
i always used from asss import *
|
|
Back to top |
|
|
D1st0rt Miss Directed Wannabe
Age:36 Gender: Joined: Aug 31 2003 Posts: 2247 Location: Blacksburg, VA Offline
|
Posted: Mon Nov 14, 2005 1:31 pm Post subject: |
|
|
|
|
I changed what you said and it insmods now but won't attach
|
|
Back to top |
|
|
Cyan~Fire I'll count you!
Age:36 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Mon Nov 14, 2005 2:34 pm Post subject: |
|
|
|
|
asss.reg_callback?
|
|
Back to top |
|
|
D1st0rt Miss Directed Wannabe
Age:36 Gender: Joined: Aug 31 2003 Posts: 2247 Location: Blacksburg, VA Offline
|
Posted: Tue Nov 15, 2005 2:24 am Post subject: |
|
|
|
|
Ok, fixed it
turretwar.py - 3.75 KB
File downloaded or viewed 100 time(s)
|
|
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: 1155 page(s) served in previous 5 minutes.
|