Discard script

tyilo

Member
Code:
boolean discard(int number, item stuff)
{
	int amount = item_amount(stuff);
	for counter from 1 upto number
	{
		visit_url("inventory.php?action=discard&pwd=" + my_hash() + "&whichitem=" + to_int(stuff));
	}
	if(amount == 0)
	{
		print("You don't have any " + to_plural(stuff) + ".", "red");
		return false;
	}
	if(amount - number == item_amount(stuff))
	{
		print("Discarded " + number + " " + to_plural(stuff) + " successfully.", "green");
		return true;
	}
	else
	{
		print("Could only discard " + (amount - item_amount(stuff)) + " out of " + number + ".", "red");
		return false;
	}
}
boolean discard(item stuff)
{
	return discard(item_amount(stuff), stuff);
}
the syntax is either
boolean discard(int amount, item it)
or
boolean discard(item it)
the last one discarding all items of that type
 
Last edited:

StDoodle

Minion
I might feel better about using this script if it had a built-in check to make sure that "discard" was the only way to get rid of the items passed to it. In fact, I really should have used something like this when I got rid of all my useless powder a while back.
 

Veracity

Developer
Staff member
I use something very similar to this to get rid of useless powder. Scary? You gotta do what you gotta do.
 

Bale

Minion
I might feel better about using this script if it had a built-in check to make sure that "discard" was the only way to get rid of the items passed to it.
Here's something less scary:

Code:
boolean red_out(string message) { print(message, "red"); return false; }

boolean discard(int number, item stuff)
{
	if(is_tradeable(stuff)) return red_out("Don't discard that! It can be malled!");
	if(autosell_price(stuff) > 0) return red_out("Don't discard that! It can be autosold!");
	int amount = item_amount(stuff);
	for counter from 1 upto number
	{
		visit_url("inventory.php?action=discard&pwd=" + my_hash() + "&whichitem=" + to_int(stuff));
	}
	if(amount == 0)
	{
		print("You don't have any " + to_plural(stuff) + ".", "red");
		return false;
	}
	if(amount - number == item_amount(stuff))
	{
		print("Discarded " + number + " " + to_plural(stuff) + " successfully.", "green");
		return true;
	}
	else
	{
		print("Could only discard " + (amount - item_amount(stuff)) + " out of " + number + ".", "red");
		return false;
	}
}
boolean discard(item stuff)
{
	return discard(item_amount(stuff), stuff);
}
 
Last edited:

zarqon

Well-known member
Handy! I'd at least add something to autosell items rather than discard them if they have an autosell value, to slightly reduce scariness. Optionally, you could add something to check if the item is selling for more than minmall, in which case it would send the item to me. :)

PHP:
boolean discard(int num, item stuff) {
   int initamount = item_amount(stuff);
   num = min(max(num,0),initamount);
   if (num == 0) return true;
   if (autosell_price(stuff) > 0) return autosell(num,stuff);
   for i from 1 upto num
      visit_url("inventory.php?action=discard&pwd&whichitem="+to_int(stuff));
   return (item_amount(stuff) == initamount - num);
}
boolean discard(item stuff) {
   return discard(item_amount(stuff), stuff);
}

EDIT: Ha, I missed Bale's post. Bale: vprint() is a better name than red_out(). ;)
 
Last edited:
...which makes it not-quite-as-useless powder. Ah, the irony.

You never know, maybe one day TPTB will implement a use for the useless.
 

goom

New member
and here is some progress i made
Code:
boolean red_out(string message) { print(message, "red"); return false; }

[COLOR="Red"]Void main( int number ){[/COLOR]

[COLOR="Red"][B][U]item stuff = $item[];[/U][/B][/COLOR]

    boolean discard(int number, item stuff)
    {
            if(is_tradeable(stuff)) return red_out("Don't discard that! It can be malled!");
            if(autosell_price(stuff) > 0) return red_out("Don't discard that! It can be autosold!");
        int amount = item_amount(stuff);
    for counter from 1 upto number
        {
            visit_url("inventory.php?action=discard&pwd=" + my_hash() + "&whichitem=" + to_int(stuff));
        }
    if(amount == 0)
        {
            print("You don't have any " + to_plural(stuff) + ".", "red");
            return false;
        }
    if(amount - number == item_amount(stuff))
        {
            print("Discarded " + number + " " + to_plural(stuff) + " successfully.", "green");
            return true;
        }
    else
        {
            print("Could only discard " + (amount - item_amount(stuff)) + " out of " + number + ".", "red");
            return false;
        }
    }
    boolean discard(item stuff)
    {
        return discard(item_amount(stuff), stuff);
    }
}

i added the pop up that asks you how many items to discard

now all i need is a way to make mafia pop up a message to ask me which item i want to mass discard,
you can see my attempt to do so in the red underlined text, i know it makes no sense
but i'm learning this language as i go along and i have very basic understanding at programming
 

Bale

Minion
The only way you can get mafia to prompt you for an item is to put it in the declaration for main(). There is no mafia command to prompt the user other than user_confirm() which will only return a boolean value.

In other words, declare void main(int number, item stuff)
 

goom

New member
ok, so i deleted that silly "item stuff = $item[];"
and canged the "void main(int number)" to "void main(int number, item stuff)"
it now prompts for both values but still does nothing
no error messege
and it haven't discarded anything
 

StDoodle

Minion
Well, actually, you can prompt for a lot more if you use a relay info script; that's just a bit more complicated, though.
 

Theraze

Active member
Make your void main() call discard(number, stuff); Also, I'd suggest not putting the discard function inside main, unless you don't want to be able to call it from another script/alias.
 

goom

New member
Make your void main() call discard(number, stuff); Also, I'd suggest not putting the discard function inside main, unless you don't want to be able to call it from another script/alias.

i'm really a coding n00b and i'm not a native english speaker
could you modify the code and highlight the changes?
sorry for being such a lame coder
 
Top