コード例 #1
0
ファイル: RollBot.py プロジェクト: prozaker/PythonBot
#!/usr/bin/env python

import random
from Credentials import botowner, botname, botpassword
from SubspaceBot import *

if __name__ == '__main__':
    bot = SubspaceBot(botowner,
                      'This bot rolls a random number between 1 and 100')
    bot.connectToServer('66.235.184.102', 7900, botname, botpassword,
                        '#python')

    print "Bot connected to server"

    roll_command_id = bot.registerCommand('!roll',
                                          'Roll a number between 1 and 100')

    while bot.isConnected():
        event = bot.waitForEvent()
        if event.type == EVENT_COMMAND:
            if event.command.id == roll_command_id:
                random_number = random.randrange(1, 101)
                bot.sendArenaMessage(event.player.name + ' rolled ' +
                                     str(random_number) + ' (1-100)')

    print "Bot disconnected"
コード例 #2
0
ファイル: RollBot-Commented.py プロジェクト: cycad/PythonBot
from Credentials import botowner, botname, botpassword

# import the SubspaceBot class. this is what has all the features we need
from SubspaceBot import *


if __name__ == '__main__':
	# initialize the bot, setting its owner and description, then connecting to the server
	bot = SubspaceBot(botowner, 'This bot rolls a random number between 1 and 100')
	bot.connectToServer('66.235.184.102', 7900, botname, botpassword, '#python')
	
	print "Bot connected to server"
	
	# register two commands, !roll and !about
	roll_command_id = bot.registerCommand('!roll', 'Roll a number between 1 and 100')
	
	# keep looping as long as the bot is connected. at each loop, pull out the next
	# even that is waiting for us to process
	while bot.isConnected():
		event = bot.waitForEvent()
		
		# based on the event type, 
		if event.type == EVENT_COMMAND:
			# based on what type of command this is, handle it accordingly
			if event.command.id == roll_command_id:
				# this command is the !roll command
				random_number = random.randrange(1, 101)
				bot.sendArenaMessage(event.player.name + ' rolled ' + str(random_number) + ' (1-100)')
		
	print "Bot disconnected"
コード例 #3
0
ファイル: KillBot.py プロジェクト: cycad/PythonBot
#!/usr/bin/env python

import random
from Credentials import botowner, botname, botpassword
from SubspaceBot import *


if __name__ == '__main__':
	bot = SubspaceBot(botowner, 'This bot announces kills to the arena')
	bot.connectToServer('66.235.184.102', 7900, botname, botpassword, '#python')
	
	print "Bot connected to server"
	
	while bot.isConnected():
		event = bot.waitForEvent()
		if event.type == EVENT_KILL:
			bot.sendArenaMessage(event.killer.name + ' killed ' + event.killed.name + '!')
		
	print "Bot disconnected"
コード例 #4
0
ファイル: PeriodicBot.py プロジェクト: cycad/PythonBot
#!/usr/bin/env python

import random
from Credentials import botowner, botname, botpassword
from SubspaceBot import *


if __name__ == '__main__':
	bot = SubspaceBot(botowner, 'This bot announces an arena message periodically')
	bot.connectToServer('66.235.184.102', 7900, botname, botpassword, '#python')
	
	print "Bot connected to server"
	
	last_arena_ticks = GetTickCountHs()
	interval = 5 * 60 * 100	# 5 minutes * 60 -> seconds, seconds * 100 -> hundreths of seconds
	
	while bot.isConnected():
		event = bot.waitForEvent()
		if event.type == EVENT_TICK:
			if (GetTickCountHs() - last_arena_ticks) & 0xFFFFFFFF >= interval:
				bot.sendArenaMessage('5 minutes have passed since the last message')
				last_arena_ticks = GetTickCountHs()
			
	print "Bot disconnected"
コード例 #5
0
ファイル: KillBot.py プロジェクト: prozaker/PythonBot
#!/usr/bin/env python

import random
from Credentials import botowner, botname, botpassword
from SubspaceBot import *

if __name__ == '__main__':
    bot = SubspaceBot(botowner, 'This bot announces kills to the arena')
    bot.connectToServer('66.235.184.102', 7900, botname, botpassword,
                        '#python')

    print "Bot connected to server"

    while bot.isConnected():
        event = bot.waitForEvent()
        if event.type == EVENT_KILL:
            bot.sendArenaMessage(event.killer.name + ' killed ' +
                                 event.killed.name + '!')

    print "Bot disconnected"
コード例 #6
0
ファイル: SpreeBot.py プロジェクト: prozaker/PythonBot
class PlayerInfo():
	def __init__(self):
		self.consecutive_kills = 0

if __name__ == '__main__':
	bot = SubspaceBot(botowner, 'This bot announces kill sprees to the arena')
	bot.connectToServer('66.235.184.102', 7900, botname, botpassword, '#python')
	
	print "Bot connected to server"
	
	while bot.isConnected():
		event = bot.waitForEvent()
		if event.type == EVENT_ENTER:
			event.player.player_info = PlayerInfo()
		if event.type == EVENT_KILL:
			# increment the killers consecutive kills and announce if its time
			p = event.killer
			pi = event.killer.player_info
			pi.consecutive_kills += 1
			if pi.consecutive_kills >= 5 and pi.consecutive_kills % 5 == 0:
				bot.sendArenaMessage(event.killer.name + ' is on a spree with ' + str(pi.consecutive_kills) + ' kills!')
			
			# announce the end of a kill-streak if the player has one, then reset the killed players consecutive kill count
			p = event.killed
			pi = event.killed.player_info
			if pi.consecutive_kills >= 5:
				bot.sendArenaMessage(p.name + '\'s ' + str(pi.consecutive_kills) + '-kill streak was ended by ' + event.killer.name + '!')
			pi.consecutive_kills = 0
		
	print "Bot disconnected"
コード例 #7
0
ファイル: ShipChangeBot.py プロジェクト: prozaker/PythonBot
#!/usr/bin/env python

import random
from Credentials import botowner, botname, botpassword
from SubspaceBot import *

if __name__ == '__main__':
    bot = SubspaceBot(botowner, 'This bot announces ship changes')
    bot.connectToServer('66.235.184.102', 7900, botname, botpassword,
                        '#python')

    print "Bot connected to server"

    while bot.isConnected():
        event = bot.waitForEvent()
        if event.type == EVENT_CHANGE:
            if event.old_ship != event.player.ship:
                bot.sendArenaMessage(event.player.name + ' changed from ' +
                                     GetShipName(event.old_ship) + ' to ' +
                                     GetShipName(event.player.ship) + '!')

    print "Bot disconnected"
コード例 #8
0
	start = Rectangle(478, 510, 483, 514)
	finish = Rectangle(541, 510, 545, 514)
	
	roll_start_id = bot.registerCommand('!race', 'Start the race')
	
	while bot.isConnected():
		event = bot.waitForEvent()
		if event.type == EVENT_ENTER:
			# initialize player info
			event.player.player_info = PlayerInfo()
		elif event.type == EVENT_POSITION_UPDATE:
			if event.player.player_info.start_ticks is None and start.containsPlayer(event.player):
				# the players start ticks is empty and hes entered the start area
				# start the race off and set his tick stamp
				event.player.player_info.start_ticks = GetTickCountHs()
				bot.sendArenaMessage('%s has started the race!' % event.player.name)
			if event.player.player_info.start_ticks is not None and finish.containsPlayer(event.player):
				# the player has a start tick stamp, and hes entered the finish area
				race_time = TickDiff(GetTickCountHs(), event.player.player_info.start_ticks) / 100.0
				bot.sendArenaMessage('%s finished the race in %f seconds!' % (event.player.name, race_time))
				# unset the tick stamp, so to start again he has to enter the start area
				event.player.player_info.start_ticks = None
		elif event.type == EVENT_COMMAND:
			if event.command.id == roll_start_id:
				bot.sendPrivateMessage(event.player, '*warpto %d %d' % beginning_warpto)
				bot.sendPrivateMessage(event.player, 'The race will start when you cross the start line')
				# unset his ticks, just in case he used the command from inside a race
				event.player.player_info.start_ticks = None
		
	print "Bot disconnected"
コード例 #9
0
ファイル: ShipChangeBot.py プロジェクト: cycad/PythonBot
#!/usr/bin/env python

import random
from Credentials import botowner, botname, botpassword
from SubspaceBot import *


if __name__ == '__main__':
	bot = SubspaceBot(botowner, 'This bot announces ship changes')
	bot.connectToServer('66.235.184.102', 7900, botname, botpassword, '#python')
	
	print "Bot connected to server"
	
	while bot.isConnected():
		event = bot.waitForEvent()
		if event.type == EVENT_CHANGE:
			if event.old_ship != event.player.ship:
				bot.sendArenaMessage(event.player.name + ' changed from ' + GetShipName(event.old_ship) + ' to ' + GetShipName(event.player.ship) + '!')
			
	print "Bot disconnected"
コード例 #10
0
ファイル: RaceBot.py プロジェクト: prozaker/PythonBot
    start = Rectangle(478, 510, 483, 514)
    finish = Rectangle(541, 510, 545, 514)

    roll_start_id = bot.registerCommand("!race", "Start the race")

    while bot.isConnected():
        event = bot.waitForEvent()
        if event.type == EVENT_ENTER:
            # initialize player info
            event.player.player_info = PlayerInfo()
        elif event.type == EVENT_POSITION_UPDATE:
            if event.player.player_info.start_ticks is None and start.containsPlayer(event.player):
                # the players start ticks is empty and hes entered the start area
                # start the race off and set his tick stamp
                event.player.player_info.start_ticks = GetTickCountHs()
                bot.sendArenaMessage("%s has started the race!" % event.player.name)
            if event.player.player_info.start_ticks is not None and finish.containsPlayer(event.player):
                # the player has a start tick stamp, and hes entered the finish area
                race_time = TickDiff(GetTickCountHs(), event.player.player_info.start_ticks) / 100.0
                bot.sendArenaMessage("%s finished the race in %f seconds!" % (event.player.name, race_time))
                # unset the tick stamp, so to start again he has to enter the start area
                event.player.player_info.start_ticks = None
        elif event.type == EVENT_COMMAND:
            if event.command.id == roll_start_id:
                bot.sendPrivateMessage(event.player, "*warpto %d %d" % beginning_warpto)
                bot.sendPrivateMessage(event.player, "The race will start when you cross the start line")
                # unset his ticks, just in case he used the command from inside a race
                event.player.player_info.start_ticks = None

    print "Bot disconnected"
コード例 #11
0
#!/usr/bin/env python

import random
from Credentials import botowner, botname, botpassword
from SubspaceBot import *

if __name__ == '__main__':
    bot = SubspaceBot(botowner,
                      'This bot announces an arena message periodically')
    bot.connectToServer('66.235.184.102', 7900, botname, botpassword,
                        '#python')

    print "Bot connected to server"

    last_arena_ticks = GetTickCountHs()
    interval = 5 * 60 * 100  # 5 minutes * 60 -> seconds, seconds * 100 -> hundreths of seconds

    while bot.isConnected():
        event = bot.waitForEvent()
        if event.type == EVENT_TICK:
            if (GetTickCountHs() - last_arena_ticks) & 0xFFFFFFFF >= interval:
                bot.sendArenaMessage(
                    '5 minutes have passed since the last message')
                last_arena_ticks = GetTickCountHs()

    print "Bot disconnected"