viewing paste topic/4374- lucky-pick-event | Athena

Posted on the | Last edited on
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
//  callfunc "shuffle", <min num>, <max num>, <output array> {, <count> };
function    script  shuffle {
    .@static = getarg(0);
    .@range = getarg(1) +1 - .@static;
    .@count = getarg(3, 0);
    if ( .@range <= 0 )
        return 0;
    if ( !.@count || .@count > .@range )
        .@count = .@range;
    while ( .@i < .@count ) {
        .@r = .@save = rand( .@i, .@range -1 ) ;
        if ( !.@tmp1[.@i] ) {
            .@r = .@tmp1[.@r] ? .@tmp2[.@r] : .@r;
            .@tmp2[.@i] = .@r;
            .@tmp2[.@save] = .@i;
            .@tmp1[.@save] = 1;
            set getelementofarray( getarg(2), .@i ), .@r + .@static;
            set getelementofarray( getarg(2), .@save ), .@i + .@static;
        }
        .@i++;
    }
    return .@count;
}
 
-   script  dkfdjhsfkjs -1,{
OnInit:
    bindatcmd "test", strnpcinfo(0)+"::Onooo", 99,100;
    bindatcmd "qwer", strnpcinfo(0)+"::Onaaa", 99,100;
    bindatcmd "asdf", strnpcinfo(0)+"::Onbbb", 99,100;
    end;
Onooo:
    getservermember 0;
    for ( .@i = 0; .@i < $@servermembercount; .@i++ )
        dispbottom $@servermembername$[.@i];
    end;
Onaaa:
//  while ( .@i++ < 100 ) { // ran a test with 100 times
    getservermember 2;
    .@winneraid = $@servermemberaid[ rand( $@servermembercount ) ];
    announce "Winner is "+ rid2name( .@winneraid ), bc_all;
    getitem 501, 1, .@winneraid;
//  }
    end;
Onbbb:
//  while ( .@j++ < 100 ) { // ran a test with 100 times
    getservermember 2;
    callfunc "shuffle", 0, $@servermembercount -1, .@r;
    for ( .@i = 0; .@i < $@servermembercount; .@i++ ) {
        attachrid $@servermemberaid[ .@r[.@i] ];
        if ( getgmlevel() < 60 && checkvending() != 2 ) {
            announce "Winner is "+ strcharinfo(0), bc_all;
            getitem 501, 1;
            break;
        }
    }
//  }
    end;    
}
Viewed 1478 times, submitted by AnnieRuru.