Is it possible to search for a specific word, or set of words inside a map?
string[int] mapname;
foreach i in mapname {
if (mapname[i] == "Mr. Accessory" ) {
mapname[i] [COLOR=#ff0000][B]+=[/B][/COLOR] " the text to add";
}
}
string [int] my_list;
file_to_map( "pazsox.txt" , my_list);
for i from 0 to (count(my_list) - 1)
{
if (contains_text(my_list[i], sender))
{ print ("true"); return; }
if(!contains_text(my_list[i], sender))
{ print("false"); record note
{
string message;
}
[int] test;
int NE= count(test);
test[NE].message= sender;
Map_to_File(test, "pazsox.txt");
}
}
I'm trying to make a list of people who have spoken in clan.
Ok. Here's the code I'm working on.
Regardless of if a users name is in the file or not, it adds the name again. I obviously only want a persons name on the list once, and never again.Code:string [int] my_list; file_to_map( "pazsox.txt" , my_list); for i from 0 to (count(my_list) - 1) { if (contains_text(my_list[i], sender)) { print ("true"); return; } [B]If the 'sender' you are testing for happens to be the first name in the map, then this will print true and return. [/B] [B]If any other name is first in the map, then this will print false and add the name WHETHER it appears later in the map or not.[/B] if(!contains_text(my_list[i], sender)) { print("false"); [B]'test' can just be a string[int] map. There is no need to make a record[int] map here (that I can see).[/B] [COLOR=#ff0000]record note { string message; } [int] test; [/COLOR][B]--> string[int] test; [/B] int NE= count(test); test[NE][COLOR=#ff0000].message[/COLOR]= sender; --> just [B]test[NE] = sender;[/B] Map_to_File(test, "pazsox.txt"); } }
I have a feeling the answer is in AlbinoRhino's response above, I just need to figure it out.
string [int] my_list;
file_to_map( "pazsox.txt" , my_list);
[B]string storage_string = "";[/B]
foreach i in my_list {
storage_string += my_list[i] + " ";
}
[B]All the names in the list are now in a single string....[/B]
if ( !contains_text(storage_string, sender) ) {
my_list[count(my_list)] = sender;
map_to_file(my_list, "pazsox.txt");
}
To do what you are trying to do...(I think)...maybe something like this:
I don't understand what you are trying to do.
Do you have a predefined list of items you want to track so that you look for each item in the list and do something if the log shows it was taken or returned?
Do you look at the log and only track things that were taken and returned?
Are you assuming that there will be zero or one of an item of interest in the stash or could there be more than one?
The map I would suggest (and walk you through if necessary) depends upon what you are trying to do.
void main()
{
string ClanLog= visit_url( "clan_log.php" );
int start=index_of( ClanLog , "Stash") +55;
ClanLog=substring(ClanLog, start);
matcher m_stash_put = create_matcher( ">(\\d{2})/(\\d{2})/(\\d{2}), (\\d{2}):(\\d{2})(AM:|PM:) <(.+?)>(.+?) \\(#(\\d+)\\)</a> (added|took|contributed) (\\d+) (.+?)\\.<" , ClanLog );
int I=0;
while( I<6 )//test # iterations
{
m_stash_put.find();
I=I+1;
string group1= m_stash_put.group( 1 );
string group2= m_stash_put.group( 2 );
string group3= m_stash_put.group( 3 );
string group4= m_stash_put.group( 4 );
string group5= m_stash_put.group( 5 );
string group6= m_stash_put.group( 6 );
string group7= m_stash_put.group( 7 );
string group8= m_stash_put.group( 8 );
string group9= m_stash_put.group( 9 );
string group10= m_stash_put.group( 10 );
string group11= m_stash_put.group( 11 );
string group12= m_stash_put.group( 12 );
string [int] mymap;
if ((group10) == "took")
{
print(group8 + " " + group10 + " " + group11 + " " + group12);
mymap[count(mymap)] = (group8) + (group10) + (group12);
}
map_to_file(mymap,"myfile.txt");
}
}
void main()
{
string [int] mymap;
map_to_file(mymap,"myfile.txt");
string ClanLog= visit_url( "clan_log.php" );
int start=index_of( ClanLog , "Stash") +55;
ClanLog=substring(ClanLog, start);
matcher m_stash_put = create_matcher( ">(\\d{2})/(\\d{2})/(\\d{2}), (\\d{2}):(\\d{2})(AM:|PM:) <(.+?)>(.+?) \\(#(\\d+)\\)</a> (added|took|contributed) (\\d+) (.+?)\\.<" , ClanLog );
int I=0;
while( I<50 )//test # iterations
{
m_stash_put.find();
I=I+1;
string group8= m_stash_put.group( 8 ); // user name
string group9= m_stash_put.group( 9 ); // user's number
string group10= m_stash_put.group( 10 ); // took/added/contributed
string group11= m_stash_put.group( 11 ); // how many
string group12= m_stash_put.group( 12 ); // what was taken
string [int] mymap;
string filename = "myfile.txt";
file_to_map(filename, mymap);
if ((group10) == "added")
{
// print(group8 + " " + group10 + " " + group11 + " " + group12);
mymap[count(mymap)] = (group8) + (group10) + (group12);
}
map_to_file(mymap,filename);
file_to_map(filename, mymap);
string storage_string = "";
foreach i in mymap {
storage_string += mymap[i] + " ";
}
if (!contains_text(storage_string, group8+"added"+group12))
print(group8 + " " + group10 + " " + group11 + " "+ group12);
}
}
int [int, item] stash_deltas;
file_to_map("stash.txt", stash_deltas);
matcher m = create_matcher("...", visit_url("clan_log.php"));
while (m.find()) {
int time = parseTimestamp(m.group(1));
if (time < get_property("lastClanStashRefresh")) {
continue;
}
if (m.group(3) == "contributed") {
// Player donated Meat.
continue;
}
int pid = m.group(2).to_int();
int sign = m.group(3) == "took" ? -1 : 1;
int qty = m.group(4).to_int();
item it = m.group(5).to_item();
stash_deltas[pid, it] += sign * qty;
}
map_to_file(stash_deltas, "stash.txt");
foreach pid, it, delta in stash_deltas {
if (historical_price(it) > THRESHOLD && delta > 0) {
// player ${pid} owes ${delta} of ${it}; use get_player_name(pid) to yield something human-readable
}
}