Jump to content

Functional programming with osbot [run time scripts]


Nbacon

Recommended Posts

Hello there, 

I origanal made a post about this in Unofficial Scripts & Applications. But see how no one wants it. I'm moving the updates to Off-topic. When making Bots in I believe that best bots can stop and start at any time and keep going with mininal globle variables and find its place based off state of the bot. So this project is a full blow programming laungage called scheme a flavor of lisp writen in java (writing one language in another? yes). Scheme is a functional programming laungage so that means runs of the idea of Lambda expressions and inputs. Lambda expressions make funtions that take 0 to N inputs and can be thought of as the same like math funtions were you have some inputs/none to 1 output  [example  f(x,y) = x+y+5]. Scheme is not typed this means thay you can pass any to a funtion like other funtions, good and bad data. It can "find out" if programed to know what to do with the data. 

This weeks update is under this post 


The basics of Sceme (extensive https://www.scheme.com/tspl3/ )

  Reveal hidden contents

 

  •  Ever thing is Lisp notation
    •   a mixture of parentheses and prefix notaiton (inside out)
    •   (+ ( * 5 2 ) 3) = (+ ( 10 ) 3) = 13
  • Scheme Expressions [either pairs or atoms ]
    •  Atoms [things that can't get more basic]
      • #f,#t,numbers, funtions ,() [null]
    • Pairs [combaition of data]
      • (cons x y) = '(x . y)   - > cons makes a pair, x is the car ,and y is the cdr
    •  List [combation of Pairs] basicly linked lists, pair whose cdr is a list or null
      •  (list 1 2 3 4) -> '(1 2 3 4 ) -> (1 cons (2 cons (3 cons (4 cons ())))) [these are all the same]
  • Define vars
    • basily its like var [something] = [something else]
      •  examples 
        •   (define y 5)   x = 5
        • (define x (cons 1 y))   x = '( 1 . 5 )
  • Define lambda
    • 3 ways or combition of the following [example in java [int name( int x , int y) { return x+y;};]]    
      •  (define (name x y ) (+ x y ))  
      •  (define name (lambda (x y) (+ x y ))) 
        • uses of the above funtions  (name 5 4)
      •  (define name (lambda (x) (lambda (y)(+ x y )))) 
        •  uses  ((name 5)4)  
  •  How to use lambda funtions 
    •   basily rap the name of the funtion with the arguments in a ()
  •  how to curry funtions
  •   Curring alows you to fill in some or all data in a funtion and use that as funtion its self
  • math example f(x,y) = x+y 
  •  but say you curry x with 5. f(5,y) = 5+y you basicly have f(y)= 5+y
  • Examples from my code
    • The main funtion is "item"
      • (define (item name minQuantity maxQuantity noted stackable equiable only)
                     (list name minQuantity maxQuantity noted stackable equiable only))
    • I dont want fill out the funtion evertime so I curry it with basic idea of a equiable-item or tool-item
      • (define (equiable-item  name)  (item name 1 1 #f #f #t #t))
      • (define (tool-item  name equiable ) (item name 1 1 #f #f equiable #t) )

 

 

Why I do  I think funtional programming better then java?
Because you can keep data and methods separate,  the abilty to pass functions as parameters and Currying  https://en.wikipedia.org/wiki/Currying. You can make a basic functional programming laungage in 500 lines or less in C.  I can program program alot faster, I made an AIO woodcutter 2 hours becuase when I program like a dfs I believe they run faster, are easier to change/mantain and use less resourses.

Showing off the basics [updated 07192020]

 

 

Videos+Scripts 

 AIO Woodcut video [updated for new code]

Wc code rewriten for super banker saves around 300 lines of code.

  Hide contents

Things that i would like to point out 

  • axe upgrades
  • Abitly to have custom addives like WC outfit and rabits foot
  • picks up birds nest.
  • 20+ area
  • progress mode possible and task ready

 

Code:

  Reveal hidden contents


(import "code/bank/bank-open?");;bank-open?
(import "code/bank/open-bank");;open-bank
(import "code/other/rip-names");;rip-names
(import "code/other/rip-spot");;rip-spot
(import "code/items/tool-item");;tool
(import "code/items/equiable-item");;equiable
(import "code/items/item");;equiable
(import "code/Skills/Woodcuting/additives");;additives
(import "code/Skills/Woodcuting/axes");;axes
(import "code/Skills/Woodcuting/logs");;logs
(import "code/other/is-empty-except-ls");;is-empty-except-ls


(define drop? #f)
(define setup? #f)
(define tree-area '())
(define tree-name '())
(define gear '())

(define setup 
        (lambda (bank set-tree-name set-tree-area )
          (set! drop? (not bank) )
          (set! tree-area set-tree-area )
          (set! tree-name set-tree-name )
          (set! setup? #t )))

(define (WC)
        (define (axe-check item-holder-check)  
                (lambda (name wc-level att-level)
                  (and (item-holder-check  name)	
                       (>= (getvirtuallevel (skill (woodcutting)))  wc-level ))))
        (define (usebank) 
                (define (get-banked-items) 
                        (define (check name ) (or(contains (getinventory)  name)(contains (getbank)  name) (contains (getequipment)  name))) 
                        (define (best-axe)
                                (letrec
                                  ((loop (lambda (x)
                                           (cond
                                             ((null? x)   #fuck this should never run)
                                             ((apply (axe-check check)  (car x) ) (car x))
                                             (else (loop (cdr x)))))))
                                  (loop axes )))
                        (define (can-wear-axe? name wc-level att-level)(>= (getvirtuallevel (skill (attack)))  att-level ))
                        (define (get-additives ax)
                                (letrec
                                  ((loop (lambda (x acc)
                                           (cond ((null? x ) acc )
                                                 ((check (car x) ) (  loop (cdr x)   (cons   (equiable-item  (car x))  acc )    ))
                                                 (else (loop (cdr x)   acc  ))))))
                                  (loop additives  (cons ax ()))))
                        (define (get-ax ax) (tool-item  (car ax )  (apply can-wear-axe? ax)))
                        (get-additives (get-ax (best-axe))))
                (cond
                  ((not (bank-open?)) (open-bank))
                  ((super-bank? ( apply super-bank  (get-banked-items))) (run( apply super-bank  (get-banked-items))))
                  (else (walks-to-trees))))
        
        (define (need-to-bank?)
                (define (check name ) (or(contains (getinventory)  name)  (contains (getequipment)  name))) 
                (define (can-use-axe)
                        (letrec
                          ((loop (lambda (x)
                                   (cond ((null? x)  #f)
                                         ((not ( apply (axe-check check) (car x)))(loop (cdr x)))
                                         (else #t)))))
                          (loop axes )))
                (define (inv-full)  (and  (not drop?)(isfull  (getinventory))))
                (define (axes?)  ( = (+ (  apply getamount (getinventory) (rip-names axes))( apply getamount (getequipment) (rip-names axes))) 1 ))
                (define (check-inv)   (not(is-empty-except-ls getinventory  (append (rip-names axes) (rip-names logs)))))
                (define (check-equp) (not (is-empty-except-ls getequipment   (append additives (rip-names axes)))))
                (or (inv-full) (not (axes?  = 1 ) )  (not (can-use-axe))  ( check-inv )  ( check-equp )))

        (define (need-to-drop?) 
                (and  drop? (isfull  (getinventory))))
        (define (drop-logs) 
                (apply drop-all(getinventory) (rip-names logs)))
        
        (define  (not-near-trees?) 
                (not (contains  tree-area   (myplayer))))
        (define (walks-to-trees) (webWalk tree-area ))

        (define (see-birds-nests? ) 
                (not(null? (closest (getGroundItems)  "Bird's nest" ))))
        (define (pick-up-nest) (pick-up-item "Bird's nest"))

        (define (not-choping?) (and(not (ismoving (myplayer) )  )  (= (getanimation (myplayer) ) -1)  ))
        (define (chop-tree)  (and (interact (closest (getObjects) tree-area tree-name  ) "Chop down" )  (sleep-until not-choping?  1800 600)))
        
		(cond
          ((inside-bank?) (usebank))
          ((need-to-bank?) (walk-closest-bank))
          ((need-to-drop?) (drop-logs))
          ((not-near-trees?)  (walks-to-trees))
          ((see-birds-nests?)  (pick-up-nest)) 
          ((not-choping?)  (chop-tree)) 
          (else "wait")))

(define (loop) (wc))

 

 

 

 

AIO Firemaking video

  Hide contents

Things that i would like to point out 

  •  progressive mode 
  • If give given a path will find the best one

 

Code:

  Reveal hidden contents


(import "code/Skills/Firemaking/fm-logs")
(import "code/items/tool-item")
(import "code/items/fill-space-item")
(import "code/items/item-use-item")
(import "code/scheme/filter")
(import "code/bank/bank-open?");;bank-open?
(import "code/bank/open-bank");;open-bank
(define superbanker-code   '())
(define setup? #f)
(define logs '())
(define pro #f)

(define setup 
	(lambda (area logs-name  progressive)
		(set! fmspace   area)
		(set! superbanker-code  (super-bank (tool-item  "Tinderbox"  #f)) (fill-space-item  logs-name 1 #f))
		(set! logs   logs-name)
		(set! pro   progressive)
		(set! setup? #t )))

(define (firemake)
	(define (test-object x)
		(define (removeGroundDecoration x ) (not (GroundDecoration? x) ))
		( =  0  (length (filter removeGroundDecoration (get (getObjects) x )))))
	(define (getspot)
		(define (get-useable-spots ls )  (filter test-object  ls))
		(define (getspot-helper ls)
			(cond 
				((null? ls) #f)
				(( > (length (get-useable-spots  (getpositions (area (caar ls) (cadar ls)  (-(caar ls) 27) (cadar ls))))) 27)   (car ls))
       ; (( > (length (get-useable-spots  (getpositions (area    (car(car ls))    (car (cdr (car ls)))  (-(car  (car ls) ) 27) (car (cdr (car ls))))))) 27)   (car ls))
       (else  (getspot-helper (cdr ls)))))
		(getspot-helper fmspace))

	(define  (spot-has-object)   (not (test-object (myposition))))

	(define (usebank)  
		

		(define (upgrade)
			(letrec
				((loop (lambda (x)
					(cond
						((null? x)   #fuck this should never run)
						(( and (>= (getstatic (skill (firemaking)))  (cadar x) )  (contains (getbank)  (caar x))) (caar x))
						(else (loop (cdr x)))))))
				(loop ( reverse fm-logs) )))

		(define (upgrade?) (not (eq? (upgrade) logs  )))
		(cond 
			((not (bank-open?)) (open-bank))
			((and (upgrade?) pro)(set! logs  (upgrade)))	
			((need-to-bank?) (run (super-bank (tool-item  "Tinderbox"  #f) (fill-space-item  logs 1 #f) )))
			(else (move))))
	
	(define  (need-to-bank?)    (not(contains (getinventory)  logs) ))
	(define (not-burning?) (and(not (ismoving (myplayer))) (= (getanimation (myplayer)) -1)))
	
	(define (burn bool) 
		(if bool 
			(item-use-item-closest "Tinderbox" logs )
			(item-use-item-closest   logs "Tinderbox")))

	(define (move) (accurate-walk (apply  position  (getspot))))
	(cond
		((inside-bank?) (usebank))
		((and   (= (getanimation (myplayer) ) -1) (need-to-bank?)) (walk-closest-bank))
		((spot-has-object)  (move)) 
		((not-burning?) (burn (even?(getx (getposition (myplayer))))))
   ((not (isitemselected))(burn (odd?(getx (getposition (myplayer))))));;add hover
   (else "wait")))

(define (loop) (firemake))


(define fmspace '((3176 3503 0)
	(3176 3502 0)
	(3176 3500 0)
	(3176 3501 0)
	(3176 3497 0)
	(3176 3496 0)))

(setup fmspace "Logs" #t)

 

 

 

 

AIO F2P runecrafting video 

  Hide contents

Things that i would like to point out 

  • All tiaras and  runes that are ftp

 

 

Code:

  Reveal hidden contents



(import "code/bank/bank-open?")
(import "code/bank/open-bank")
(import "code/items/fill-space-item")
(import "code/items/tool-item")
(import "code/other/not-moving?")
(import "code/other/item-use-object-closest")
(import "code/other/item-use-object-sleep")
(import "code/runecrafting/runes")

( define my-rune 'air)
( define make-tiaras  #f)	

(define (runecrafting)

	(define (check-e name ) (contains (getequipment)  name) )
	(define (check-i name ) (contains (getinventory)  name) )
	(define (not-near-altar) (not (near-altar)) )
	(define  (near-altar) (contains  (runes  my-rune 'altar)    (myplayer)))

	(define (usebank)
		(define (get-banked-items)
			(define (check name) (or(contains (getinventory)  name)(contains (getbank)  name) (contains (getequipment)  name))) 
			(define (tiaras?) (if (check (runes  my-rune  'tiaras)) (tool-item (runes  my-rune  'tiaras)  #t)  (tool-item  (check-i (runes  my-rune  'talismans))  #f)))	
			(cond
				((not make-tiaras) (list (fill-space-item  "Pure essence" 1 #f)  (tiaras?)))
				((and(check (runes  my-rune  'tiaras)) make-tiaras) (list (tool-item (runes  my-rune 'tiaras)  #t) (fill-space-item  "Tiara" 1 #f) (fill-space-item  (runes  my-rune  'talismans) 1 #f)))
				(( and (not (check (runes  my-rune  'tiaras)))make-tiaras )(list (fill-space-item  "Tiara" 1 #f) (fill-space-item  (runes  my-rune  'talismans) 1 #f)))
				(else (walks-to-altar))))
		(cond
			((not (bank-open?)) (open-bank))
			((need-to-bank?)(run( apply super-bank  (get-banked-items))))
			(else (walks-to-altar))))

	(define (need-to-bank?)  
		(or 
			(not (or (check-e (runes  my-rune  'tiaras))  (check-i (runes  my-rune  'talismans))))   
			(and make-tiaras  (not (and (check-i "Tiara")  (check-i (runes  my-rune  'talismans)))))
			(and  (not make-tiaras)(not (check-i "Pure essence" )))))
	(define (walks-to-altar)
		(define (enter-altar) 
			(define  (enter-altar-talismans tally)  (item-use-object-sleep  tally "Mysterious ruins" near-altar ))
			(define  (enter-altar-tiaras)  (and (interact (closest (getObjects) "Mysterious ruins"  ) "Enter" )  (sleep-until near-altar  10000 )))
			(cond 
				((check-e (runes  my-rune  'tiaras))(enter-altar-tiaras))
				(else (enter-altar-talismans (runes  my-rune  'talismans)))))
		(cond 
			((contains  (runes  my-rune 'enter)  (myplayer)) (enter-altar))
			(else (webwalk (runes  my-rune 'enter)))))

	(define (goto-bank)
		(define  (leave-altar)  (and (interact (closest (getObjects) "Portal"  ) "Use" )  (sleep-until not-near-altar  10000 )))

		(cond 
			((not ( not-moving?))(sleep 700))
			((near-altar)  (leave-altar))  
			(else(walk-closest-bank))))

	(define (use-altar) 
		(define (inv-has-runes) (and (= (getanimation (myplayer) ) -1)  (check-i (runes  my-rune  'base) )))

		(cond
			((and ( not-moving?) make-tiaras) (item-use-object-closest   (runes  my-rune  'talismans) "Altar")   )
			(else (and (interact (closest (getObjects) "Altar"  ) "Craft-rune")   (sleep-until inv-has-runes  10000 ) ))))

	(define (inside-altar?) (not (null? (closest (getObjects) "Altar" ))))

	(cond
		((inside-bank?) (usebank))
		((need-to-bank?)(goto-bank))
		((inside-altar?)  (use-altar)) 
		((not-near-altar)  (walks-to-altar))
		(else "wait")))

(define (loop) (runecrafting))

 

 

 

 

 

 

 

Features

Goals 

  • Make abilty to have packages (current Goal)
  • test about 600 500 400  300 more methods
  • Gui system like scratch
  • Gui that can be made at runtime
  • Implement ansi common lisp (50% done)
  • Dictionaries and hashmaps(current in O(n) time but can get to O(1) time)
  • Arrays [have not needed them yet so i have not added them.]

Program Goals

  • AIO skilling system (like Expv's AIO)
    • RC
    • FM
    • WC
    • Combat
    • Herblore
    • Fletching 
  • AIO quest system 
    • All ftp quest done
  • Account builder system like level 3 to MMF bot and level 3 to blast furnace with coal bag and ice gloves.

 

 

 

Number of bots baned: 3

  • Feltching testing(injection)
  • Some quest (my guess dorics quest.)
  • Banned after doing Monkey madness. [no idea on cause]

 

 

Cook assistant quest 

  Reveal hidden contents

(define (ca-quest action)
  	(define ca-config 29)
  
	(define (ca-check) (not (= 2 (get (getConfigs) ca-config))))
  
  	(define ca-items  '(("Pot of flour" #f 1) ("Bucket of milk" #f  1) ("Egg" #f 1)))
 
	(define cook-area   (Area 3205 3215 3212 3212))

	(define (Quest)   (talk-to-area   "Cook" '(1 1)  cook-area))
		(cond
			((eq? 'check action )(ca-check))	 
			((eq? 'items action )(ca-items))
  			((eq? 'setup action ) basic-setup)
			((eq? 'quest action )(Quest))))

 

 

 

 

 

Edited by Nbacon
  • Like 2
Link to comment
Share on other sites

On 6/15/2020 at 12:38 AM, RoundBox said:

I really like this. It's an interesting concept and I think you should keep going.

Thanks

On 6/15/2020 at 4:18 AM, poishishikochi said:

WOW!! Amazing! How can I contact you?

You can contact me with a personal message or on discord inept#0327 [254157948585115650]

Edited by Nbacon
Link to comment
Share on other sites

Week 1 Updates:

  • Conditional sleeps
    •  (and (chop tree)   (Conditional-sleep   tree-choped?  )) [06122020]
  • Starting documentation [06152020]
    • Very slow
  • Starting Threading and sub lang.
    • Threading not done. Thought to be done but is not.
  • parallelism? Speed is not an issue at the moment but might be when harder scripts are made.

Skills done:

  • WC [06032020]
  • RC  [06132020]
  • Basic area combat [06122020]

Quest done: 

  • Cook's Assistant [06132020]
  • Doric's Quest  [06132020]
  • Imp Catcher [06132020]
  • Sheep Shearer [06132020]
  • Witch's potion [06132020]
  • X marks the spot  [06132020]
  • Rune mysteries [06142020]
  • Goblin Diplomacy [06142020]
  • The Restless Ghost [06142020]
  • Prince Ali Rescue [06142020]
  • Ernest the chicken [06152020]
  • Romeo & Juliet [06152020]
  • Vampyre Slayer [06152020]
  • Pirate's treasure [06162020]
  • The Knight's Sword [06162020]
  • Black knights' fortess [06162020]
  • Dragon slayer [06172020]
  • The Corsair Curse [06182020]

Quest that might never get done:

  • Misthalin Mystery [the end is to hard for me to think of bfs/dfs type logic]
  • Shield of Arrav partner quest ( might get both done but they are low priority)
Link to comment
Share on other sites

Week 2 Updates:

This week was spent making a super banker and refactor ftp quest to fit a new task system  and fixing bugs with sleep-untill  .

New account update:

  • New account for members quest.
  • New account has 41 Qp [all ftp quest]

Bot updates:

  • Added fming
  • Adding Abyss and member runes to Rc [kinda full rewrite]
  • tasks abilty [need to change scrpits work with it]

Quests:

  • Druidic Ritual

Code updetes:

  • Refactoring
    • Made it easy to add Task system.[ 06202020]
    •  interaction with items (spam clicks).[fixed 06202020]
    •  combat with npc (spam clicks).[fixed 06192020]
      • (define (loop )(attack-npc (target-npc "Chicken")))   <- one liner chicken bot that list better than 99% of Ive seen.
    • Polling get Configs (1 time per loop is fine )[fixed 06192020]
      • Went from
        •   (cond     
             ((=(& 15 (get (getConfigs) bkf-config)) 0)(start))
             ((=(& 15 (get (getConfigs) bkf-config)) 1)(get-to-grate))
             ((=(& 15 (get (getConfigs) bkf-config)) 2)(cabage-time))
             ((=(& 15 (get (getConfigs) bkf-config)) 3)(quest-done))))
           
      • to
        •  (define 
              (quest config)
              (cond     
               ((= config 0)(start))
               ((= config 1)(get-to-grate))
               ((= config 2)(cabage-time))
               ((= config 3)(quest-done))))
           
    • Pull out code that can be curried.[06192020]
      • (item-use-object-area item object area)
      • (item-use-item item1 item2  )
      • (dig area)

Goals:

  • Expand/remove api.
    •  super banker[done]
      • withdraws gear and inv (bank excess if exist)
        • abilty to withdraw dynamic sets; like herbs and vails 14 of each,  9 flour 9 buckets of water ext .
          • (1 herb, 1 vail ) will withdraw 14 of each
          • (1 flour , 1 bucket of water  , 1 free space) will withdraw 9,9 and leave the rest emepty
          • (3 cosmic runes , 1 unpower orb) will withdraw  81 cosmic runes and 27 orbs.
        • abilty to withdraw gear
          • Air orb banking would look like 
            • (wear "glory (?)" ) (wear staff of air )(stack-item  3 "Cosmic rune") (fill-space unpower orb )
  • Task system [done]
    • Time [done]
    • xp[done]
    • resources[done]

 

Roleover Goals

  • Ge, Ironmen ftp all quest, documentation.

 

 

Edited by Nbacon
  • Like 1
Link to comment
Share on other sites

I did not have alot free time this week. With the time i did have I made 2 new skill bots herb and fletching(they need to be remade because they poorly coded) and Import. 

Week 3 Updates:

  • Import (user defined functions )
    •  (import "bank" "wc"     )   this will import all methods bank folder and woodcutting  wc folder
    •  (import "bank\1" "wc\enum"     )   this will import a just that file or the full folder
  • Wipe and load
    • This will wipe out all old code and load a file (hopefully with code that tells the bot to do something)
  • Log-in 
    • (Log-in username password)
  • item-closest
    • As seen in firemaking video 
    • Finds the closest item with that name or id to mouse 

Quest:

  • Enter the abyss

Skills(tring to write these in a better way)

  • herblore
  • fletching 

 

Edited by Nbacon
Link to comment
Share on other sites

Week 4:

I was making a gui with a file tree and some how deleted all my java projects. Just a friendly reminder to always use version control offen. Only lost 2 or 3 days of work mostly gui.

 

 Aio fishing done.

Im going to get videos of quest and write the bots later.

Quest:

  • waterfall quest
    • varbits✅
    • writen ❎
  • Tree Gnome Village
    • varbits✅
    • writen ❎
  • Monk's Friend
    • varbits✅
    • writen ❎
  • Hazeel Cult
    • varbits✅
    • writen ❎
  • Murder Mystery (going to be hard because there are 6 varents)
    • varbits✅
    • writen ❎
  • Recruitment Drive (have the varbits so the bot has a 90% chance of passing it every time.)
Link to comment
Share on other sites

Week 5:

New video of the new built in ide.

 
 

 

Screen shots of the Gui and Flow programing mock-up

628586134_Screenshotfrom2020-07-1714-10-33.png.82166412e7738184f9ea6a7dbf4d78ec.png

 

 

https://imgur.com/a/TZaGe2N

Todo

  • better auto complete 
  • syntax highlighter
  • parentheses matching 
  • Per run error checking 
  • flow prgraming 
    • Flow to Scheme code
    • Scheme to Flow

 

 

Edited by Nbacon
Link to comment
Share on other sites

This week I tried so many Flow programing layouts 7+ and I settled on this one. Just need to make patern that alows for easy expandablity.

https://imgur.com/a/JwoSsb9

Week 6:

Even more Gui work this week

Goals

  • better auto-complete [Done 07232020]
  • syntax highlighter [Done 07182020]
  • parentheses matching [Done 07182020]
  • Per run error checking 
  • flow prgraming 
    • Flow to Scheme code
    • Scheme to Flow

 

On 6/14/2020 at 10:00 PM, Nbacon said:

995966844_Screenshotfrom2020-07-1811-56-04.png.fc8102e363cafc29c7012efdd2fbfdca.png

 

 

 

 

 

 

Edited by Nbacon
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...