H&H Groovy bot

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

Moderator: Phades

Re: H&H Groovy bot

Postby boshaw » Mon Aug 29, 2011 5:12 am

depends how in depth you wish to make this dairy farmer chat spammer on the go
Code: Select all
RED => Corresponds to the # that's red color in buddy window list
SLEEP_TIME => Refers to time to pause script in [ms]
Logs  // -> Array/list of preset chat bullshit
PObjs // -> Array/list for future use to hold gobs of players
Obj  // -> Single gob for future use

dickweed: while(not_interupted_script){  // <-- not_interupted_script refering to some interupt system you have, or not
   sleep(SLEEP_TIME);
   PObjs = getobjs("player"); //<--- Where player refers to player-gobs which are defined by Neg attrs
   for each (PObjs : Obj) { //<-- for loop works fine, any way to loop through all objs
      if(!is_kinned(Obj) || (!is_vil_gob(Obj) && pcolor(Obj,RED))){
          print(Logs[random(MAX_LOGS)],ACHAT);
          break dickweed;
      }
   }
}


that would be a basic implementation.

Functions:
sleep(int) => pause script for x [ms]
getobjs(string) => refers to special gob finder for gobs only identifiable via Neg attr
is_kinned(Gob) => refers to function that see if said gob has KinInfo.class; Returns true/false; not needed really unless you make some of your villagers the color of your enemy
is_vil_gob(Gob) => refers to function that sees if said gob is part of your village; Returns true/false
pcolor(Gob,int) => refers to function that sees if said gob is said color according to buddy window; returns true/false
print(string,int) => prints said string to said chat with the corresponding integer value



I'm sure you can translate into groovy.
User avatar
boshaw
 
Posts: 1590
Joined: Tue Jun 01, 2010 10:22 pm

Re: H&H Groovy bot

Postby foomanchu » Tue Aug 30, 2011 4:33 pm

hey,
I got a question i was hoping someone could answer..
ive been trying to make a script where a waterflask gets picked up and refilled at a well
ive tried a few different things but i cant seem to get the right click on well part to work after picking up the flask

Code: Select all
println 'refilling flask'
    ark_bot.set_inventory("Inventory")
    def flask_c
    def wellId = ark_bot.find_map_object("well", 66, 0, 0)
    if (!wellId) { println 'well not found!!!'}
    while(ark_bot.next_item()){
      if (ark_bot.is_item_name('waterflask')){
        flask_c =  new Coord(ark_bot.item_coord_x(), ark_bot.item_coord_y());
        def well_c = new Coord(-1,0);
        ark_bot.item_click("take", 0);
        thread.sleep(1000);
        //ark_bot.DoClick(wellId, 3, 0);
        //ark_bot.DoInteractClick(well_c, 3);
        thread.sleep(6000);
        ark_bot.item_drop(flask_c);
        break;
      }
    }


the commented part is what doesnt seem to work
anyone got any ideas on how to do it?
thanks
foomanchu
 
Posts: 121
Joined: Wed Jun 29, 2011 6:13 am

Re: H&H Groovy bot

Postby boshaw » Tue Aug 30, 2011 5:25 pm

Code: Select all
public boolean iteminteract(Coord cc, Coord ul) {
   Gob hit = gobatpos(cc);
   Coord mc = s2m(cc.add(viewoffset(sz, this.mc).inv()));
   if(hit == null)
      wdgmsg("itemact", cc, mc, ui.modflags());
   else
      wdgmsg("itemact", cc, mc, ui.modflags(), hit.id, hit.getc());
   return(true);
}


That's the original function used by the client when right clicking a item to a object on the map so to do it if possible do:

Code: Select all
//First you'll need to "take" the flask which you did then:
//ui.mainview -> refers to MapView.class instance for hnh client your ui should have a variable for it if you can access it
ui.mainview.wdgmsg("itemact", new Coord (1,1),WELL_COORD_ON_MAP,WELL_ID,WELL_COORD_ON_MAP);


that should work as long as you have the flask already taken from the inventory. the CC should matter since those are just screen coords (not actual tile coords).
User avatar
boshaw
 
Posts: 1590
Joined: Tue Jun 01, 2010 10:22 pm

Re: H&H Groovy bot

Postby foomanchu » Wed Aug 31, 2011 3:21 am

thanks for the speedy response

so i put the line you posted after the take, along with changing the parameters you posted
ui.mainview.wdgmsg("itemact", new Coord (1,1),well_c,wellId,well_c);

unfortunately it doesnt work.. excuse my coding newbiness
is there a particular file i should be importing to get that function to work? only thing i can think of that i have in my script is import haven.UI which makes me think that i should be able to use that function

the error i get is:

Code: Select all
C:\HnH\PanAeon-Hearth-Haven-Groovy-Bot-3185fe0>java -cp groovy-1.7.5.jar -Xms256
m -Xmx512m -jar haven.jar moltke.seatribe.se
refilling flask
Exception in groovy script engine:
groovy.lang.MissingPropertyException: No such property: ui for class: MyScript
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptByteco
deAdapter.java:49)
        at org.codehaus.groovy.runtime.callsite.GetEffectivePogoPropertySite.get
Property(GetEffectivePogoPropertySite.java:86)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjec
tGetProperty(AbstractCallSite.java:239)
        at MyScript.run(well.groovy:37)
        at MyScript$run.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSi
teArray.java:40)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCa
llSite.java:116)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCa
llSite.java:120)
        at well.run(well.groovy:45)
        at groovy.util.GroovyScriptEngine.run(GroovyScriptEngine.java:515)
        at haven.hhl.hhl_main.ParseScript(hhl_main.java:70)
        at haven.hhl.hhl_thread.run(hhl_main.java:89)


i wish i had an example script that filled a bucket from a barrel or well that works :P
im basically learning by stripping code from harvester/lamber/hello script.. the updated script that someone posted earlier in this thread had a refill from barrel, however, his method didnt work (not to mention used left click even when its right to refill).
im trying to figure stuff out outside of the context it is used in example scripts, but the process is slow going.. so if some light can be shed on this question, id be forever grateful ;)
foomanchu
 
Posts: 121
Joined: Wed Jun 29, 2011 6:13 am

Re: H&H Groovy bot

Postby boshaw » Wed Aug 31, 2011 4:17 am

ok it's saying it can't find property/variable "ui" because TECHNICALLY ui is a variable in all widgets and i when i did my mods i had a variable called "ui" which was the latest UI instance (like all widgets have) for you this would be weird to do since you're not technically part of one java class, you're in your own script world and idk if it has some static ui variable out there, but there's another solution. I was hoping that Pan's client would have a UI instance static variable at use in the UI.java but whoever code he pulled from he didn't seem to add that so we'll have to go through ui through a widget.

When i say widget i mean anything UI related, Items (in inventory), windows, etc. So you're going to want to get a copy of a widget in a variable say 'x' (i'm not sure how you do that in art_bot but i assume there's some easy method...). Now that we have 'x' we can access UI through the ui variable that all widgets contain:

Code: Select all
x.ui.mainview.wdgmsg("itemact", new Coord (1,1),well_c,wellId,well_c);


The above should work, also as i'm looking through Pan's ark_bot.java -> https://github.com/PanAeon/Hearth-Haven ... k_bot.java

it contains a static reference to the UI class so you should be able to :

Code: Select all
ark_bot.ui.mainview.wdgmsg("itemact", new Coord (1,1),well_c,wellId,well_c);


the last method should work and i would recommend that over the widget example actually.

Bucket-Barrel problem :
http://paste.lisp.org/display/124383#3
The above link is a section of code from my hunger bot actually you can try to translate that to ark_bot stuff, but i'm not sure if ark_bot provides all the functions i used.

Here's a explanation of the process though:
1) Get a EMPTY bucket found within your inventory
::(ekets (get_inv_items_name "gfx/invobjs/buckete" PLAYER_INV))
ekets = my variable which will end up being type ArrayList<Widget>
get_inv_items_name is a function used to get a widget from in inventory X[Player's for this] with the RES name of "gfx/invobjs/buckete" which is empty bucket resource
2) Find our barrel
::(barrels (getobjs "gfx/terobjs/barrel")) [NOTE: this code wasn't part of the above pasted so you won't see it there]
barrels => variable name for my ArrayList<Gob> Remember these are Gobs, not widgets since they are Ocache objects
getobjs => refers to my function for finding Ocache objects within the current draw distance via their RES name "gfx/terobjs/barrel" for barrels
3) Take the first empty bucket found
::(let ((eket (jcall "get" ekets 0)))
this is just dealing with my arraylist of empty buckets, i want the first one in there (you probably won't need this)
4)OPTIONAL[see 6)] Right click the barrel
::(right_click_obj barrel)
right_click_obj => Right clicks a ocache object (Gob); [wdgmsg("click"...)']
5) Sleep your program, 2 seconds is good enough assuming your bot is within 1 tile of the barrle
::(jsleep 2000) [in millis for me]
6)OPTIONAL: Error checking, make sure the barrel has water and has > 0 L. I don't think this is possible with ark_bot without alot of hacking around to be honest so you probably can just ignore this.
::(if (> (get_barrel_depth) 0)
7) Put the bucket back in inventory slot found at
::(let ((cx (jcall "coord_x" eket))
::(cy (jcall "coord_y" eket)))
this is basically just getting the coordinates of the bucket widget when it back still in your inventory, cx,cy are of type Coord
-----------------------
At this point is where we actually get the water
-----------------------
8) Pick your bucket up
::(take_item eket)
take_item => refering to wdgmsg("take") for a Item widget, ark_bot should have a function for doing this and i think you were using it earlier
9) Sleep your program in case of lag, 1 sec will do
10) Interact the bucket with the barrel
::(interact_hold_gob barrel)
interact_hold_gob => Right clicks a ocache object (Gob); [NOTE: this is a wdgmsg("itemact",....) call to MapView.java also known as (ui.mainview)]
11) Sleep your program again once again in case of lag, time depends on how far this barrel will be from you
12) Final step: put the bucket back in inventory
::(put_hold_item cx cy PLAYER_INV))
put_hold_item => refers to a function that puts the current item being held back into Inventory X (player for us) at coordinates cx,cy which is where the bucket was originally. I think ark_bot has a function to do this as well.

That's basically how you do bucket -> barrel stuff. You really don't need the optional stuff unless you think it could happen, for me i had to use it so that my hungerbot would know to go to the next barrel when the old one was empty.
User avatar
boshaw
 
Posts: 1590
Joined: Tue Jun 01, 2010 10:22 pm

Re: H&H Groovy bot

Postby foomanchu » Wed Aug 31, 2011 4:52 am

hey, thanks again for the speedy response

wish i was home to try out that line, groovy bot only seems to work on my desktop ;)
but i'll post how it goes when i can manage to try it out

and my apologies about my previous post being unclear and getting you to write out your bucket/barrel process ;)
i was simply stating that earlier in this thread, someone posted a function that refilled his waterbucket from a barrel that ended up being erroneous
though i suppose i did indirectly ask for an example, but i was referring to any example groovy code to have a bigger base of code to learn from

i do have a hunger bot that i pieced together.. the only thing that doesnt work is the refilling from a well part.. i can work around it by loading a bunch of buckets filled with water and looping till buckets are either empty or hunger reaches a certain point, but my main goal for completing this script was to learn the basics of item interactions to apply to later and more complex scripts
but enough rambling... thanks again for the reply and i will try it out asap ;)
foomanchu
 
Posts: 121
Joined: Wed Jun 29, 2011 6:13 am

Re: H&H Groovy bot

Postby foomanchu » Fri Sep 02, 2011 5:40 am

well i finally got home and tested it out
good news and bad news
good news i guess first.. ;)
the line "ui.mainview.wdgmsg("itemact", new Coord (1,1),well_c,wellId,well_c);" does not give me any errors.. it runs through the entire script

the bad news is that it does nothing :(
(i played around with the coord numbers for that variable being declared in the function, along with well coords, even trying it out with an empty bucket as opposed to a waterflask)
so it just picks up the flask/bucket, holds it in cursor for the duration of my delay, then puts it back in the inventory spot it previously occupied

this makes me both glad and mad that i changed programs from compsci to engineering :P
foomanchu
 
Posts: 121
Joined: Wed Jun 29, 2011 6:13 am

Re: H&H Groovy bot

Postby boshaw » Sat Sep 03, 2011 12:33 am

foomanchu wrote:well i finally got home and tested it out
good news and bad news
good news i guess first.. ;)
the line "ui.mainview.wdgmsg("itemact", new Coord (1,1),well_c,wellId,well_c);" does not give me any errors.. it runs through the entire script

the bad news is that it does nothing :(
(i played around with the coord numbers for that variable being declared in the function, along with well coords, even trying it out with an empty bucket as opposed to a waterflask)
so it just picks up the flask/bucket, holds it in cursor for the duration of my delay, then puts it back in the inventory spot it previously occupied

this makes me both glad and mad that i changed programs from compsci to engineering :P


I think i gave you a slight error, sorry, after the first well_c there should be the ui.modflags() argument. Sorry about that (finally got home to look at my actualy bot code now), try the below.
Code: Select all
   public void interact_hold_gob(Gob g){
      log("INTERACT HOLD OBJ WITH GOB");
      ui.mainview.wdgmsg("itemact", new Coord(5,5), g.getc(), ui.modflags(), g.id, g.getc());
   }
User avatar
boshaw
 
Posts: 1590
Joined: Tue Jun 01, 2010 10:22 pm

Re: H&H Groovy bot

Postby jaguar » Tue Sep 13, 2011 10:54 pm

is it possible to take blocks from the sign?
User avatar
jaguar
 
Posts: 251
Joined: Sun Jan 16, 2011 11:59 pm

Re: H&H Groovy bot

Postby boshaw » Tue Sep 13, 2011 11:55 pm

jaguar wrote:is it possible to take blocks from the sign?

Search for a ISBox type widget (which are each indiviual sign component)
and then do one of the following:
Code: Select all
    public boolean mousedown(Coord c, int button) {
        if(button == 1) {
            if(ui.modshift)
                wdgmsg("xfer");
            else
                wdgmsg("click");
            return(true);
        }
        return(false);
    }
   
    public boolean mousewheel(Coord c, int amount) {
      if(amount < 0)
          wdgmsg("xfer2", -1, ui.modflags());
      if(amount > 0)
          wdgmsg("xfer2", 1, ui.modflags());
      return(true);
    }

both of the mousedown wdgmsg should either a) give you the block or b) put it in your inventory. iirc the wdgmsg("xfer2",-1,ui.modflags()); is the one which transfers the signs components into your inventory.
User avatar
boshaw
 
Posts: 1590
Joined: Tue Jun 01, 2010 10:22 pm

PreviousNext

Return to The Wizards' Tower

Who is online

Users browsing this forum: Ahrefs [Bot], Claude [Bot] and 0 guests