Is item check?

Nightmist

Member
Is there some way to check if a string name corresponds to a item name?
I tried string_to_item, but that throws a error when it isnt a actual item.

Just wondering... (Yes for the trade response script again =P)
 

holatuwol

Developer
I would give you a hook straight into the internal data for it, except mafia's actually not sensitive at all, and it will return TRUE provided some suffix portion of whatever you give it matches an item name.  For example, if you gave it "hello my name is cherry pie", it would tell you TRUE in later builds which have cherry pie, because it knows there's an item ID for cherry pie, and that long old string might have been a plural.  Instead:

boolean is_valid_item_name( string substring )
{
    for id from 1 to 2010
        if ( contains_text( item_to_string( int_to_item( id ) ), substring ) )
            return true;

    return false;
}

Edit: Although I guess I could use the other internal method which is actually used when you do an item name lookup for things entered via the CLI (which is what the ASH uses, which is slightly different from what the rest of mafia uses, and which might result in equally strange things happening, for example "$item[200 668 scroll]" would give you the item representing 668 scrolls, whether or not you wanted it that way).  What's the code you want to use look like?
 

Nightmist

Member
I haven't actually coded it just yet, it's going to be for a part of my trade response script though and I'm planning to pull out requests for specific items and the requested quantity from the trade note and work from that. (Thats easily done with the new substring and index_of)

Your example using the "for id from" and such would actually work for what I'm trying to do but then is there a way to find out what the highest item number in the internal database that mafia has? (Since just checking for a $item[none] breaks since theres empty item number slots... I could set it to a insanely high value but then that would just waste time checking for items that are not even in the internal datafiles.)
 
Top