Created
August 30, 2010 16:51
-
-
Save jmhobbs/557668 to your computer and use it in GitHub Desktop.
The original LazerCatz bot!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Lazer Bot | |
// @author jmhobbs | |
// @version 2.2 | |
// @namespace http://www.lazercatzthegame.com/ | |
// @description a bot for Lazer Catz | |
// @include http://www.lazercatzthegame.com/* | |
// ==/UserScript== | |
var current_target = null; | |
function moveDude () { | |
var potential = { id: null, distance: 4001, offset: [0,0] }; | |
for( var id in unsafeWindow.LC.players ) { | |
if( id == unsafeWindow.LC.user.id ) { continue; } // Skip ourselves | |
if( unsafeWindow.LC.players[id].dead ) { continue; } // Skip dead users | |
var x_offset = unsafeWindow.LC.user.offset[0] - unsafeWindow.LC.players[id].offset[0], | |
y_offset = unsafeWindow.LC.user.offset[1] - unsafeWindow.LC.players[id].offset[1]; | |
var distance = Math.abs( x_offset ) + Math.abs( y_offset ); | |
if( potential.distance > distance ) { | |
potential.id = id; | |
potential.distance = distance; | |
potential.offset = [ x_offset, y_offset ]; | |
} | |
} | |
if( potential.id == null ) { | |
// Move randomly if no one is around | |
var choices = [ 'n', 's', 'e', 'w' ]; | |
if( 1 == Math.floor( Math.random() * 2 ) ) { | |
unsafeWindow.LC.moveUser( choices[Math.floor( Math.random() * 4 )] ); | |
} | |
return setTimeout( moveDude, 500 ); | |
} | |
if( current_target != potential.id ) { | |
unsafeWindow.LC.message( "LazerBot Targeting " + unsafeWindow.LC.players[potential.id].nick ); | |
current_target = potential.id; | |
} | |
if( Math.abs( x_offset ) > Math.abs( y_offset ) ) { | |
if( x_offset > 0 ) { | |
if( x_offset > 40 ) { | |
unsafeWindow.LC.moveUser( 'w' ); | |
} | |
else { | |
unsafeWindow.LC.moveUser( 'e' ); | |
} | |
} | |
else { | |
if( x_offset < -40 ) { | |
unsafeWindow.LC.moveUser( 'e' ); | |
} | |
else { | |
unsafeWindow.LC.moveUser( 'w' ); | |
} | |
} | |
} | |
else { | |
if( y_offset > 0 ) { | |
if( y_offset > 40 ) { | |
unsafeWindow.LC.moveUser( 'n' ); | |
} | |
else { | |
unsafeWindow.LC.moveUser( 's' ); | |
} | |
} | |
else { | |
if( y_offset < -40 ) { | |
unsafeWindow.LC.moveUser( 's '); | |
} | |
else { | |
unsafeWindow.LC.moveUser( 'n '); | |
} | |
} | |
} | |
if( unsafeWindow.LC.user.charge >= 10 ) { | |
unsafeWindow.LC.fire(); | |
} | |
setTimeout( moveDude, 500 ); | |
} | |
unsafeWindow.LC.startScreen.keyUp( { which: 13 } ); | |
unsafeWindow.document.getElementById( "name-input" ).value = "LazerBot-" + Math.floor( Math.random() * 1000 ); | |
unsafeWindow.LC.nameSelectScreen.keyUp( { which: 13 } ); | |
unsafeWindow.LC.characterSelectScreen.keyUp( { which: 13 } ); | |
unsafeWindow.LC.pew = { play: function () {} }; | |
unsafeWindow.LC.message( "LazerBot Ready..." ); | |
setTimeout( moveDude, 2500 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment