kinda fun making this script
been awhile I scripted something like mission board
function script rand__ {
.@range = getarg(0);
.@count = getarg(2, 0);
.@count = ( .@count == 0 || .@count > .@range )? .@range : ( .@count > 128 )? 128 : .@count;
while ( .@i < .@count ) {
.@r = .@save = rand( .@i, .@range -1 ) ;
if ( getd(".@tmp1_"+ .@i ) == 0 ) {
.@r = ( getd(".@tmp1_"+ .@r ) )? getd( ".@tmp2_"+ .@r ) : .@r;
setd ".@tmp2_"+ .@i, .@r;
setd ".@tmp2_"+ .@save , .@i;
setd ".@tmp1_"+ .@save , 1;
set getelementofarray( getarg(1), .@i ), .@r;
if ( .@save < .@count )
set getelementofarray( getarg(1), .@save ), .@i;
}
.@i++;
}
return .@count;
}
prontera,156,188,5 script khdfsdkjhf 100,{
// hatgame$ = "";
if ( hatgame$ != "" ) {
explode @tmp$, hatgame$, "#";
callsub L_preview;
next;
for ( .@i = 1; .@i <= 3; .@i++ ) {
if ( countitem( .itemreq[ atoi( @tmp$[ .@i ] ) *2 ] ) < .itemreq[ atoi( @tmp$[ .@i ] ) *2 +1 ] ) {
mes "you don't have enough "+ getitemname( .itemreq[ atoi( @tmp$[ .@i ] ) *2 ] );
close;
}
}
for ( .@i = 1; .@i <= 3; .@i++ )
delitem .itemreq[ atoi( @tmp$[ .@i ] ) *2 ], .itemreq[ atoi( @tmp$[ .@i ] ) *2 +1 ];
getitem atoi( @tmp$[0] ), 1;
mes "congrats for "+ getitemname( atoi( @tmp$[0] ) );
hatgame$ = "";
close;
}
mes "to play a hat game you need "+ .itemstart[0] +" "+ getitemname(.itemstart[1])+".";
next;
if ( select ( "Yes", "No" ) == 2 ) close;
if ( countitem(.itemstart[1]) < .itemstart[0] ) {
mes "you don't have enough required items";
close;
}
delitem .itemstart[1], .itemstart[0];
@tmp$[0] = .rewarditem[ rand( .rewarditemsize ) ] +"";
set .@dummy, callfunc( "rand__", .itemreqsize, $@rand, 3 );
for ( .@i = 0; .@i < 3; .@i++ )
@tmp$[ .@i +1 ] = $@rand[ .@i ] +"";
hatgame$ = implode( @tmp$, "#" );
callsub L_preview;
close;
L_preview:
mes "headgear : "+ getitemname( atoi( @tmp$[0] ) );
mes "you have to bring";
for ( .@i = 1; .@i <= 3; .@i++ )
mes .itemreq[ atoi( @tmp$[ .@i ] ) *2 +1 ] +"x "+ getitemname( .itemreq[ atoi( @tmp$[ .@i ] ) *2 ] );
return;
OnInit:
setarray .itemstart,
10, 909; // 10 jellopy
setarray .itemreq,
501, 10, // 10 red pot
502, 9, // 9 orange pot
503, 8, // 8 yellow pot
504, 7, // 7 white pot
505, 6, // 6 blue pot
512, 1, // 1 apple
513, 2, // 2 banana
514, 3, // 3 grape
515, 4; // 4 carrot
setarray .rewarditem,
5001, 5002, 5003, 5004;
.itemreqsize = getarraysize(.itemreq) / 2;
.rewarditemsize = getarraysize(.rewarditem);
end;
}
credit to keyworld for the shuffling algorithm