Maxing non combat and how to use maps

Grabuge

Member
Hi everyone. I'm new to scripting and even after reading the wiki I can't figure out maps.

I'm trying to make a script that will get me to a specific combat rate modifier at a specific price per adventure. I would like to know if there is a way to use a maps so I don't have to copy paste each item and duration. I plan to add CombatRate > 0 once I figure out how mapping works. I was planing of making one list of all the plus combat and shrugging those off and a second map that would have the minus combat effect name, item name, duration, rate of combat modifier. Also is the a way to sort, so the cheapest is use first? Right now I was thinking of using if(mall price(item1)> mall price(item2) but that gets long after a couple of item.

Thank you in advance.


Code:
void Main(int PricePerAdv, int CombatRate){
	print("Checking item's prices and buying those who are worth it.", "green");
	
	if (CombatRate < 0){
		print("Gonna shrug combat modifier if we have to.", "green");
		if ((have_effect($effect[Musk of The Moose]) > 1)){
			cli_execute("uneffect Musk of The Moose");
		}

		if ((have_effect($effect[Carlweather's Cantata of Confrontation]) > 1)){
			cli_execute("uneffect Carlweather's Cantata of Confrontation");
		}

		if(combat_rate_modifier() > CombatRate){
			## Check for Simply Invisible
			if ((have_effect($effect[Simply Invisible]) < 1) && mall_price($item[Invisibility potion]) < ( PricePerAdv * 20 * 1)){
				use(1, $item[Invisibility potion]);
			}
			## Check for Predjudicetidigitation
			if ((have_effect($effect[Predjudicetidigitation]) < 1) && mall_price($item[worst candy]) < ( PricePerAdv * 10 * 2)){
				use(1, $item[worst candy]);
			}
		}

		print( "You are now at "+combat_rate_modifier()+"%. It's the best we can do for that price." ,"blue");
	}
}
 

Bale

Minion
I'm afraid that without knowing what your problem is at understanding maps it is hard to explain them. I'd need to write a whole essay on the subject or point at one of the primers you have already read. So instead I'll just provide a simple and vaguely relevant example that I have lying around.

Code:
// What is the most expensive Gene Tonic?
item [int] tonics;
for i from 7384 to 7405
	tonics[count(tonics)] = to_item(i);
sort tonics by mall_price(value);

// Print out a table of that information
buffer output;
output.append('<table border="1"><tr><th>Price</th><th>Gene Tonic</th></tr>');
foreach x in tonics {
	output.append("<tr><td>");
	output.append(mall_price(tonics[x]));
	output.append("</td><td>");
	output.append(tonics[x]);
	output.append("</td></tr>");
}
output.append("</table>");
print_html(output);

Note that the key for tonics is count(tonics) so that I can be sure it is the integers starting at 0 and increasing by 1 for each tonic. This makes it ideal for sorting behavior. I then use the sort command to order it by mall_price() of the value. This exchanges the keys and values so that the cheapest is tonics[0] and the most expensive is tonics[count(tonics) - 1].

The foreach command will iterate over every key in an existing map starting at the one whose index has the lowest alphanumeric value.
 
Last edited:

lostcalpolydude

Developer
Staff member
With the right skills and equipment you can reach the "maximum" (there's a soft cap at 25 in either direction) +combat or -combat for 0 MPA (equipping a -combat item over something else might have a cost to it, but not one that can be trivially calculated in a script), so it really depends on what you are doing.
 

Grabuge

Member
I do know that it is easy to get to the max with equipment but there is several reason why you would want to get to +25 or -25 without having to change your equipment. Farming comes into mind where replacing a piece of equipment would be detrimental the goal. Place where outfits are needed, you need your powerful IOTM to survives, etc.

In the case of farming, I want to get as close to +25 as possible without spending more meat then what the non combat makes me lose.

What I wanted to do is make a file with this information:
EFFECT, ITEM, TURNS, 5% Multiplier

ex:
Simply Invisible,Invisibility potion,20, 1
Predjudicetidigitation,worst candy,10,2
etc.

So the script would become:
for each effect in maps
if ((have_effect($effect[EFFECT]) < 1) && mall_price($item[ITEM]) < ( PricePerAdv * TURNS * MULTIPLIER)){
use(1, $item[ITEM]);
}

Is that possible?
 

Bale

Minion
Then what you are missing is a record.

Code:
record com_info {
   item it;
   int turns;
   int multipler;
};
com_info [effect] ef_map;
file_to_map("comef_map.txt", ef_map);

The more you tell us, the better we can help you.
 

Grabuge

Member
Ok now that I have the map, How do I link to each cell? How do I change the scipt to do this?

for each effect in maps
if ((have_effect($effect[EFFECT]) < 1) && mall_price($item[ITEM]) < ( PricePerAdv * TURNS * MULTIPLIER)){
use(1, $item[ITEM]);
}
 

Bale

Minion
I don't know where PricePerAdv is calculated, so I cannot substitute in anything for that term, but the rest looks like this:

Code:
foreach ef,info in ef_map
   if ((have_effect(ef) < 1) && mall_price(info.it) < ( PricePerAdv * info.turns * info.multiplier))
      use(1, info.it);

Note that info as defined in the foreach is the same as ef_map[ef].
 

Bale

Minion
I'm glad. Sometimes a good example or two can help more than a full explanation.

Good luck with your script! Don't hesitate to ask if you have another question.
 

Grabuge

Member
Ok most of the script is now working. Thank you for your help.

I'm having trouble with sorting. When I sort with my previous map, I ended up with the all the data moving around to the wrong effect. So I changed my file to be:
1->Invisibility potion->Simply Invisible->less->20->1
2->Chunk of rock salt->Fresh scent->less->10->1
etc

so now when I check my values with this test code:
Code:
record CombRateMod {
	item it;
	effect ef;
	string MoreOrLess;
	int turns;
	int mult;

};
CombRateMod [int] CombEf_map;
file_to_map("CombMod_map.txt", CombEf_map);


sort CombEf_map by mall_price(value.it);

	foreach it,info in CombEf_map
		print( "The effect is "+(info.ef)+" and it gives you "+info.MoreOrLess+" combat. You need to use "+(info.it)+" and it come at a price of "+mall_price(info.it)+"." ,"green");
It gives me this :
You can use chunk of rock salt to get the effect Fresh Scent, it will give you 10 turns of less combat for a price of 469 meat.
You can use invisibility potion to get the effect Simply Invisible, it will give you 20 turns of less combat for a price of 6210 meat.

when the effect is the first entry in the file it would give me something like this:
You can use chunk of rock salt to get the effect Celestial Camouflage, it will give you 10 turns of less combat for a price of 469 meat.

So everything was sorted but not the name of the effect.

Is there a way do sort without adding that extra entry in the file? Also is it possible to further do modification to the sort? When I try "sort CombEf_map by mall_price(value.it)/info.turns" it tells me that info is an unknown variable.
Do I have to generate a new map with mall_price/turns? I would I even do that?

Thank you
 

Bale

Minion
sort CombEf_map by (mall_price(value.it) / value.turns)

It doesn't know the term info since it was only defined within the foreach. The only special terms you can use in a sort command are index and value.
 
Top