Checking for items in Hagnks

Pazleysox

Member
Is there a script command to see if you have any item in storage?

I'm trying to write an informational script for myself to remind me what items I should pull for max rollover turns, and want to check for items before I just start pulling things.
 

Pazleysox

Member

I tried this, wrote the file I wanted mapped, and get nothing in return.

Or if you want a list, like get_inventory() returns, looks like get_storage() exists from the code.

I've looked into those....

I've tried this too:

Code:
int item_count() {
   item x = $item[knob goblin firecracker];
   int counter = item_amount( x ) + closet_amount( x ) + storage_amount( x );
   return counter;
}
This returns nothing.

I can't figure it out... for the time being, I just wrote a simple script to pull the stuff I know I have, and equip it.
 

xKiv

Active member
Is it possible that mafia thinks you already emptied your hagnks this ascension? Then it wouldn't check storage during session refresh, and storage_amount(x) would == 0 for all x until you force the refresh somehow (does visiting hagnk's work?)
 

Pazleysox

Member
Is it possible that mafia thinks you already emptied your hagnks this ascension? Then it wouldn't check storage during session refresh, and storage_amount(x) would == 0 for all x until you force the refresh somehow (does visiting hagnk's work?)

I'm only testing these scripts when I'm in ronin (which is pretty much all the time). I've even tried this:
Code:
int item_count() {
   item x = $item[knob goblin firecracker];
   int counter = storage_amount( x );
   return counter;
}

And got nothing returned. I'm also looking at the other thread about clubs/enchantments. It might be able to be done a few ways.
 

Pazleysox

Member
I've discovered multiple ways of looking for things in storage now. I've been screwing around with a bunch of codes, and here's 4 that i've come up with

This one is pretty simple, and a great way to search for 1 item.
PHP:
{
int[item] inventory = get_storage() ;
	item it = $item[2-ball];
   if ( inventory[it] > 1 ) 
      print ("You have " + it, "green");
	else print ("You don't have " + it);
}
I wanted to search for multiple items though, so I worked to find a way to do it.
PHP:
{
int[item] inventory = get_storage() ;
	item it = $item[2-ball];
   if ( inventory[it] > 1 ) 
      print ("You have " + it, "green");
	else print ("You don't have " + it);
}
//have to split these up, or mafia will come up with error.  This can be repeated as many times as needed/wanted.
{
int[item] inventory = get_storage() ;
	item it = $item[3-ball];
   if ( inventory[it] > 1 ) 
      print ("You have " + it, "green");
	else print ("You don't have " + it);
}
This one is almost identical to the one above, but allows for multiple searches, without writing multiple lines of the same code, like the code above.
This code is the one I think I will use for the script I'm writing.
PHP:
{
int[item] inventory = get_storage() ;
	foreach it in $items[8-ball, 3-ball, 4-ball, talisman of baio]
   if ( inventory[it] >= 1 ) 
      print ("You have " + it, "green");
	else print ("You don't have " + it, "red');
}
This next one is obviously not the best code, but amazingly it was the first one I found that worked. I stole the whole thing from another script that I wrote, and never released.
PHP:
{
int[item] inventory = get_storage() ;
boolean firecracker = false;
	item it = $item[knob goblin firecracker];
	if ( inventory [it] >= 1)
		{ firecracker = true;	}
	if (firecracker) {print ("You have " + it , "green");}
		else {print ("You do not have" + it , "red");}
}
 

xKiv

Active member
So get_storage()[it] returns the correct amount, but storage_amount(it) doesn't? Both work for me (in aftercore, but I haven't "pulled all").

...

Code:
int item_count() {
   item x = $item[knob goblin firecracker];
   int counter = storage_amount( x );
   return counter;
}
Is that all? Are you not *calling* the function you defined? That would explain why nothing is returned ...
 

Pazleysox

Member
So get_storage()[it] returns the correct amount, but storage_amount(it) doesn't? Both work for me (in aftercore, but I haven't "pulled all").

...

Code:
int item_count() {
   item x = $item[knob goblin firecracker];
   int counter = storage_amount( x );
   return counter;
}
Is that all? Are you not *calling* the function you defined? That would explain why nothing is returned ...

get_storage()[it] returns a true or false.

I've been messing around with storage_amount(it), and can't get it to work... I'm not sure what you mean about "calling" the function...

For the script I'm trying to write, the get_storage()[it] command is perfect. Knowing how many if [it] I have doesn't make a difference. BUT having said that, learning how to get storage_amount(it) to work properly would be nice.
 

lostcalpolydude

Developer
Staff member
I'm not sure what you mean about "calling" the function...

The functions you posted should at least return 0, if mafia was giving bad info about what you have in storage. If it didn't even return that, then your code is at fault. A script that just has a function that you never call will do nothing.
 

AlbinoRhino

Active member
Code:
int item_count() {
   item x = $item[knob goblin firecracker];
   int counter = storage_amount( x );
   return counter;
}

What you have posted is a function definition. The function is named " item_count() ". In order to have the script actually run that code, you need to "call" the function from somewhere in the script.

You would do that by placing:

item_count();

at the place in your script where you want your function to run the code it contains.

The function returns an integer. In order to actually see that return, you would need to 'capture' the return value and then print it.

So...

int x = item_count(); ( x will capture the return value)

print(x); ( to see what that return value was )

edit:
or you could add a

print(counter);

line to your function, and it will print the value each time it is " called ".
 
Last edited:

xKiv

Active member
get_storage()[it] returns a true or false.

That's weird, because it seems to be a syntax error on my end.

(I had to use instead: ash int[item] i=get_storage(); i[$item[...]];)
(and it returns the same (correct) number as storage_amount($item[...]))
 

Pazleysox

Member
Code:
edit:
or you could add a 

print(counter);

line to your function, and it will print the value each time it is " called ".[/QUOTE]

I'm even more confused than before.  LOL  I guess I should leave this stuff to the experts, and only dabble when I can figure it out!  :p
 

ckb

Minion
Staff member
I'm even more confused than before. LOL I guess I should leave this stuff to the experts, and only dabble when I can figure it out! :p

Maybe if you describe what you want your code to do, we can help guide you through it, and develop a script to do what you need.
 

AlbinoRhino

Active member
int item_count() < function will return an integer, function is named 'item_count()'
{
item x = $item[knob goblin firecracker]; < 'x' is the item to count
int counter = storage_amount( x ); < 'counter' is the storage amount of ' x'
< 'counter' now has a value we can do something with

< AFTER 'counter' has a value, and BEFORE we exit the function we can print the value

print("You have "+counter+" of "+x+" in Hagnk's.");

return counter; < exit the function and 'return' to the place in the code that the function was called from
}


< somewhere later in the script,

item_count();

< the function has been called, the code it contains will run. The code contains a 'print()' line. The storage_amount and name of the item will be printed.
 
Last edited:

Pazleysox

Member
int item_count() < function will return an integer, function is named 'item_count()'
{
item x = $item[knob goblin firecracker]; < 'x' is the item to count
int counter = storage_amount( x ); < 'counter' is the storage amount of ' x'
< 'counter' now has a value we can do something with

< AFTER 'counter' has a value, and BEFORE we exit the function we can print the value

print("You have "+counter+" of "+x+" in Hagnk's.");

return counter; < exit the function and 'return' to the place in the code that the function was called from
}

< somewhere later in the script,

item_count();

< the function has been called, the code it contains will run. The code contains a 'print()' line. The storage_amount and name of the item will be printed.

Wow, this looks so easy now that it's spelled out for me (duh). I took this, and ran it, and (of course) it worked perfect. Now I can work on my script! (yay) (I would put if in here now, but...) WHEN I run into more trouble, I'll ask here again. Thank you so much for your help. I greatly appreciate it.

Maybe if you describe what you want your code to do, we can help guide you through it, and develop a script to do what you need.

Lol, AlbinoRhino just spelled it out for me. I'm n00bish when it comes to scripting. I usually bully my way through what I want, but I have enough knowledge to do very simple things.

Next Question: Is it possible to do a search for multiple items at once?
Code:
{   int[item] inventory = get_storage() ;
	foreach it in $items[8-ball, 3-ball, 4-ball, talisman of baio]
   if ( inventory[it] >= 1 ) 
      print ("You have " + it, "green");
	else print ("You don't have " + it);   }

kind of like this code does, but with a count for each item?

Code:
void main()
{
int item_count(){
item x = $item[knob goblin firecracker];
int counter = storage_amount( x ); 
print("You have "+counter+" of "+x+" in Hagnk's.");

return counter; 
}
item_count();
{
int item_count(){
item x = $item[8-ball];
int counter = storage_amount( x ); 
print("You have "+counter+" of "+x+" in Hagnk's.");

return counter; 
}
item_count(); 

}}
I know this way works, but is there a simpler way to do this?

Edit:
It looks like from Darzil's first post, there *IS* a way to do it. I would have to map what I'm looking for. I'll work on this.
 
Last edited:

AlbinoRhino

Active member
The code you have here:

PHP:
{   int[item] inventory = get_storage() ;
    foreach it in $items[8-ball, 3-ball, 4-ball, talisman of baio]
   if ( inventory[it] >= 1 ) 
      print ("You have " + it, "green");
    else print ("You don't have " + it);   }


int[item] inventory = get_storage() ;
...is most of the way there. get_storage() returns a map of ITEM_AMOUNT[item]. You have named that map 'inventory'.


< a foreach loop will go through each key in the map (in this case that map has [item] keys)

foreach i in inventory <i.e. each item in my map (in this case it's actually items in storage, not inventory)

foreach i in inventory
{
print(i + " " + inventory);
<--- print the 'key' (an item 'i') and the value associated with that key (in this case the amount of i in storage ) in the form MAP_NAME[key] --- so --- ' inventory ' represents the storage amount for any particular item ' i ' )
}

The above should list everything in Hagnk's along with the amount Hagnk is holding for you.


Keep at it ! It all gels together in the end !
 
Last edited:

ckb

Minion
Staff member
You can get data from functions, and also pass them data.
A modification of your item_count() function might take the item as input, and print the amount you have in storage. You return an int of the quantity, but you are not using it in your example.
Order of your function definitions is important. Usually, you define your individual utility functions, then call them from a main() statement.

Here is an example of a modified item_count() that takes an item as an argument, prints the info, then returns an int of the quantity:
PHP:
int item_count(item it) {
	int counter = storage_amount(it); 
	print("You have "+counter+" of "+it+" in Hagnk's.");
	return counter; 
}

We can use this new function for multiple items, calling it multiple times in a loop. We define that function first, then call it from main(). For fun and education, I added a new variable that sums the total number of items checked and prints that at the end.

PHP:
int item_count(item it) {
	int counter = storage_amount(it); 
	print("You have "+counter+" of "+it+" in Hagnk's.");
	return counter; 
}

void main() {
	int xx = 0;
	foreach it in $items[8-ball, 3-ball, 4-ball, talisman of baio] {
		xx = xx + item_count(it);
	}
	print("You have a total of "+xx+"items!");
}

Yea! Scripting is fun!
 
Last edited:

Pazleysox

Member
The code you have here:

PHP:
{   int[item] inventory = get_storage() ;
    foreach it in $items[8-ball, 3-ball, 4-ball, talisman of baio]
   if ( inventory[it] >= 1 ) 
      print ("You have " + it, "green");
    else print ("You don't have " + it);   }


int[item] inventory = get_storage() ;
...is most of the way there. get_storage() returns a map of ITEM_AMOUNT[item]. You have named that map 'inventory'.


< a foreach loop will go through each key in the map (in this case that map has [item] keys)

foreach i in inventory <i.e. each item in my map (in this case it's actually items in storage, not inventory)

foreach i in inventory
{
print(i + " " + inventory);
<--- print the 'key' (an item 'i') and the value associated with that key (in this case the amount of i in storage ) in the form MAP_NAME[key] --- so --- ' inventory ' represents the storage amount for any particular item ' i ' )
}

The above should list everything in Hagnk's along with the amount Hagnk is holding for you.


Keep at it ! It all gels together in the end !


This s great! I didn't realize it would be that easy. Script works great so far!

Next issue:
Code:
	if ((it) > 0)
	{
	print ("You have " + it + " " + inventory[it],  "green");
	}

How can I make this work? IE If there is 0 in storage, it won't printout anything...
 

AlbinoRhino

Active member
This s great! I didn't realize it would be that easy. Script works great so far!

Next issue:
Code:
    if ((it) > 0)
    {
    print ("You have " + it + " " + inventory[it],  "green");
    }

How can I make this work? IE If there is 0 in storage, it won't printout anything...

PHP:
foreach i in inventory
{
print(i + " " + inventory[i]);   <--- ' inventory[i] ' represents the storage amount for any particular item ' i '
}

So...

PHP:
foreach i in inventory
{
  if ( inventory[i] > 0 )     <--- ' inventory[i] ' represents the storage amount for any particular item ' i '
  {
  print(i + " " + inventory[i]);
  }
}

... should print any item with a storage amount > 0. However, get_storage() should only return items where that is true. Which makes me think you are no longer using get_storage(). In which case I need to see more of your code than you have posted to be sure... but generally ...

if ( item_amount(it) > 0 ) {} <---- Items in inventory

or

if ( storage_amount(it) > 0 ) {}

or

if ( available _amount(it) > 0 ) {} <---- Items that are ' available ' to you according to the game state and your autoSatisfy settings.
 
Last edited:

Pazleysox

Member
if ( available _amount(it) > 0 ) {} <---- Items that are ' available ' to you according to the game state and your autoSatisfy settings.

Here's what i ended up tryng:

PHP:
void main()
{
	foreach it in $items[
8-ball,
3-ball, 
2-ball, 
anticheese,
talisman of baio]
	{
		if (available_amount(it) >= 1 || storage_amount(it) >=1 )
	{
	print ("You have " + available_amount(it) + " " +it+ " on hand, and " + storage_amount(it) + " in storage", "green");	}
		
} }
and here's the printout:
You have 0 8-ball on hand, and 33 in storage
You have 0 3-ball on hand, and 6 in storage
You have 0 2-ball on hand, and 11 in storage
You have 1 anticheese on hand, and 21 in storage

This is perfect for me right now! This is exactly what I'm looking for the script to do.

The available_amount(it) looks at what I have in my inventory. I'm not sure what setting to change, but it's ok. I'm happy with the script the way it will come out.
 
Last edited:
Top