how to get a raffle ticket

lippo

New member
I want to build a script that buys exactly one raffle ticket, but all commands I have tested and found in this forum doesn't work.
 

tebee

Member
use

cli_execute ( " raffle 1 inventory");

buys 1 using cash from inventory

or

cli_execute ( " raffle 1 storage");

buys 1 using cash from Hagnks
 

Veracity

Developer
Staff member
Of course, if all you want is a CLI script, you don't need cli_execute. Call it raffle1.txt, say, and just put in:

raffle 1 storage
 

Atreyuu

New member
Of course, if all you want is a CLI script, you don't need cli_execute. Call it raffle1.txt, say, and just put in:

raffle 1 storage

I've been using it "On Logout" and it works very well, but is there a way to ensure it only runs once a day? I log in and play my turns at night, then I log in from time to time during the day to chat in clan, play the mall, or just organize my inventory. It's not a big deal, but I really only WANT to buy 10 tickets a day, there are some days I end up with 100. Like I said it's not a big deal to me, if it was I'd just disable the scipt or log in without mafia. Just curious. Thanks.
 

StDoodle

Minion
From an ash script, you could just set a once-per-day preference. The following should work per-user (assuming the function daily_raffle() is called from main() in your logout script). Note that it returns a boolean value (true if you've raffled as of the script's finish, false if for some reason you didn't, such as lack of meat).
Code:
boolean daily_raffle() {
    boolean result

    switch ( ! to_boolean(get_property("_raflled_" + my_name() ) )
    {
        case (true):
            result = true;
            break;
        default:
            result = cli_execute("raffle 1 inventory") ;
            set_property("_raffled_" + my_name() , result);
    }

        return result;
}

Edit: suppose it might be nice to show a possible use, for someone who wants to do nothing else on logout (save this script w/ whatever name you want, and put it in the scripts directory, then make sure to set your preferences to use it on logout).
Code:
// code from above

main() {
        if( daily_raffle() )
        {
                print("You've bought your ticket for the day." , "blue");
        } else {
                print("You were unable to buy your ticket today." , "red");
        }
}

However, I don't think any of the "print" stuff shows up once you logoff anymore, so I dunno why I bothered with all that...
 
Last edited:

slyz

Developer
It might be simpler to check if there already is a raffle ticket in your inventory:
PHP:
# amount of tickets you want, edit to change:
int num_tickets = 10;

boolean daily_raffle( int num ) {
     if ( item_amount($item[raffle ticket]) < num )
          return cli_execute("raffle "+(num-item_amount($item[raffle ticket]))+" inventory");
     return true;
}

void main () {
     if( daily_raffle(num_tickets) )
          print("You've bought your ticket(s) for the day." , "blue");
     else
          print("You were unable to buy your ticket(s) today." , "red");
}

EDIT: I finally remembered to look up what tags do colored snippets!
 
Last edited:

Bale

Minion
Actually, Spiny, you're making it more complicated than it has to be. There's no need to set a preference.

PHP:
if(available_amount($item[raffle ticket]) < 1) {
   if(can_interact() {
      cli_execute("raffle 1 inventory");
   } else cli_execute("raffle 1 storage");
}

Edit: It seems that I've been ninja'ed by slyz, but mine has a check to see if you're in ronin/hardcore.
 
Last edited:

zarqon

Well-known member
Here's the littlest one!

Code:
if (item_amount($item[raffle ticket]) < 1) 
   visit_url("raffle.php?action=buy&pwd&where="+to_int(!can_interact())+"&quantity=1");
 

Veracity

Developer
Staff member
Really? How about this:
Code:
if (item_amount($item[raffle ticket]) < 1) 
    cli_execute( "raffle 1" );
That will go to inventory if you can interact - are out of Ronin - or to storage otherwise.

I've never understood why people are so enamored of using "visit_url" to do things that are built-in to KoLmafia...
 
Last edited:

heeheehee

Developer
Staff member
Yeah, Veracity's solution wins. We apparently like using visit_url() because we're the type who never really used the CLI for much. I know I pretty much jumped right into ASH scripting with a minimal knowledge of CLI commands. Y'know, buy, use, eat, drink, create, cast... and I think that was all I really used. Maybe mallsell and autosell as well. But yeah. Just the basics. (Speaking for myself, here, of course.)
 

zarqon

Well-known member
Actually, I use visit_url() for things that are not built in to mafia -- or to get more detailed control (i.e. my kmail functions). For me, that means after first consulting ashref. CLI commands don't have meaningful return values so I don't generally consider them / know they exist.

That said, I think I will change that in my login script now that I know about the CLI command's built-in handling.
 
Top