Prime - Amber Tweaks and Scripting API

Forum for alternative clients, mods & discussions on the same.

Re: Prime - Amber Tweaks and Scripting API

Postby mentokeep » Wed Jan 04, 2017 4:00 pm

Bugreport:
Code: Select all
Can't find method haven.OCache.getgob(org.mozilla.javascript.Undefined).

when pfClick is invoked in my script. Error occurs on 0.3, on 0.2 it works fine.

UPD: my bad, edited to reflect last changes in API, now works ok.
mentokeep
 
Posts: 3
Joined: Mon Dec 19, 2016 10:11 pm

Re: Prime - Amber Tweaks and Scripting API

Postby Paradoxs » Wed Jan 04, 2017 8:53 pm

Odd I didn't think I changed the implementation of pfClick
User avatar
Paradoxs
 
Posts: 294
Joined: Tue Aug 25, 2015 7:16 am

Re: Prime - Amber Tweaks and Scripting API

Postby LostJustice » Thu Jan 05, 2017 12:49 am

mentokeep wrote:
Paradoxs wrote:
mentokeep wrote:Some reports from linux :)

One more thing: if scripts folder name like in release archive -- on linux no scripts is seen inside client, but if rename to Scripts (with frist uppercase S) -- scripts apears in client. I think on windows no differences on filepaths and scripts dir name also works fine, but not on unix-capable.


I noticed this too and its been fixed for the latest release (which will be uploaded within an hour)

As far as your issues with run.sh, its odd because I simply put an amber release file in it, so there shouldn't be a difference. I'll grab a new one to see if that fixes it


Still broken run.sh file. In release 0.3 of prime its 117 bytes (like before), in amber release its 115 bytes. You can see diff -u for this two files btw.


The reason this happens is because in windows, there is a next line symbol which linux interprets as ^M causing the file to be invalid. So to fix this, simply just open the file in linux as is, copy what you see into a different file exactly as you see it without the ^M and then save it as a .sh file. Then it will work. Otherwise, from a window's perspective, make sure you make the file run from either all one line or use an editor that uses a universal new line, like notepad++.
Image
User avatar
LostJustice
 
Posts: 677
Joined: Sun Mar 25, 2012 3:57 am

Re: Prime - Amber Tweaks and Scripting API

Postby deboon » Thu Jan 05, 2017 2:46 pm

LostJustice wrote:The reason this happens is because in windows, there is a next line symbol which linux interprets as ^M causing the file to be invalid. So to fix this, simply just open the file in linux as is, copy what you see into a different file exactly as you see it without the ^M and then save it as a .sh file. Then it will work. Otherwise, from a window's perspective, make sure you make the file run from either all one line or use an editor that uses a universal new line, like notepad++.


Yes, I fixed somehow like this. More correct info can be found here, for example. I am just want this will be fixed on upstream (in release archive).

P.S. previous comments was mine, alts account :)
deboon
 
Posts: 15
Joined: Tue Aug 30, 2011 6:59 am

Re: Prime - Amber Tweaks and Scripting API

Postby Paradoxs » Thu Jan 05, 2017 6:51 pm

deboon wrote:
LostJustice wrote:The reason this happens is because in windows, there is a next line symbol which linux interprets as ^M causing the file to be invalid. So to fix this, simply just open the file in linux as is, copy what you see into a different file exactly as you see it without the ^M and then save it as a .sh file. Then it will work. Otherwise, from a window's perspective, make sure you make the file run from either all one line or use an editor that uses a universal new line, like notepad++.


Yes, I fixed somehow like this. More correct info can be found here, for example. I am just want this will be fixed on upstream (in release archive).

P.S. previous comments was mine, alts account :)


Yea I forgot to change my upload copy. I added it to my change-notes so that I don't forget
User avatar
Paradoxs
 
Posts: 294
Joined: Tue Aug 25, 2015 7:16 am

Re: Prime - Amber Tweaks and Scripting API

Postby Robben_DuMarsch » Thu Jan 05, 2017 8:22 pm

Thanks a lot for your work, Paradoxs.
You're keeping the playing field somewhat even for those of us without people in our group willing or able to customize a client and write an API themselves.
User avatar
Robben_DuMarsch
 
Posts: 2301
Joined: Wed Sep 28, 2011 2:58 am

API Revision 0.3.1

Postby Paradoxs » Thu Jan 05, 2017 11:26 pm

Api Revision 0.3.1 Download it here: https://raw.githubusercontent.com/TimothyCates/PrimeAPI/master/API.js

Added functions to deal with lag by waiting for windows and flower menus. All timeouts are optional and default at 10 seconds to prevent runaway threads

Fixed
    useItem
    Fixed bug in useItem where passing a MapObject did not work as intended due to a misnamed variable

Added
    barrelType(MapObject)
    if the passed object is a barrel return its contents

    waitForWindow(WindowName, Timeout)
    Waits for the window with WindowName to appear or for Timeout milliseconds before continuing. Returns true if window found otherwise false

    isMoving())
    isMoving was accidentally remove in the release of 0.3, this adds it back in

    waitForFlower(Timeout)
    Waits for the flower menu to appear or for Timeout milliseconds before continuing. Returns true if flower menu found otherwise false

    closeFlower()
    if a flower menu is open, close it

    closeWindow(Name)
    if a window with Name is open, close it

    getFlowerOptions()
    returns a string of the flower menu options if one is found otherwise false

    flowerHasOption(Option)
    returns true if a open flower menu has Option otherwise false

    startSurvey()
    if a land survey window is open, it will begin surveying

    RemoveSurvey()
    if a land survey window is open, it will remove the surbey

User avatar
Paradoxs
 
Posts: 294
Joined: Tue Aug 25, 2015 7:16 am

Example Script - Ambers Auto leveler 2.0

Postby Paradoxs » Fri Jan 06, 2017 12:12 pm

Since I know it can be a pain to figure out how the API comes together and can be used in a piece of script for new scripters. Heres a semi-advanced example. I'll expand the examples this weekend, and fix this terribly rough one up later

Its an auto-leveler. It uses any and all dirt pile in the area, any and all water barrels in the area, and a waterflask to refill via barrels. Its a rough example, it makes mistakes here and there, drops dirt on the ground, but overall gets the job done. removes full stockpiles from its list, and detects low energy to end the bot. I'd say you could use it to get an idea of how to make a decent leveler-bot and with some time (30 mins maybe) fix all its bugs and improve it ten fold. But I'm going to bed for the night so I'll leave it to this weekend for that

You will need to update your API at the github above, I had to re-add getEnergy() when making this script, it appears it was missed in the revision and in the update to an external API

Code: Select all
var WaterBarrels = [];
var Survey = null;
var Startup = true;
var Stockpiles = [];


function main(){
    if(Startup) {
        getBarrels();
        getSurvey();
        getStockpiles();
        Startup = false;
    }
    while(Survey != null){
        while(getStamina() > 30 && getEnergy() > 55){
            DoSurvey();
            if(!hasHand()){
                sleep(1000);
                while(Prime.__GameUI.prog >= 0)
                    Prime.sleep(10);
            }else{
                drop("soil");
                sleep(500);
                fillPile();
            }
        }
        if(getStamina() < 100)
            doDrink();
        if(getEnergy() < 55) {
            Survey = null;
            print("Not enough Energy");
        }
    }

    print("Survey Done");
    exit();
}

function getSurvey(){
    var Surveys = getMapObjects("survobj");
    if(Surveys.length == 0) {
        print("No Surveys, exiting");
        exit();
    }
    Survey = Surveys[0];
}

function fillPile(){
    pfClick(Stockpiles[0], MouseButton.Right);
    waitForTask();
    while(hasItem("soil")) {
        pfClick(Stockpiles[0], MouseButton.Right);
        waitForWindow("Stockpile");
        if(getStockpile().Current == getStockpile().Max) {
            UpdateStockpile();
            closeWindow("Stockpile");
        }else{
            if (!hasHand())
                take("soil");
            sleep(500);
            useItem(Stockpiles[0]);
        }
    }
    useItem(Stockpiles[0]);
    sleep(500);
    drop("soil");
}

function UpdateStockpile(){
    var newStockpiles = [];
    for(var Index = 1; Index < Stockpiles.length ; Index++){
        newStockpiles.push(Stockpiles[Index]);
    }
    if(newStockpiles.length == 0) {
        print("No more Stockpiles");
        exit();
    }
    Stockpiles = newStockpiles;
}

function getBarrels(){
    var Barrels = getMapObjects("barrel");
    for(var Index = 0; Index < Barrels.length; Index++){
        if(barrelType(Barrels[Index]) == "water")
            WaterBarrels.push(Barrels[Index]);
    }
}

function getStockpiles(){
    var Dirt = getMapObjects("stockpile-soil");
    if(Dirt.length == 0){
        print("At least one stockpile is needed");
        exit();
    }
    Stockpiles = Dirt;
}

function DoSurvey(){
    pfClick(Survey, MouseButton.Right);
    waitForTask();
    if(!startSurvey())
        exit();
}

function doDrink(){
    drink();
    if(getStamina() < 100)
        Refill();
}

function Refill(){
    pfClick(WaterBarrels[0], MouseButton.left);
    waitForTask();
    take("waterflask");
    sleep(1000);
    useItem(WaterBarrels[0]);
    drop("waterflask", Inventory.Hand, Inventory.Player)
    sleep(500);
    drink();
    take("waterflask");
    sleep(1000);
    useItem(WaterBarrels[0]);
    sleep(500);
    useItem(WaterBarrels[0]);
    drop("waterflask", Inventory.Hand, Inventory.Player)
    DoSurvey();
};
User avatar
Paradoxs
 
Posts: 294
Joined: Tue Aug 25, 2015 7:16 am

Re: Prime - Amber Tweaks and Scripting API

Postby gigafunk » Sat Jan 07, 2017 12:10 am

Should this work?


Code: Select all
function main(){
   print("Hey test");
}



i ran a few of your test scripts and cant seem to see where the console is. I figured it was system chat but it doesnt appear to be.... Lil help, then i can be off and running debugging with prints!
gigafunk
 
Posts: 23
Joined: Sat Apr 21, 2012 10:28 pm

Re: Prime - Amber Tweaks and Scripting API

Postby iamahh » Sat Jan 07, 2017 2:01 am

run game via debug.bat and you see messages in a separate console window
iamahh
 
Posts: 1810
Joined: Sat Dec 12, 2015 8:23 pm

PreviousNext

Return to The Wizards' Tower

Who is online

Users browsing this forum: Claude [Bot] and 119 guests