PDA

View Full Version : int buy( int quantity, item it, int price_limit ) usage



hotdeth
01-27-2010, 02:47 PM
I'm new to ash but have done a little CLI scripting. I decided the other day that I want to start collecting spooky shroomkabobs and am looking for something to buy some every day as long as they are below a certain price.

It appears that: int buy( int quantity, item it, int price_limit ) is the perfect commant however I'm not quite sure how to use it in the CLI or if it must be in an ASH script.

my understanding of the usage: buy ( 1 , "spooky shroomkabob", 101 )

the CLI treats this like the "buy 1 spooky shroomkabob " and complains if there is a max meat price.

Can somone point me in the right direction either on this functions usage or an ash script that already contains this function so I can figure it out?

Thanks!

P

jasonharper
01-27-2010, 04:55 PM
buy ( 1 , $item[spooky shroomkabob], 101 ) is how you'd do this from ASH.
buy 1 spooky shroomkabob @ 101 is the equivalent CLI command.

hotdeth
01-28-2010, 11:17 AM
Thanks! I was able to get the buy to work via the CLI however I am still having issues getting it to work in an ash script.

putting the command given in an .ash file and running it gives the following results:

Expected ;, found null (Collecting.ash, line 1)

mredge73
01-28-2010, 12:24 PM
read the error, all commands in ash end with ;

SinginSally
01-28-2010, 01:23 PM
Keep in mind that you can always do it the lazy/noob way.

cli_execute("buy 1 spooky shroomkabob @ 101");

Since you are familiar with CLI commands, you can easily ash script whatever you want by simply cli_executing. You can 'assemble' a command as well, such as...

cli_execute("buy " +numShroomToBuy +" spooky shroomkabob @ " +maxPrice);

where the 2 variables are ints of course. The only catch is you have to be CAREFUL about spacing. Note the space after Buy and before Spooky.

hotdeth
01-28-2010, 02:03 PM
Hmmm I could have sworn I had added the ; at the end and tried it already. I didn't happen to see the need for a ; at the end of every line in the Advanced scripting guide.

Sally: Thank you very much for the info. this will be very helpful to play with. I've noticed when doing two of these that if the first one returns < 1 the script is aborted. is there a way to continue execution even if the purchase fails?

Thanks for all the help and putting up with stupid questions!

SinginSally
01-28-2010, 08:13 PM
Man, that is a good question. BTW, when I referred to doing it the noob way, I was definitely referring to myself. I am brand new at it and didn't know Ashref even existed. So many of my scripts still use cli_execute in one form or another.

I cant imagine why it would abort though. Does it abort just when you do the cli_execute version of buy, or when you use the 'real' ash command, or both?

I guess you could try to catch the variable and maybe that will make it happier somehow?

i.e. int didItBuy = cli_execute(buy....);

Grotfang
01-30-2010, 09:41 AM
void main( int numShroomToBuy , int maxPrice )
{
cli_execute("buy " + numShroomToBuy + " spooky shroomkabob @ " + maxPrice);
}

Can't see why that would abort...

heeheehee
01-30-2010, 04:28 PM
Normally, it'll abort. It's a bit interesting to work with this, because while buy(int qty, item it) is a boolean, buy(int qty, item it, int lim) is an integer reflecting how many you bought.

void main(int qty, item it, int lim) {
int q = buy( qty,it,lim);
print("Bought "+it+" ("+q+")"+".");
}

This is a really wonky result. The above will execute everything even if you don't buy anything, but the following will abort if the limit prevents the script from buying the desired quantity:

void main(int qty, item it, int lim) {
buy( qty,it,lim);
print("All done!");
}

Both will print the "Stopped purchasing item @ price.", which is innate to Mafia. Interesting, huh?

slyz
01-31-2010, 09:27 AM
I guess you could try to catch the variable and maybe that will make it happier somehow?

i.e. int didItBuy = cli_execute(buy....);

That.

EDIT: except with the ash version.

mredge73
02-01-2010, 02:07 PM
To keep it from aborting you should be able to catch the variable like we do with adventure().



if(!buy(qty,it))
print("Buy Failed","red");

if(buy(qty,it,lmt)<0)
print("Buy Failed","red");

SinginSally
02-17-2010, 03:47 PM
I guess you could try to catch the variable and maybe that will make it happier somehow?

i.e. int didItBuy = cli_execute(buy....);

Heh. One heck of a lucky guess huh? :-) Glad it worked out for you. I might try to make a similar script, so it is good that you blazed the trail for me.