Display case manager script help

Now I'm really puzzled. Last night when I couldn't get the code you posted to work I restarted mafia and tried it again, with no success. Then I posted here and logged out. I haven't altered anything (in fact, the computer hasn't been touched) but this morning when I ran it, it worked perfectly.

EDIT:
This seems unnecessary however. If you are already using or plan on using Bale's excellent OCD Inventory Control script I would suggest just taking the time to set it up. New content comes out at a rate that is fairly easy to keep up with.

You're absolutely right, but I'm a bit, well, obsessive compulsive. Besides, 90% of what I do here is aimed at simply learning how to script, that only leaves 10% for practicality.

EDIT2: Doesn't that bit of code you posted tell OCD to save only as many of a particular item as there are in my DC? What if I wanted to instruct it to save as many as I had (ie: save [$item[item name]] == -1; )?
 
Last edited:
EDIT2: Doesn't that bit of code you posted tell OCD to save only as many of a particular item as there are in my DC? What if I wanted to instruct it to save as many as I had (ie: save [$item[item name]] == -1; )?

Code:
int [item] DC;
 file_to_map("DC Data.txt", DC);
foreach key, num in DC
     save [key] = num;
That code instructs OCD to save whatever the second column in the DC Data.txt tells it to. If the number is a negative number ALL of that item will be saved, if the number is 5 then 5 will be saved, if the number is 0 then 0 will be saved.
 
Last edited:
Thanks Ninja, that makes perfect sense.

I added a condition to only put my bag o' tricks into my DC if I'm level 13 or below. I also modified how the script responds to the second column for better integration with OCD. Here's how it looks now, if any bugs or inefficiencies leap out at you please let me know how I can fix them.
Code:
int [item] list; 

void setup_display() { 
    file_to_map("DC Data.txt", list); 
    foreach key in $items[] 
            if(display_amount(key)>0 && key == $item[bag o' tricks] && my_level() > 13) 
                list [key] = 0;
            else
            if(display_amount(key)>0 && !(list contains key)) 
                list [key] = -1; 
    map_to_file(list, "DC Data.txt"); 
} 

void display_stuff() {
    print("Putting...");
    foreach key in list
        if(item_amount(key)>0 && list[key] != 0)
               print(" "+key, "blue");
    print("... into display case");    
    foreach key in list
        switch {
        case list[key] == 0:
            print("Not putting "+key+" in display case at the moment");
            break;
        case list[key] == -1:
            put_display(item_amount(key), key);
            break;
        case list[key] > 0: 
            int dis_amount = max(list[key] - display_amount(key), 0);
            if(dis_amount >0 && item_amount(key) > 0)
                put_display(min(item_amount(key), dis_amount), key);
            break; 
        }
    print("DC updated", "green");
}

void main() {
    setup_display();
    display_stuff();
I'd like to thank you both (and Spiny and Alhifar who chimed in before) for the help you've given me. I realise you guys have done most (ie: all) of the work, but I've learned a heap trying to keep up with you.
 
At first glance it looks good. I did notice that your main is missing its closing curly brace, but I assume it just didn't get copied over. It has come a long ways. Cheers.
 
Oh yeah, sorry, that was a copy/paste error.

Well on testing it I find that it won't update "DC Data.txt" quite as I'd hoped.
Code:
if(key == $item[bag o' tricks] && my_level() > 13) 
                list [key] = 0;
Now that works fine, but when my level is below 13 (I used < 13 to test) the associated number in the second column remains the same (0) rather than being updated to -1.

EDIT: Oh and note that I removed display_amount(key)>0 because it was counter-productive (if I don't want it put in my DC, then display_amount should be 0 anyway).

EDIT2: I found another simpler method of adding conditional handling:
Code:
void setup_display() {
    file_to_map("DC Data.txt", list);
    foreach key in $items[] //Conditional handling goes here
        if(key == $item[bag o' tricks] && my_level() > 13) //If my level is above 13, don't put BoT in DC
            remove list [key];
        else
        if(display_amount(key)>0 && !(list contains key))
            list [key] = -1;
    map_to_file(list, "DC Data.txt");
}
And to ensure OCD saves it even when my_level() !> 13 I just add save [$item[bag o' tricks]] to "OCD Data Creator.ash". Actually I don't even have to do that as Bale kindly put all the Mr. Store items in already.

EDIT3: Haha, the script I attached makes me cry. All that effort... I'm going to have fun editing it! :D
 
Last edited:
Back
Top