09-07-2004, 02:50 PM
Code:
/*
njaguar's uber game creator scriptzor
Compatable with core 0.37.01+ only!
*/
// ignore these commands
var SINGLE_PLAYER=0, CLOSED_BNET=1, OPEN_BNET=3;
var NORMAL = 0, NIGHTMARE = 1, HELL = 2;
var TRUE = true, FALSE = false, True = true, False = false;
var game_type = SINGLE_PLAYER;
// end ignore
// UNCOMMENT THE BELOW LINE TO SET IT TO CONNECT TO BNET INSTEAD
game_type = CLOSED_BNET;
/***************************
CHARACTER POSITION MAP:
0 1
2 3
4 5
6 7
It's zero based, so for top left, use 0, top right use 1, etc.
****************************/
var charposition = 0;
// ENTER YOUR ACCOUNT NAME AND PASSWORD INSIDE THE QUOTES
var accountname = "***";
var accountpass = "***";
var spamChat=true;
var channel="The Void";
var gamename = "me mf-";
var gamepass = "kktx";
// SET THESE TO true IF YOU WANT TO USE RANDOM GAME NAMES OR PASSWORDS
var random_gamename = false;
var random_password = true;
//var difficulty = NORMAL;
//var difficulty = NIGHTMARE;
var difficulty = HELL;
//************ Probably don't need to go below this line.
// under construction
var charname = "Bossom-DD"; // Set this is you want it to auto pick the appropriate character
var CreateGameTimeout = 30000; // wait 30 seconds before attempting to create a new game
var GameCreateDelay = rnd(2000,3000); // wait 10 seconds between game creates
var LoginWaitTimeout = 10000; // wait 10 seconds for login to finish (connect->password dialog)
var useDDE = true; // don't use this until it's fixed in the core
// SYSTEM VARIABLES
var d2_game_types = ["Single Player", "Closed Battle.net", "", "Open Battle.net"];
var editboxes = [ [1,432,162,158,20],[1,432,217,158,20] ];
var radiobuttons = [ [6,430,381,16,16], [6,555,381,16,16], [6,698,381,16,16] ];
// CREATE and CREATE GAME
var buttons = [ [6,533,469,120,20], [6,594,433,172,32]];
var chatbox = [4,28,410,354,298];
// Join Game Selection Button
var JoinGameSelectButton = [6, 652, 469, 120, 20];
var JoinGame_ConfirmButton = [6, 594, 433, 172, 32];
var JoinGame_NamePassList = [[1, 432, 148, 155, 20], [1, 606, 148, 155, 20]];
// main menu
// single player, bnet, realm select, other multi, quit
var mainbuttons = [ [6,264,324,272,35], [6,264,366,272,35], [6,264,391,272,25], [6,264,433,272,35], [6,264,568,272,35] ];
// account, pass, login, change password, create new, exit
var bnetlogin = [ [1,322,342,162,19], [1,322,396,162,19], [6,264,484,272,35], [6,264,572,272,35], [6,264,528,272,35], [6,33,572,128,35] ];
//CANCEL 6 330 416 128 35 true false undefined
var loginDialogCancel = [6,330,416,128,35];
// char screen
var charselectrealm = [6,609,113,182,30]; // select realm button
// OK, EXIT, CREATE NEW
var charbuttons = [ [6,627,572,128,35],[6,33,572,128,35],[6,33,528,168,60] ];
// 1.09d positions
//var CharPositions = [[4,37,178,200,90],[4,309,178,200,90],[4,37,271,200,90],[4,309,271,200,90],[4,37,364,200,90],[4,309,364,200,90],[4,37,457,200,90],[4,309,457,200,90]];
var CharPositions = [[4,237,178,72,93],[4,509,178,72,93],[4,237,271,72,93],[4,509,271,72,93],[4,237,364,72,93],[4,509,364,72,93],[4,237,457,72,93],[4,509,457,72,93]];
var SP_Diffs = [[6,264,297,272,35],[6,264,340,272,35],[6,264,383,272,35]];
var total_games = 0;
var total_failed = 0;
var LastGameAttempt = 0;
var debug_mode = true;
function dprint(txt, skip_wait_for_chat) {
now = new Date();
txt = now.toLocaleString() + " : " + txt;
var f;
if(debug_mode) {
f=fileOpen("output/starter.log",2);
if(f) {
f.writeLine(txt);
// f.close();
}
}
// wait_for_controls();
// if(skip_wait_for_chat!=1) wait_for_chat_control();
if(debug_mode) {
// f=fileOpen("output/starter.log",2);
if(f) {
// f.writeLine("wait_for_chat_controls() finished");
f.close();
}
}
print(txt);
if(useDDE) sendDDE(1,"mIRC","command","","/echo 4 [color=#00ff00]d2jsp[/color] " + txt);
}
function findControl(arr) {
return getControl(arr[0],arr[1],arr[2],arr[3],arr[4]);
}
function ChooseCharacter() {
dprint("We're at the char select screen. Choosing character for " + d2_game_types[game_type] + ".",1);
delay( (game_type==SINGLE_PLAYER ? 500 : 3000) );
// load('tools/dumpcontrols.d2j');
if(!find_and_click_control(CharPositions[charposition])) return false;
if(!find_and_click_control(charbuttons[0])) return false;
}
function ChooseOnlineOffline() {
if(game_type == CLOSED_BNET) {
dprint("We're on the main menu, logging in to battle.net", 1);
if(!find_and_click_control(mainbuttons[CLOSED_BNET])) return false;
// while(!findControl(bnetlogin[0])) dprint("waiting..",1);
// delay(3000);
// while(!findControl(bnetlogin[0])) load('tools/dumpcontrols.d2j');
}
if(game_type == SINGLE_PLAYER) {
dprint("We're on the main menu, choosing single player",1);
if(!find_and_click_control(mainbuttons[SINGLE_PLAYER])) return false;
}
if(game_type == OPEN_BNET) {
dprint("We're on the main menu, choosing open bnet",1);
if(!find_and_click_control(mainbuttons[OPEN_BNET])) return false;
// stop();
}
}
function findLocation() {
// we're on chat, proceed.
if(findControl(chatbox)) {
return true;
}
if(findControl(mainbuttons[0])) { // main menu (single player)
ChooseOnlineOffline();
return false;
}
if(findControl(bnetlogin[0])) {
ctr=0;
while(findControl(loginDialogCancel)) {
if(ctr>LoginWaitTimeout/10) {
find_and_click_control(loginDialogCancel);
return false;
}
ctr++;
delay(10);
}
dprint("We're at the bnet login page. Logging in.",1);
if(!find_control_and_set_text(bnetlogin[0], accountname)) return false;
if(!find_control_and_set_text(bnetlogin[1], accountpass)) return false;
delay(1000);
if(!find_and_click_control(bnetlogin[2])) return false;
}
if(findControl(SP_Diffs[0])) {
if(game_type == SINGLE_PLAYER) {
dprint("Selecting Single Player Difficulty.",1);
if(!find_and_click_control(SP_Diffs[difficulty])) return false;
} else {
// SANITY CHECK! GET BACK TO MAIN MENU!
}
return false;
}
if(findControl(charbuttons[2])) {
ChooseCharacter();
return false;
}
if(!me.ingame) {
dprint("in unknown location in findLocation()...",1);
// load("tools/dumpcontrols.d2j");
}
return false;
}
function keypressHandler(key) {
dprint("got key event: " + key);
}
function main() {
var LastGameStarted = -1;
delay(3000);
while(!findLocation()) delay(1000);
// first time on bnet, so...
dprint("Successfully logged onto battle.net.");
dprint("Starting game creations.");
// clickLadder();
if(spamChat)
enterChat();
while(1) {
LastGameStarted = me.gamestarttime;
if(createGame(gamename + (++total_games), gamepass)) {
game_failed = false;
while(!me.ingame) {
now = getTickCount();
if(now - LastGameAttempt > CreateGameTimeout && me.gamestarttime==LastGameStarted) {
dprint("Last Game Creation timed out. Attempting to create another game in 10 seconds.");
total_failed++;
game_failed = true;
delay(10000);
break;
} else {
delay(500);
}
}
if(!game_failed) {
while(me.ingame) { // we're in game now, wait till we leave the game.
delay(500);
}
now = getTickCount();
dprint("Game End Detected! Elapsed time: " + ((now-LastGameAttempt)/1000) + " seconds");
dprint("Waiting " + (GameCreateDelay/1000) + " seconds before starting next game.");
delay(GameCreateDelay);
if(spamChat)
enterChat();
}
} else {
// dprint("Failed to find a control for game creation. Waiting 10 seconds and trying again.");
dprint("Failed to find a control for game creation. Will attempt to find location in 10 seconds.");
delay(10000);
while(!findLocation()) delay(1000);
}
// run the garbage collector each run just in case...
runGC();
// delay after the garbage collector for slower machines to let memory repage itself
delay(500);
}
}
function wait_for_chat_control() {
while(!getControl(chatbox[0],chatbox[1],chatbox[2],chatbox[3],chatbox[4])) delay(50);
}
/*
function wait_for_controls(timeout) {
if(isNaN(timeout)) timeout=30000; // default to 30 seconds timeout
i=0;
while(!getControl() && i++<100) delay(50);
}
*/
function createGame(name, pass) {
// total_games++;
if(random_gamename) name = TDW_BASIC_GetRandomString(rnd(4,15));
if(random_password) pass = TDW_BASIC_GetRandomString(rnd(4,15));
delay(1000);
// added delays back in due to crashes on some machines
if(!find_and_click_control(buttons[0])) return false;
delay(100);
if(!find_control_and_set_text(editboxes[0], name)) return false;
delay(100);
if(!find_control_and_set_text(editboxes[1], pass)) return false;
delay(100);
if(!find_and_click_control(radiobuttons[difficulty])) return false;
delay(100);
if(!find_and_click_control(buttons[1])) return false;
LastGameAttempt = getTickCount();
dprint("Game #" + total_games + " Created, " + total_failed + " fails so far. Now waiting for game to start...");
return true;
}
// function from TDW
function JoinGame(name, pass) {
if(!find_and_click_control(JoinGameSelectButton)) return false;
delay(500);
if(!find_control_and_set_text(JoinGame_NamePassList[0], name)) return false;
delay(500);
if ((pass != null) && (pass != "")) {
if (!find_control_and_set_text(JoinGame_NamePassList[1], pass))
return false;
delay(500);
}
if(!find_and_click_control(JoinGame_ConfirmButton)) return false;
LastGameAttempt = getTickCount();
dprint("Game Joined, now waiting for game entry to complete...");
return true;
}
function find_and_click_control(arr) {
if((control = find_control_by_properties(arr)) != null) {
control.click();
return true;
}
return false;
}
function find_control_and_set_text(arr, str) {
if((control = find_control_by_properties(arr)) != null) {
control.setText(str);
return true;
}
return false;
}
function find_control_by_properties(arr) {
control = getControl(arr[0],arr[1],arr[2],arr[3],arr[4]);
// if(control) do {
// if(control.type==arr[0] && control.x==arr[1] && control.y==arr[2] && control.xsize==arr[3] && control.ysize==arr[4]) return control;
// } while(control.getNext());
return control; //0;
}
function find_control_by_name(str) {
control = getControl();
if(control) do {
if(control.text == str) return control;
} while(control.getNext());
return 0;
}
function clickLadder() {
c = find_control_by_name("LADDER");
if(c) {
c.click();
delay(100);
c = find_control_by_name("EXPANSION HARDCORE LADDER");
if(c) {
c.click();
} else {
print("Could not find EXPANSION HARDCORE LADDER button.");
}
} else {
print("Could not find LADDER button.");
}
}
/////ADDED BY BOB102//////////
function enterChat() {
c = find_control_by_name("ENTER CHAT");
if(c) {
c.click();
delay(1000);
say("/join "+channel);
delay(500);
for(a=0;a<3;a++)
{
random_words = TDW_BASIC_GetRandomString(rnd(4,15));
say(random_words);
delay(500);
}
} else {
print("Could not enter chat.");
}
}
///////////////////////////////
//Server Down 4 438 300 326 150 false false Server Down
// RANDOM NAME GENERATOR BY TheDesertWind (thanks!)
// ////////////////////////////////////////////////////////////////////////////
function TDW_BASIC_GetRandomString(out_length, char_set_string)
{
if (out_length < 1)
return("");
char_set_string = (TDW_BASIC_GEN_TypeOfStringNotEmpty(char_set_string)) ?
char_set_string :
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var out_string = "";
for ( ; out_length; out_length--)
out_string += char_set_string.charAt(rnd(0, char_set_string.length - 1));
return(out_string);
}
// ////////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////////
function TDW_BASIC_GetRandomStringLower(out_length)
{
return(TDW_BASIC_GetRandomString(out_length, "abcdefghijklmnopqrstuvwxyz"));
}
// ////////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////////
function TDW_BASIC_GetRandomStringUpper(out_length)
{
return(TDW_BASIC_GetRandomString(out_length, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
}
// ////////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////////
function TDW_BASIC_GetRandomStringDigits(out_length)
{
return(TDW_BASIC_GetRandomString(out_length, "0123456789"));
}
// ////////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////////
function TDW_BASIC_GEN_TypeOfStringNotEmpty(in_data)
{
return((TDW_BASIC_GEN_TypeOfString(in_data) && (in_data != "")) ?
true : false);
}
// ////////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////////
function TDW_BASIC_GEN_TypeOfString(in_data)
{
return(((in_data instanceof String) || (typeof(in_data) == "string")) ?
true : false);
}
// ////////////////////////////////////////////////////////////////////////////
Null