Question about estimated pricing

scrambles

New member
in my script i have a list of tradable items to be bought, and used. The problem is is that some of the items are REALLY expensive, and i dont want anybody to run it with out fair warning about how much meat could possible be spent on such items.

How would i go about doing this?
 

slyz

Developer
That depends on how you wrote your script. We can help you if you post it.

EDIT: And I didn't understand the title... what does your question have to do with estimated pricing?
 

scrambles

New member
this is how i wrote the script, not the entire script but this is the main chunk that should be priced.
also I think the tittle of the thread was in relation to an additional function i want the script to preform.

thanks for the help, i am fairley new to scripting and i just have no idea about how to go about this additional function.
Also yes this is an ash script

retrieve_item( 17, $item[prismatic wad] );

retrieve_item( 3, $item[mojo filter] );

retrieve_item( 5, $item[munchies pill] );

retrieve_item( 5, $item[ol' scratch's salad fork] );

retrieve_item( 17, $item[prismatic wad] );

retrieve_item( 6, $item[frosty's frosty mug] );

retrieve_item( 1, $item[spice melenge] );

retrieve_item( 1, $item[pumpkin pie] );

retrieve_item( 1, $item[hodgman's blanket] );

retrieve_item( 1, $item[pumpkin beer] );

retrieve_item( 3, $item[jar of fermented pickle juice] );

retrieve_item( 3, $item[extra-greasy slider] );
 
Last edited:

Theraze

Active member
Probably want to do something like:
Code:
int totalprice;
totalprice += historical_price($item[prismatic wad]) * max(0, 34 - available_amount($item[prismatic wad]));
totalprice += historical_price($item[mojo filter]) * max(0, 3 - available_amount($item[mojo filter]));
totalprice += historical_price($item[munchies pill]) * max(0, 5 - available_amount($item[munchies pill]));
totalprice += historical_price($item[ol' scratch's salad fork]) * max(0, 5 - available_amount($item[ol' scratch's salad fork]));
totalprice += historical_price($item[frosty's frosty mug]) * max(0, 6 - available_amount($item[frosty's frosty mug]));
totalprice += historical_price($item[spice melange]) * max(0, 1 - available_amount($item[spice melange]));
totalprice += historical_price($item[pumpkin pie]) * max(0, 1 - available_amount($item[pumpkin pie]));
totalprice += historical_price($item[hodgman's blanket]) * max(0, 1 - available_amount($item[hodgman's blanket]));
totalprice += historical_price($item[pumpkin beer]) * max(0, 1 - available_amount($item[pumpkin beer]));
totalprice += historical_price($item[jar of fermented pickle juice]) * max(0, 3 - available_amount($item[jar of fermented pickle juice]));
totalprice += historical_price($item[extra-greasy slider]) * max(0, 3 - available_amount($item[extra-greasy slider]));
Note that it's spice melange, not spice melenge... unless you want some major fails.

Also, we collect/price all 34 prismatic wads at once. That's because if you run 2 retrieve_item(17, $item[prismatic wad]) in a row, you only end up with 17 wads... it collects that many total, not that many additional. You want 34, so we need to do that as one.

We use max(0, <number needed> - available_amount($item)) because we never want to end up with a 'discount' because of having more than the number already... either 0 or the amount needed will be higher. No negative numbers. We use available_amount, not item_amount or anything else, because that's how many items retrieve_item will consider, so you get an accurate summary of how much you actually will be spending.

Oh, and we're using historical_price rather than mall_price because we want it to run fast. If you care about the absolute latest info... change those to mall_price, but they'll need to hit the server once every new-instance of mafia, rather than using shared prices.

Oh, and code blocks go in {code}{/code} or {php}{/php} blocks. Change {} to []. :) Code gives fixed width, b/w text. Php gives colourized (sometimes well, sometimes horribly) fixed width text.
 
Last edited:

Bale

Minion
Well that looks like a good way to lose your mind. Especially since you need to enter each item twice whenever you change them or their quantity. Not to mention the rest of the copy/paste that is required to modify the script. I'd rather keep a single list of items in an easier to edit manner

How about?

Code:
int [item] list;
// int is the number of each item to acquire
list [ $item[prismatic wad] ] = 17;
list [ $item[mojo filter] ] = 3;
list [ $item[munchies pill] ] = 5;
list [ $item[ol' scratch's salad fork] ] = 5;
list [ $item[prismatic wad] ] = 17;
list [ $item[frosty's frosty mug] ] = 6;
list [ $item[spice melange] ] = 1;
list [ $item[pumpkin pie] ] = 1;
list [ $item[hodgman's blanket] ] = 1;
list [ $item[pumpkin beer] ] = 1;
list [ $item[jar of fermented pickle juice] ] = 3;
list [ $item[extra-greasy slider] ] = 3;

totalprice;
foreach it in list
	totalprice += (historical_price(it) * max(list[it] - available_amount(it), 0));

if(!user_confirm("Is it okay to spend "+totalprice+" meat?"))
	abort("Too expensive!");
	
foreach it in list
	retrieve_item(list[it], it);
 

Theraze

Active member
Wasn't totalprice supposed to be defined? Looks like it's supposed to be prefaced by an int or float or something...

And yeah, I was doing it the "my browser is lagging and this works" way. Efficiency is a feature of having a good internet connection. :)
 

scrambles

New member
another question i had was, where should i put this in my scrip?
totalprice;

foreach it in list
totalprice += (historical_price(it) * max(list[it] - available_amount(it), 0));

for this i am wondering exactly what it is saying in computer talk so i can understand it? (for the statment above)

if(!user_confirm("Is it okay to spend "+totalprice+" meat?"))
abort("Too expensive!");

foreach it in list
retrieve_item(list[it], it); for this the "it" i assume stands for item correct?

sorry about all the question scripting interestes me greatly and i want to learn how to do it
thanks again
 

roippi

Developer
I really don't mean any offense by this, but that is like walking into a literature class and asking how to read.

Spend some time on the wiki, reading some helpful articles. If there's a control structure you don't understand (i.e. foreach) or a operator (i.e. +=) you can look that up there too. But you need to have some very basic level of knowledge - or at least be willing to do the work to get there - before we can help you.
 

Grotfang

Developer
This reminds me of the wonderful article by Eric S. Raymond How To Ask Questions The Smart Way. Sadly it seems to be read by people who already understand its proposals more than it is by its intended audience.

I particularly like:

Before You Ask

Before asking a technical question by e-mail, or in a newsgroup, or on a website chat board, do the following:

  1. Try to find an answer by searching the archives of the forum you plan to post to.
  2. Try to find an answer by searching the Web.
  3. Try to find an answer by reading the manual.
  4. Try to find an answer by reading a FAQ.
  5. Try to find an answer by inspection or experimentation.
  6. Try to find an answer by asking a skilled friend.
  7. If you're a programmer, try to find an answer by reading the source code.

When you ask your question, display the fact that you have done these things first; this will help establish that you're not being a lazy sponge and wasting people's time. Better yet, display what you have learned from doing these things. We like answering questions for people who have demonstrated they can learn from the answers.
 

scrambles

New member
I have done all of the above, and have gained a little more understanding of the subject of scripting, however I still have some questions.

int [item] list; // so this is the number , data type , and map name correct?
// int is the number of each item to acquire
list [ $item[prismatic wad] ] = 17;
list [ $item[mojo filter] ] = 3;
list [ $item[munchies pill] ] = 5;
list [ $item[ol' scratch's salad fork] ] = 5;
list [ $item[prismatic wad] ] = 17;
list [ $item[frosty's frosty mug] ] = 6;
list [ $item[spice melange] ] = 1;
list [ $item[pumpkin pie] ] = 1;
list [ $item[hodgman's blanket] ] = 1;
list [ $item[pumpkin beer] ] = 1;
list [ $item[jar of fermented pickle juice] ] = 3;
list [ $item[extra-greasy slider] ] = 3;

totalprice; //<< does this pretty much set "totalprice" as a variable like X += (historical_price(it) * max(list[it] - available_amount(it), 0));

foreach it in list
totalprice += (historical_price(it) * max(list[it] - available_amount(it), 0)); /*does the "it" reffer to the items previously mentions in the list above? Also i get an "Expected ;, found += (clanhop.ash, line 19)"
when i try to run the script



*/
if(!user_confirm("Is it okay to spend "+totalprice+" meat?"))
abort("Too expensive!");

foreach it in list
retrieve_item(list[it], it);

thanks for the help
 
Last edited:

Bale

Minion
totalprice; //<< does this pretty much set "totalprice" as a variable like X += (historical_price(it) * max(list[it] - available_amount(it), 0));

That was a typo. That should have been

Code:
int totalprice;

This declares the variable and sets it to the default value of 0 so that it can be used in the script. All variables need to be declared before you use them. Otherwise mafia wouldn't have know if totalprice was an int, item, location or anything else.


totalprice += (historical_price(it) * max(list[it] - available_amount(it), 0)); /*does the "it" reffer to the items previously mentions in the list above? Also i get an "Expected ;, found += (clanhop.ash, line 19)"

"it" refers to the variable in the foreach it in list. Specially, "foreach" iterates over every item in the map called list. Since the keys in that map are items, "it" is each of those items, one at a time.
 
Top