dumb question - how do I do file_to_map("inebriety.txt", booze) so it always works au

dumb question - how do I do file_to_map("inebriety.txt", booze) so it always works au

tomatically without moving inebriety to /data? does it still get updated when I do that (but I don't want to anyway)? can I check if any item is booze and get inebriety another way? thanks

please fix your forum settings
 
Last edited:

jasonharper

Developer
file_to_map() can read the built-in data files without having an actual file in /data. In fact, you don't WANT an actual file in /data, since file_to_map() would continue reading it, even if it's outdated and mafia itself refuses to use it for its own purposes.

You can tell if an item is booze by item_type() returning "booze", but the only way to determine the inebriety amount is to read the file.
 

slyz

Developer
Here's a little bit of code (stolen from dj-d's EatDrink.ash) that will load it.
All you need is a map that can hold all the data types in inebriety.txt. A string[item,int,int,string,string,string] map would be awkward, thus the booze_data record.

I also added a (simplified) part to get the actual average number of advs as an example.
PHP:
record booze_data {
	int consumptionGain;
	int level;	 
	string range;
	string mus;
	string mys;
	string mox;
	
};

booze_data[item] drinks;
if ( !file_to_map("inebriety.txt", drinks) )
	abort("Failed to load inebriety.txt");

float get_average( string range ) {	
	float average;
	string[int] split_range = split_string(range, "-");
	if (count(split_range) == 1)
		return split_range[0].to_float() ;
	return ( ( split_range[0].to_int() + split_range[1].to_int() ) / 2 ) ;
}

float get_num_adv( string range ) {
	float num_adv = get_average(range);
	if ( have_effect($effect[Got Milk]) == 0 || have_effect($effect[Ode to Booze]) == 0 )
		return num_adv ;
	if (num_adv <= 4)
		return num_adv + 1;
	if (num_adv <= 7)
		return num_adv + 2;
	if (num_adv <= 10)
		return num_adv + 3;
	return num_adv + 4;
}

print(get_num_adv(drinks[$item[fuzzbump]].range));
 
awesome, thanks
I don't know what I will do with adventures, probably nothing
I'm dumb, I just forget that everything's not an array

I'll put it here it doesn't do much. Is there an html parser for showconsumption.php already written? Could anyone help me with that? I don't want to
and something with recursion, or sorting, or something
 

Attachments

  • consumption.ash
    1.9 KB · Views: 32
  • initial_booze.txt
    3 KB · Views: 49
Last edited:
Top