you have to continue the cases for each bag
function script coinbag {
swtich(getarg(0,0)) //default to 0 to prevent errors
{
case 0:
//For B Grade e.g.
setarray .@coins[0],<id>,<amt>,<id>,<amt>,...;
break;
case 1: //C Grade
setarray .@coins[0],<id>,<amt>,<id>,<amt>,...;
break;
//etc...
case 2: //D Grade
setarray .@coins[0],<id>,<amt>,<id>,<amt>,...;
break;
//etc...
}
.@rnd = rand(getarraysize(.@coins)) / 2;
getitem .@coins[(.@rnd*2)],.@coins[((.@rnd*2)+1)]
}
what i am doing here:
depending with which parameter you call the function, the array is filled with other values, e.g. callfunc "coinbag",1 calls the case for the C Grade Bag, callfunc "coinbag",2 the case for the D Grade Bag. you just have to fill the array with the right ids and values.
after filling the array, all coin bags do the same: getting your item.
What i am then doing is a bit tricky. I am dividing the random number I got by 2, then multiplied it by 2 again so that i have the even number, e.g: rand(getarraysize)) returns 3, divided by 2 equals 1 (because of rounding), then mult by 2 again is 2, which would be .@coins[2] which is the ID. the next element is .@coins[3], which is the amount of the item. then you just get the item with getitem.