MMG Martingale script

tamahome

New member
Ok, we can start here then.
I want to return a meat result directly from the bet page. It is much faster than going to the betarchive. I don't know about you, but it takes forever for me to load the archive. I also don't have meat coming in from anywhere else to change the values of this result, so we are safe that way.

Code:
int total() {
   if usehagnksmeat = false {
   string s = visit_url("bet.php");
   s = substring(s,index_of(s,"You have"),index_of(s,"Meat on hand"));
   int result = to_int(s);
   }
   else {
   string s = visit_url("bet.php");
   s = substring(s,index_of(s,"hand and"),index_of(s,"Meat in Hagnk's"));
   int result = to_int(s);
   }
   print("Meat available: "+result);
   return result;
}

If I have done this right, result should return a value of either hagnks or on hand. That is assuming I have understood the functions correctly.
 

zarqon

Well-known member
Looks like it should work, although you need parentheses around conditions for if statements. Best way is to make a test script to try it out:

testavailablemeat.ash
Code:
boolean usehagnksmeat;

int total() {
   if (!usehagnksmeat) {
   string s = visit_url("bet.php");
   s = substring(s,index_of(s,"You have"),index_of(s,"Meat on hand"));
   int result = to_int(s);
   } else {
   string s = visit_url("bet.php");
   s = substring(s,index_of(s,"hand and"),index_of(s,"Meat in Hagnk's"));
   int result = to_int(s);
   }
   print("Meat available: "+result);
   return result;
}

void main(boolean usehagnks) {
   usehangksmeat = usehagnks;
   print("Checking available meat...");
   total();
}

The only problem with checking bet.php is that you might get a kmail that changes your available meat, or you might sell something in your store. If you don't have a store that's fine but kmails are a different issue.
 

tamahome

New member
My character I want this script for is not avery social character so it isn't going to be a huge problem with incoming meat possibilities. I also wanted to do it this way for the speed of the check. It is quite a bit faster than checking the archive.

Now for a quick question. Why does it need to be - if (!usehagnksmeat) Why the (!) , and why does it not need a qualifying equals to a value?

Also when I try to run the above test script, it has an error. Script parsing error (testavailablemeat.ash, line 1).
 

zarqon

Well-known member
If statements (and while and repeat loops) require conditions, like so:

if ( condition ) { commands }

Conditions must evaluate to a boolean, i.e. true or false. When you use a boolean value as a condition, it evaluates to true or false without needing an operator like "==" or "<".

So instead of (usehagnksmeat == true) you can just use:

if (usehagnksmeat) print("Using Hagnk's.");

Also, ! means "not". So instead of (usehagnksmeat == false) you can use:

if (!usehagnksmeat) print("Not using Hagnk's.");

This is useful for functions that return a boolean value, for example:

if (!retrieve_item(1,$item[turtle totem]))
print("You were unable to get the item.");


As far as the test script, I made a few changes to it, and now it works:

Code:
boolean usehagnksmeat;

int total() {
   string s = visit_url("bet.php");
   if (!usehagnksmeat)
      s = substring(s,index_of(s,"Add a Bet:"),index_of(s,"Meat on hand"));
   else s = substring(s,index_of(s,"hand and"),index_of(s,"Meat in Hagnk's"));
   int result = to_int(s);
   print("Meat available: "+result);
   return result;
}

void main(boolean usehagnks) {
   usehagnksmeat = usehagnks;
   print("Checking available meat...");
   total();
}

Feel free to ask about any of the changes.
 

tamahome

New member
I don't know if I am doing something wrong or not. I tried to run this new script and I still get a parsing error. As for the changes, all that was really changed was to clean things up a little. I get that part. Also thanks for explaining the (!), that helps alot.
 

Bale

Minion
wordpad is not ideal. notepad is much better for this. wordpad can get you in trouble by saving formatting characters if you're not careful.

If that still doesn't work, attach your script to your next reply so we can download it and check it ourselves.
 

tamahome

New member
Ok, saved it using notepad and it did work.

I now have a working betting script. Just one problem. It only runs through the bets once, and if it wins it stops. How can I get it to run through and then start again at the beginning?
 
Last edited:

zarqon

Well-known member
Change the name of your main() function, say to betchain(). Then make a new main() that calls betchain() X times.

Code:
betchain() { previous main() function }

main(int numchains) {
   for i from 1 to numchains
      betchain();
}
 

tamahome

New member
Everything seems to be working okay, except it will stop and error out sometimes after a bet. It does print out a debug log. I can attach that if so desired. Any reasons why it would error out?
 

dj_d

Member
The debug log and the exact text of the error would be useful.

And when you do get it running, please share your win/loss record!
 

tamahome

New member
It just says Unexpected error, debug log printed.
 

Attachments

  • test.ash
    2.4 KB · Views: 20
  • DEBUG_20090318.txt
    4.7 KB · Views: 33
Last edited:

zarqon

Well-known member
Somehow it is not finding one of the test strings for index_of(). Do those strings always exist in bet.php?
 

tamahome

New member
They should be there unless there are five bets running at one time.

Maybe the code should be changed to something like this.

Code:
int total() {
   if (!usehagnksmeat) 
      s = my_meat()  
   else {
      string s = visit_url("storage.php");
      s = substring(s,index_of(s,"You have"),index_of(s,"meat in long-term"));
   }
   int result = to_int(s);
   print("Meat available: "+result);
   return result;
}
 
Last edited:

zarqon

Well-known member
Good idea, but I don't think mafia would know that your meat has changed. (And it won't run because there is an error assigning something to s, which has not been declared.)

However, if you are OK with never using Hagnk's, this function would be waaay easy to write:

Code:
int total() {
   refresh_status();
   return my_meat();
}

Also, using "You have" for the beginning won't work, because that would include a lot of numbers, not just the number you want. Look at the HTML, not the displayed page. You'll see "You have" can occur above the desired place with "You have no oustanding bets" or whatever the message is. This means there are several HTML tags in there too, some which say something like "width=75%". Those extra integers will mess up your to_int() conversion.
 

tamahome

New member
I did think of that. That is why I decided to change it to look at Hagnk's storage for the meat value instead of the bet page. I figured that might be the best way. The string does only show up once at hagnks.

So how about this one.
Code:
int total() 
   if (!usehagnksmeat) {
      refresh_status();
      return my_meat();
   }
   else {
      string s = visit_url("storage.php");
      s = substring(s,index_of(s,"You have"),index_of(s,"meat in long-term"));
      int result = to_int(s);
      return result;
   }

Except I don't know why it is saying that it can't do the return result.
 
Last edited:

tamahome

New member
I solved that last problem. Here is the solution.

Code:
int total() {
   string s = visit_url("bet.php");
   string t=visit_url("storage.php");
   if (!usehagnksmeat) 
      s = substring(s,index_of(s,"Add a Bet:"),index_of(s,"Meat on hand"));
   else 
      s = substring(t,index_of(t,"You have"),index_of(t,"meat in long-term storage."));
   int result = to_int(s);
   print("Meat available: "+result);
   return result;
}


After further testing, I have found that it will go through and make all the bets it can without waiting for a win or loss confirmation. As far as I can tell, the place_bet function is supposed to wait until a result is confirmed for the win or loss. For some reason the script is placing the next bet even if the result has not been returned as a win or a loss. It should run through a loop in the place_bet and not exit the function until it returns a result. Is there some way to stop it from moving on to the next bet without a result returned? Is it possible that it is confused by the total() function that I now have defined?

This is the current code that I am testing.
 

Attachments

  • test.ash
    2.4 KB · Views: 23
Last edited:

tamahome

New member
I have finished my betting script. It is below.
Many thanks to Zarqon for his help in understanding the code.

It is simple. True or false to use inventory or Hagnk's.
The bets can be changed to fit your style of betting. Simply change the code in these lines.

Code:
if (bet_five_times(1000) >= winsneeded) return;

Change the 1000 to whatever you want to bet and so on.
It will make the bet five times and if it meets the required number of wins (default is set at three) it will start over.

It will prompt you on how many times you want the bet series to run. You can make it go as long or as short as you like.

Enjoy!
 

Attachments

  • MMGBet.ash
    3.1 KB · Views: 61
Last edited:

Maj

New member
The script has been working great for me for a couple of weeks (thanks, btw) but a couple of days ago it started giving me an error message "There was a problem placing the bet". I've been searching for an answer and haven't found one. I redownloaded the script, didn't fix it. Any ideas?

Thanks in advance.
 
Top