I just started learning writing scripts and if anyone's interested I made a script which automates the crafting of straw dolls.
It takes straw from one cupboard, plant fibres from another, crafts the straw doll and puts it in a third cupboard.
It's one of the first scripts I've written so I'd really appreciate any suggestions.
It uses "jBotAPI" and "jPFAPI" ("jPFAPI" is a pathfinding tool I found posted earlier in this thread but I'll repost it here)
Straw doll automation
- Code: Select all
//#! name = Straw Dolls
//#! icon = gfx/invobjs/strawdoll
//#! uniq = strawDollsAutomation
//By Strandmullen
include ("jPFAPI");
include ("jBotAPI");
var inventory = checkInventory();
var strawContainer = jSelectObject("Select straw cupboard");
var plantFibresContainer = jSelectObject("Select plant fibres cupboard");
var strawDollContainer = jSelectObject("Select straw doll cupboard");
var strawNeeded = 4;
var plantFibresNeeded = 2;
var quit;
function getStraw(){
jPFMoveOffset_LX(strawContainer.position(), 1);
waitPFEndMove();
jDoClick(strawContainer.getID(), 3);
jWaitMove();
jWaitWindow("Cupboard");
var strawInventory = jGetWindow("Cupboard").getInventories()[0];
all = strawInventory.getItems("straw");
for (var i = 0; i < strawNeeded; i++){
one = all[i];
one.transfer();
jSleep(100);
}
}
function getPlantFibres(){
jPFMoveOffset_LX(plantFibresContainer.position(), 1);
waitPFEndMove();
jDoClick(plantFibresContainer.getID(), 3);
jWaitMove();
jWaitWindow("Cupboard");
var plantFibresInventory = jGetWindow("Cupboard").getInventories()[0];
all = plantFibresInventory.getItems("flaxfibre");
for (var i = 0; i < plantFibresNeeded; i++) {
one = all[i];
one.transfer();
jSleep(100);
}
}
function craftStrawDolls(){
jSendDoubleAction("craft", "strawdoll");
jSleep(500);
if (jIsCraftReady()) {
jCraftItem(false);
jWaitProgress();
} else {
quit = true;
}
}
function storeStrawDolls(){
inventory = checkInventory();
strawDolls = inventory.getItems("strawdoll");
strawDoll = strawDolls[0];
jPFMoveOffset_LX(strawDollContainer.position(), 1);
waitPFEndMove();
jDoClick(strawDollContainer.getID(), 3);
jWaitMove();
jWaitWindow("Cupboard");
strawDoll.transfer();
}
function main(){
while (true){
getStraw();
getPlantFibres();
craftStrawDolls();
storeStrawDolls();
}
}
main();
jPFAPI
- Code: Select all
/* |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| */
/* |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| */
/* |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| */
//LeksarPathfinder
function _pf_click(id) {
if (!jIsPathFree(jGob(id))) {
resetCursor();
if (jPFClick(id) > 0) {
if (jWaitStartMove(1000)) {
waitPFEndMove();
while (jIsMoving() || jMyCoords().dist(jObjectPos(id)) > 33) {
jSleep(100);
}
return true;
}
}
}
return false;
}
function getRandomArbitary(min, max)
{
return Math.random() * (max - min) + min;
}
function jPFMove_LX(point) {
point = jTilify(point);
var MyX = jMyCoords().x;
var MyY = jMyCoords().y;
jPFMove(point);
cycles = 0;
while (MyX != point.x || MyY != point.y)
{
jPrint("jPFMove_LX My =" + MyX + " " + MyY + " - " + point.x + " " + point.y);
jSleep(1000);
MyX = jMyCoords().x;
MyY = jMyCoords().y;
if(cycles == 10)
{
jPrint("jPFMove_LX trying to move again");
jOffsetClick(jCoord(getRandomArbitary(-2,2),getRandomArbitary(-2,2)),1,0);
jSleep(500);
jPFMove(point);
cycles = 0
}
cycles++;
}
jPrint("jPFMove ended");
}
function jPFMoveOffset_LX(point, offset) {
offsMoveS=jCoord(0,offset);
offsMoveE=jCoord(offset,0);
offsMoveW=jCoord(-offset,0);
offsMoveN=jCoord(0,-offset);
while (1) {
if(jPFMove(point.add(offsMoveS.mul(11))) > 0) {
jPFMove_LX(point.add(offsMoveS.mul(11)));
return offsMoveS;
}
if(jPFMove(point.add(offsMoveE.mul(11))) > 0) {
jPFMove_LX(point.add(offsMoveE.mul(11)));
return offsMoveE;
}
if(jPFMove(point.add(offsMoveW.mul(11))) > 0) {
jPFMove_LX(point.add(offsMoveW.mul(11)));
return offsMoveW;
}
if(jPFMove(point.add(offsMoveN.mul(11))) > 0) {
jPFMove_LX(point.add(offsMoveN.mul(11)));
return offsMoveN;
}
jPrint("jPFMoveOffset_LX can't find path");
// break;
jOffsetClick(jCoord(getRandomArbitary(-2,2),getRandomArbitary(-2,2)),1,0);
jSleep(500);
}
}
function waitPFEndMove(){
jWaitStartMove(300);
jSleep(100);
while (true) {
jWaitEndMove(10000);
jSleep(200);
if (!jIsMoving()) {
return;
}
}
}