Quote:
Originally Posted by SickAttack
I'd suggest you use the snippet I posted. But since you're a bit stubborn, I'll post another method (not as efficient as the snippet, but it would get the job done):
pawn Код:
CMD:getgift(playerid, params[]) { // Get available gifts
new available_gifts[3], count; if(boxVariables[1][boxLic]) // If not 0, thus 1 { available_gifts[count] = 1; count ++; } else if(boxVariables[1][boxMoney]) // If not 0, thus 1 { available_gifts[count] = 2; count ++; } else if(boxVariables[1][boxFireWorks]) // If not 0, thus 1 { available_gifts[count] = 3; count ++; }
// Select random available gift
switch(available_gifts(random(count))) { case 1: { // boxLic } case 2: { // boxMoney } case 3: { // boxFireWorks } default: { // No gifts are available } } return 1; }
|
And what should I do if I would want to have a certain percentage chance to get a certain gift?
That's why I was using new rand = random(20);
So I could do, "if(rand < 5) { //do code }" which would mean that it would be 10% chance to get the gift.