Item drops array: Difference between revisions
Jump to navigation
Jump to search
imported>Heeheehee New function, new page! |
Add "a" type to results (Accordion Thief-able item) |
||
(17 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
{{ | {{ | ||
#vardefine:name|item_drops_array}}{{ | #vardefine:name|item_drops_array}}{{ | ||
#vardefine:return_type|int | #vardefine:return_type|record [int]}}{{ | ||
#vardefine:aggregate|yes}}{{ | #vardefine:aggregate|yes}}{{ | ||
FunctionPage| | FunctionPage| | ||
name={{#var:name}}| | name={{#var:name}}| | ||
function1={{Function| | function1={{Function| | ||
name={{#var:name}}| | name={{#var:name}}| | ||
aggregate={{#var:aggregate}}| | aggregate={{#var:aggregate}}| | ||
return_type={{#var:return_type}}| | return_type={{#var:return_type}}| | ||
return_also={{#var:return_also}} | return_also={{#var:return_also}} | ||
}}| | |||
function2={{Function| | |||
name={{#var:name}}| | |||
aggregate={{#var:aggregate}}| | |||
return_type={{#var:return_type}}| | |||
return_also={{#var:return_also}}| | |||
parameter1={{Param|monster|check_me}}| | |||
p1desc={{Pspan|check_me}} is the (optional) monster to check.| | |||
}}| | }}| | ||
Line 22: | Line 28: | ||
int rate; | int rate; | ||
string type; | string type; | ||
} | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</p><p> | </p><p> | ||
Since this is the first function to return a record, it cannot be stored to a variable, and thus the only way to access the data is by iterating over the elements in the | The 'type' field has these currently possible values: | ||
* "" - normal item drop, base drop rate in the 'rate' field. | |||
* "0" - no drop rate information available, 'rate' will be zero. | |||
* "n" - not pickpocketable, but otherwise drops according to 'rate'. | |||
* "c" - conditional drop. | |||
* "p" - pickpocket-only. | |||
* "b" - bounty item, 'rate' is meaningless. | |||
* "a" - accordion item. | |||
</p><p> | |||
Since this is the first function to return a record, it cannot be stored to a variable, and thus the only way to access the data is by iterating over the elements in the array.| | |||
code1={{CodeSample| | code1={{CodeSample| | ||
Line 37: | Line 52: | ||
print("item: "+rec.drop+", drop rate: "+rec.rate+", type: "+rec.type); | print("item: "+rec.drop+", drop rate: "+rec.rate+", type: "+rec.type); | ||
} | } | ||
</syntaxhighlight> | |||
}} | |||
{{CodeSample| | |||
description=Saves item drop information in a custom-defined map for later usage.| | |||
code= | |||
<syntaxhighlight> | |||
record dropdata { | |||
item drop; | |||
int rate; | |||
string type; | |||
}; | |||
dropdata [int] loc_mon_it; | |||
dropdata [monster][int] all_mon_drops; | |||
foreach i1, mob in get_monsters($location[Orc Chasm]) | |||
foreach index, rec in item_drops_array(mob) { | |||
all_mon_drops [mob][index].drop = rec.drop; | |||
all_mon_drops [mob][index].rate = rec.rate; | |||
all_mon_drops [mob][index].type = rec.type; | |||
} | |||
foreach mob, index, data in all_mon_drops { | |||
string rate = data.rate + "%"; | |||
if(data.type == "0") | |||
rate = "unknown rate"; | |||
if(data.type != "p" && data.type != "b") | |||
print(mob+", drops "+data.drop+" @ "+rate); | |||
} | |||
</syntaxhighlight> | </syntaxhighlight> | ||
}}| | }}| | ||
see_also={{SeeAlso|meat_drop|item_drops}}| | see_also={{SeeAlso|meat_drop|item_drops}}| | ||
special=The zero-parameter form returns the last monster encountered (the current one, if used in combat). | special=The zero-parameter form returns the last monster encountered (the current one, if used in combat).| | ||
more_info=see [http://kolmafia.us/showthread.php?3866 this thread].| | |||
}} | }} | ||
[[Category:Item Management]] |
Latest revision as of 22:01, 8 September 2023
Function Syntax
record [int] item_drops_array()
record [int] item_drops_array(monster check_me )
- check_me is the (optional) monster to check.
Returns an array of records with three fields:
record {
item drop;
int rate;
string type;
};
The 'type' field has these currently possible values:
- "" - normal item drop, base drop rate in the 'rate' field.
- "0" - no drop rate information available, 'rate' will be zero.
- "n" - not pickpocketable, but otherwise drops according to 'rate'.
- "c" - conditional drop.
- "p" - pickpocket-only.
- "b" - bounty item, 'rate' is meaningless.
- "a" - accordion item.
Since this is the first function to return a record, it cannot be stored to a variable, and thus the only way to access the data is by iterating over the elements in the array.
Code Samples
Prints all information Mafia has regarding the item drops of a certain monster.
void drops(monster mob){
print("Monster: " + mob);
foreach index, rec in item_drops_array(mob)
print("item: "+rec.drop+", drop rate: "+rec.rate+", type: "+rec.type);
}
Saves item drop information in a custom-defined map for later usage.
record dropdata {
item drop;
int rate;
string type;
};
dropdata [int] loc_mon_it;
dropdata [monster][int] all_mon_drops;
foreach i1, mob in get_monsters($location[Orc Chasm])
foreach index, rec in item_drops_array(mob) {
all_mon_drops [mob][index].drop = rec.drop;
all_mon_drops [mob][index].rate = rec.rate;
all_mon_drops [mob][index].type = rec.type;
}
foreach mob, index, data in all_mon_drops {
string rate = data.rate + "%";
if(data.type == "0")
rate = "unknown rate";
if(data.type != "p" && data.type != "b")
print(mob+", drops "+data.drop+" @ "+rate);
}
See Also
More Information
see this thread.
Special
The zero-parameter form returns the last monster encountered (the current one, if used in combat).