Openkore.com

OpenKore Forums
It is currently 16 Oct 2018, 09:17

All times are UTC - 5 hours [ DST ]





Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: [Solved]Please help me with this macro! @storamount
PostPosted: 22 Oct 2017, 15:04 
Offline
Noob
Noob

Joined: 23 Jun 2008, 18:51
Posts: 6
Check further down for solution and working macro


Hello everybody!
In order to help myself learn some scripting (and hopefully eventually some perl so I can remake these more efficiently once I am done) I am working on writing a pack of macros to share with the community which will be released once i have worked out a few more bugs in the leveling script and finished first Job changes. Right now however I am working on a vending macro that will automatically:
- setup in desired location
- restock on items when you sell out first by checking storage and then if storage
is out of the item it will go to a specified NPC vendor
- return to desired location to set shop back up
- repeat indefinitely
- set up a shop with permanent inventory so as to be able to buy discount leveling
items with other bots being run at the same time while saving much money and
funneling Zeny to the merchant.

The code chunk I am posting up is the inventory check where it is supposed to check storage for the item, if item does not exist in storage it should go to the npc instead.

The issue i am having is even when storage is at '0' it will go there anyways instead of going to the NPC. I believe the cause of this is that if the storage is not actively open it shows a value of -1. I would just use this value, except that it does not actually tell me if the item exists in storage or not, and in order to make use of a storage check it seems I would have to make it open storage, then check contents of storage and if 0 then go to NPC. I would like to avoid having to go to storage first as it wastes a lot of zenny....which as a money making profile would be kind of pointless.

If anyone could give me some advice on how to get the contents of storage without having to be actively at it I would greatly appreciate it as this is the first hurdle I have come across I just have not been able to solve myself via forum searching and web scrubbing.

The following is the chunk of code I am currently having trouble with.

Code:
macro InvCheck  {
    if (@cartamount (Item Choice) == 0) (goto get)  #If Red Potions in Cart is = 0 go to storage script#
    if ((@storamount   (Item Choice) == 0) && (@cartamount (Item Choice) == 0)) (goto get2)  ###If Storage and Cart both = 0 then go to shop script###
    call move_to_spot #when all "if" conditions have been completed, goto next macro
   :get
      pause 2
      do closeshop
      pause 3
      do move payon www xxx
      pause 2
      do talknpc yyy zzz c r1 n
      pause 2
      do storage addfromcart Red Potion
      pause 1
      do storage gettocart @storage (Red Potion) @eval (928 - @cartamount (ItemChoice))
      pause 10
      call move_to_spot
      stop
   :get2
      pause 2
      do closeshop
      pause 3
      do move uuu vvv
      pause 2
      talknpc sss ttt b n
      pause 2
      do buy 1 @eval (500 - @cartamount (Item Choice))
      pause 3
      do cart add @inventory (Item Choice) @invamount (Item Choice)
      pause 10
      do cart add Item Choice
      pause 2
      talknpc sss ttt b n
      pause 2
      do buy 1 @eval (928 - @cartamount (Item Choice))
      pause 3
      do cart add @inventory (Red Potion) @invamount (Item Choice)
      pause 10
      do cart add Item Choice
      pause 10
      call InvCheck
      stop
}


To test the above code paste it into Notepad++ and hit ctrl+f
Click on the replace tab and replace the following with values for the proper values.

sss ttt = Merchant NPC coordinates (example: 159 96 for Payon Tool Merchant)
uuu vvv = Location near Merchant NPC (example: 159 93 to get near Payon Tool Merchant)
www xxx = Location near Storage NPC
yyy zzz = Storage NPC
Item Choice = Self Explanatory (example: Red Potion)



The only solution I have come up with so far is to move the storage check into ":get"
and if it =0 while storage open then immediately go to ":get2" like the following.

Code:
:get
      pause 2
      do closeshop
      pause 3
      do move payon www xxx
      pause 2
      do talknpc yyy zzz c r1 n
      pause 2
                if ((@storamount   (Item Choice) == 0) (goto get2)
                pause 2
      do storage addfromcart Red Potion
      pause 1
      do storage gettocart @storage (Red Potion) @eval (928 - @cartamount (ItemChoice))
      pause 10
      call move_to_spot


While this would work, it would still involve opening storage every time which again is something I really want to avoid. In the meantime I guess I will just use the function for buying replacement items but I would really like to get this issue figured out as I plan on using @storage in some of the other scripts I plan to release and getting it working properly is quite important. Thanks in advance for any help you guys can provide!


Last edited by BannedForBotting on 24 Oct 2017, 03:04, edited 3 times in total.

Top
 Profile  
 
 Post subject: Re: Please help me with this macro! @storamount
PostPosted: 22 Oct 2017, 20:53 
Offline
Human
Human

Joined: 01 Aug 2017, 01:05
Posts: 47
I thought it was @storeamount not @storamount?


Top
 Profile  
 
 Post subject: Re: Please help me with this macro! @storamount
PostPosted: 22 Oct 2017, 22:11 
Offline
Noob
Noob

Joined: 23 Jun 2008, 18:51
Posts: 6
according to the wiki it is @storamount

@storamount (<item>)
Returns the amount of the given <item> in storage.
http://openkore.com/index.php/Macro_plugin


Also, as stated in my original post, @storamount keeps returning -1 instead of 0. If the syntax was wrong it would either throw an error or not return anything.

Was a good thought though. Wish it had been that simple =D


:edit - Just for giggles I tried giving @storeamount a try and it immediately gave syntax errors. Wish that had fixed things.


Top
 Profile  
 
 Post subject: Re: Please help me with this macro! @storamount
PostPosted: 23 Oct 2017, 05:37 
Offline
Human
Human

Joined: 28 Nov 2010, 00:57
Posts: 32
I have a macro that I use this sintax:


do storage get @storage(Aloe Leaflet) @eval(int(@eval(($PesoMaximo-@eval($.weight))/$.PesoItem))) if (@storamount(Aloe Leaflet) > 0)


For the openkore check trully if the storage is empty, I end my macro with "do talknpc 195 150 c w1 r1 w1 c w1 r0"

This way the macro ends with the storage openned and check trully the amount in storage!


Top
 Profile  
 
 Post subject: Re: Please help me with this macro! @storamount
PostPosted: 23 Oct 2017, 06:15 
Offline
Noob
Noob

Joined: 23 Jun 2008, 18:51
Posts: 6
Yaham wrote:
I have a macro that I use this sintax:


do storage get @storage(Aloe Leaflet) @eval(int(@eval(($PesoMaximo-@eval($.weight))/$.PesoItem))) if (@storamount(Aloe Leaflet) > 0)


For the openkore check trully if the storage is empty, I end my macro with "do talknpc 195 150 c w1 r1 w1 c w1 r0"

This way the macro ends with the storage opened and check trully the amount in storage!



Thanks for the reply. I have rewritten the code about 24 times in different ways from scratch today trying to get it to work, I will give this function a try tomorrow and see how it works out. I had thought about the issue of Storage not being logged, so the first thing the script does now is check storage on login so it gets an accurate read before it starts to vend so that when it runs out it should have the proper storage values in memory. I figured that would work since once you have opened storage once you can check it within openkore from anywhere to see what the contents are. Are you saying that by ending the process with open storage it will keep storage open while it is vending so it can always have a constant read? If that is the case it is certainly a clever solution to a tricky problem.

I think the real issue I am having is that the 'if' statements are not being read properly and it is just going through my list of functions inside the macro 1 by 1 and trying to do them all regardless if conditions are met or not. I have tried using 'if' 'elsif' 'else' statements, and 'goto' functions and have the same issue with both....do i need to make a perl sub routine to make those functions work properly? I am trying to learn but still have a ways to go with the perl stuff although it is definitely something I am trying to pick up.

I really feel like once I get the 'if' statements to work properly that macro writing will be so much more versatile for me and I will be able to put out some cool stuff.

I did however finally get a functioning vend bot working without storage support, however NPC merchant support is working perfectly so for a simple vend bot for pots/wings/arrows/etc it is working great. In fact here it is.

Code:
#BannedForBotting
#10/22/2017

##########################################################################################################
##########################################################################################################
###########################################Auto Vending v2.3##############################################
##########################################################################################################
############################# This Macro will Open a shop with items set in ##############################
############################# shop.txt.  It will also refill the store when ##############################
############################# it runs out of items from a NPC vendor as     ##############################
############################# as specified.                                 ##############################
##########################################################################################################
##########################################################################################################

##########################################################################################################
############################ Check Inventory Levels && Open Shop #########################################
##########################################################################################################
##Make sure you have the first batch of items in your cart before running this for the first time.      ##
##It will always keep you well stocked afterwards unl;ess for some reason server goes down or you DC    ##
##during the middle of a restock run.                                                                   ##
##########################################################################################################
##########################################################################################################

automacro Logged_In  {
   exclusive 1 #makes sure nothing else will run while this macro is activated
   delay 1 #creates a delay before activating to give time to login properly
   console /Other players are not allowed to view your Equipment./ #activates the macro on login
   location payon #will only activate if on specified map
   run-once 1
   timeout 10
   call move_to_spot   
}

macro InvCheck  {
   do ai manual
   if   (@cartamount   (Red Potion) <= 1) { #replace Item with Item Name of desired item
      pause 2
      do closeshop
      pause 3
      do move 159 93 #replace xx yy with desired coordinates near merchant NPC
      pause 2
      do talknpc 159 96 b #replace xx yy with desired merchant NPC coordinates
      pause 2
      do buy 1 @eval (500 - @cartamount (Red Potion)) #replace Item with Item Name and 500 with desired
      pause 3                                  #amount to have in cart
      do cart add @eval (975 - @cartamount (Red Potion))
      do talknpc 159 96 b
      pause 2
      do buy 1 @eval (928 - @cartamount (Red Potion))
      pause 3
      do cart add Red Potion @eval (975 - @cartamount (Red Potion))#this line has 975 instead of 500
      pause 5                                           #because that is the target amount to
      release soldoutRED                                  #have in cart but you cannot hold
      call move_to_spot                                  #that many at a time outside of cart
      stop                                           #so by doing this it allows us to buy
   } else {                                           #twice and get the desired amount
      call move_to_spot                                  #into the cart. Especially useful for
      stop                                           #Arrows and Potions
   }
}


macro InvCheck_2  {
   if    (@cartamount    (Item) <= 1) { #replace Item with Item Name of desired item
      pause 2
      do closeshop
      pause 3
      do move XX YY #replace XX YY with desired coordinates near merchant NPC
      pause 2
      do talknpc XX YY b #replace XX YY with desired merchant NPC coordinates
      pause 2
      do buy 3 @eval (200 - @cartamount (Item))#replace Item with Item Name and 100 with desired
      pause 3                                      #amount to have in cart
      do cart add Item @eval (200 - @cartamount (Item)) #replace Item with Item Name amd 200
      pause 5                                       #with the desired amount to have in cart
      release soldoutFLY
      call move_to_spot
      stop
   } else {
      call move_to_spot
      stop
   }
}

macro InvCheck_3  {
   if   (@cartamount    (Item) <= 1) { #replace Item with Item Name of desired item
      pause 2
      do closeshop
      pause 3
      do move XX YY #replace XX YY with desired coordinates near merchant NPC
      pause 2
      do talknpc XX YY b #replace XX YY with desired merchant NPC coordinates
      pause 2
      do buy 4 @eval (100 - @cartamount (Item)) #replace Item with Item Name and 100 with
      pause 3                                             #desired amount to have in cart
      do cart add Item @eval (100 - @cartamount (Butterfly Wing)) #Replace Item w/ Item Name
      pause 5                                                               #and 100 with desired
      release soldoutBFLY                                                   #amount to have in your cart
      call move_to_spot
      stop
   } else {
      call move_to_spot
      stop
   }
}

macro move_to_spot  {
   do move payon XX YY #replace XX YY with coordinates 1 space away from your vending spot
   pause 3              #this will let you face a desired direction (ex. not facing the wall)
   do move 168 67 #replace XX YY with desired coordinates for your shop
   pause 3
   call Vend
}

macro Vend  {
   do openshop
   stop
}


##########################################################################################################
##################################### Restock When Sold Out ##############################################
##########################################################################################################

#Sold Out of Red Potions so this will call a restock for them
automacro soldoutRED {
   exclusive 1
   console /sold out: Red Potion/ #This makes the macro activate when your sell out of specified item
   cart "Red Potion" <= 1 #confirms you are actually out of the item in the cart
   run-once 1
   call restock_1
}

#Sold Out of ITEM so this will call a restock for them
automacro soldoutITEM {
   exclusive 1
   console /sold out: ITEM/ #This makes the macro activate when message shows up in console
   cart "Item Name" <= 1 #confirms you are actually out of the item in the cart
   run-once 1
   call restock_2
}

#Sold Out of ITEM so this will call a restock for them
automacro soldoutITEM2 {
   exclusive 1
   console /sold out: ITEM/ #This makes the macro activate when message shows up in console
   cart "Item Name" <= 1 #confirms you are actually out of the item in the cart
   run-once 1
   call restock_3
}

macro restock_1  {
   pause 30..240  #Creates random delay so shop does not close immediately thus appearing more realistic
   call InvCheck 
}

macro restock_2  {
   pause 30..240  #Creates random delay so shop does not close immediately thus appearing more realistic
   call InvCheck_2
}

macro restock_3  {
   pause 30..240  #Creates random delay so shop does not close immediately thus appearing more realistic
   call InvCheck_3
}


It is not a straight copy/paste and will require some setup to suit your needs. I left the sections for Red Potions in working order other than NPC coords so folks can use it as reference when filling out the rest. Fill in the rest of the info with items you want along with quantites and proper coords and it will fire right up. I am not 100% sure what will happen if it sells out of more than 1 item at a time right now, and is probably going to cause an issue I cannot fix until I get 'if' statements working properly for me. The 3 InvCheck macros used to be 1 solid macro but I had to split them up since the 'if' statements were not working. Once I get it working it will be able to handle selling out of multiple items at a time, and logging in without having items ready to go on first use.

I will also be posting this up in the "Share Your Macros" section once I get it working with all the functionality I want and a few more macros done for the pack I am working on.

Anyways, I went a bit off topic there so sorry about that. Again, if someone can help me get my 'if' functions to run properly I would be very very grateful. Thanks again!


Last edited by BannedForBotting on 06 Nov 2017, 12:30, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Please help me with this macro! @storamount
PostPosted: 23 Oct 2017, 23:26 
Offline
Noob
Noob

Joined: 23 Jun 2008, 18:51
Posts: 6
Yaham wrote:
I have a macro that I use this sintax:


do storage get @storage(Aloe Leaflet) @eval(int(@eval(($PesoMaximo-@eval($.weight))/$.PesoItem))) if (@storamount(Aloe Leaflet) > 0)


For the openkore check trully if the storage is empty, I end my macro with "do talknpc 195 150 c w1 r1 w1 c w1 r0"

This way the macro ends with the storage openned and check trully the amount in storage!


I was going to mess around with this today but I need to ask, what do you have $PesoMaximo, and $.PesoItem defined as in the macro and what exactly do they do? Thanks in advance for the help on this.



I was also toying around today with some things and I was able to get some of my if statements working by moving "goto get" in front of the if statement instead of behind it. I have the "goto get" commented out at the moment because the '&&' statement does not seem to be working. This is an improved version of the vending bot i posted earlier using the if statements working as I have been able to get them to so far. This macro is much more reliable for vending than the other one.

Code:

automacro StartVend {
   delay 1
   console /Other players are not allowed to view your Equipment./
   location #Put the map name of where you want to vend in here. Ex: prontera
   run-once 1
   timeout 10
   call InvCheck
}

#Sold Out of Red Potions
automacro soldoutRED {
   exclusive 1
   console /sold out: Red Potion/
   cart "Red Potion" <= 1
   run-once 1
   call InvCheck
}

macro InvCheck  {
   #goto get    if    ((@cartamount   (Red Potion) <= 1) && (@storamount    (Red Potion) > 0))
   goto get2   if   (@cartamount   (Red Potion) <= 1)
   goto get3
   stop
   :get
      pause 2
      do closeshop
      pause 3
      do move payon XX YY #spot near kafra
      pause 2
      do talknpc XX YY c r1 n #kafra
      pause 2
      do storage addfromcart Red Potion
      pause 1
      do storage gettocart @storage (Red Potion) @eval (876 - @cartamount (Red Potion))
      pause 10
      call InvCheck
      stop
   :get2
      pause 2
      do closeshop
      pause 3
      do move XX YY #spot near NPC merchant
      pause 2
      do talknpc XX YY b e #NPC Merchant
      pause 2
      do buy 1 @eval (500 - @cartamount (Red Potion))
      pause 3
      do cart add @inventory (Red Potion) @invamount (Red Potion)
      pause 10
      do cart add Red Potion
      pause 2
      talknpc XX YY b e
      pause 2
      do buy 1 @eval (876 - @cartamount (Red Potion))
      pause 3
      do cart add @inventory (Red Potion) @invamount (Red Potion)
      pause 10
      do cart add Red Potion
      pause 10
      call InvCheck
      stop
   :get3
      do closeshop
      call move_to_spot
      stop
}

macro move_to_spot  { 
   do move payon XX YY #Location 1 spot away from desired spot
   pause 3
   do move XX YY #Location of desired vending spot
   pause 3
   call Vend
}

macro Vend  {
   do openshop
   release StartVend
   release soldoutRED
}




if anyone has some insight in getting && to work that would be neat. Thanks guys!


Top
 Profile  
 
 Post subject: Re: Please help me with this macro! @storamount
PostPosted: 24 Oct 2017, 01:56 
Offline
Noob
Noob

Joined: 23 Jun 2008, 18:51
Posts: 6
So I finally figured out what I did wrong....was some extra "( )" tucked into the statements. I have vending macro working as I had originally intended so here it is. I also figured that if I just used a "< 1" when checking for storage, it would not matter if it returned -1 instead of 0 when it ran out. Thanks for the help!


Top
 Profile  
 
 Post subject: Re: [Solved]Please help me with this macro! @storamount
PostPosted: 07 Apr 2018, 15:40 
Offline
Moderators
Moderators
User avatar

Joined: 16 Dec 2011, 02:53
Posts: 1211
Location: Brazil
https://github.com/Henrybk/Plugins/tree/master/mercAI

_________________
"'There are three things all wise men fear: the sea in storm, a night with no moon, and the anger of a gentle man.'" :P

viewtopic.php?f=10&t=16117

Thanks for this Eternal! =D <3<3


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group