So, I'm trying to craft a bot that would basically play HnH as a wanderer (basically : no big building) without human interaction
First thing first I need to get out of the creation room.
So I change beliefs 1 time to 'peaceful'.
I change the character gender randomly.
Now I'm speaking with Germania to get a name, though I have trouble clicking the "gen" button. And I don't know how I'll press "enter" to validate the name neither...
Any help on how to interact with these particular windows would be welcome, and a sample of code would be awesome.
My code yet :
Code: Select all
//#! tooltip = Survivor
//#! name = Survivor
//#! uniq = 0000000-000000-000000-000000-SURVIV
include("jBotAPI");
function Survivor(){
//Initialisation
//Character just created, have to get its stuff, his name, and get out of creation room.
this.init = function(){
jBuyBelief("martial", 1); //Slide one time to peaceful
gender_npc = jFindObjectByName('npcs/surg',5000);
name_npc = jFindObjectByName('npcs/germania',5000);
port_npc = jFindObjectByName('npcs/sherlock',5000);
//************** Get a gender ***************//
if(!gender_npc){
return; //Character not in the creation room anymore
}
merl_tools.PFto(gender_npc);
random_gender = Math.floor((Math.random() * 2)+1); //number of clicks on NPC.
for(var i = 0; i < random_gender; i++){
gender_npc.doClick(3,0);
jSleep(500);
}
//************** Get a name ***************//
merl_tools.PFto(name_npc);
name_npc.doClick(3,0);
while(!jHaveWindow("Change Name")) jSleep(100);
}
}
var merl_tools = new function(){
this.dump = function(object){ //dump text to screen
name = '';
try{
name = object.name();
}catch(e){}
id = '';
try{
id = object.getID();
}catch(e){}
sayArea(object + ' - ' + name + ' - ' + id);
jSleep(2000);
},
this.PFto = function(item){ //move to item position using path-finding
jAbsClick(item.position(), 1, 0);
jSleep(500);
jWaitEndMove(50000);
jPFClick(item.getID());
old_distance = 9999999999;
distance = 0;
while(distance + 1 < old_distance){
old_distance = jMyCoords().dist(item.position());
item.doClick(1,0);
jPFClick(item.getID());
jSleep(2500);
distance = jMyCoords().dist(item.position());
}
jClosePopup();
if(distance > 20){
sayArea("I can't reach this place :(");
return false;
}else{
return true;
}
},
this.getClosestObjectByName = function(object_name){
var objects = jGetObjects(5000, jCoord(0,0), object_name);
min_distance = 9999999999;
current_object = false;
for(var i = 0; i < objects.length; i++){
distance = objects[i].position().dist(jMyCoords());
if(distance < min_distance){
min_distance = distance;
current_object = objects[i];
}
}
return current_object;
}
}
survivor = new Survivor();
survivor.init();