CMD:getgift(playerid, params[]) { if(playerVariables[playerid][pPlayingHours] >= 3) { if(boxVariables[1][boxStatus] == 1) { if(IsPlayerInRangeOfPoint(playerid, 5.0, boxVariables[1][boxX], boxVariables[1][boxY], boxVariables[1][boxZ])) { format(szMessage, 256, "Poti folosi /getgift peste %d ore.", playerVariables[playerid][pGiftHours]); /*if(playerVariables[playerid][pGiftHours] == 0) {*/ new string[256]; new gift = random(30); while(gift == 0 && boxVariables[1][boxVehicle] != 0) gift = random(30); while(gift > 0 || gift < 2 && boxVariables[1][boxPP] != 0) gift = random(30); while(gift > 1 && gift < 7 && boxVariables[1][boxMoney] != 0) gift = random(30); while(gift > 6 && gift < 12 && boxVariables[1][boxMats] != 0) gift = random(30); while(gift > 11 && gift < 17 && boxVariables[1][boxClearWarns] != 0 && playerVariables[playerid][pWarns] != 0) gift = random(30); while(gift > 13 && gift < 16 && boxVariables[1][boxClearFP] != 0 && playerVariables[playerid][pFP] != 0) gift = random(30); while(gift > 15 && gift < 21 && boxVariables[1][boxFireWorks] != 0) gift = random(30); while(gift > 20 && gift < 23 && boxVariables[1][boxHidden] != 0) gift = random(30); while(gift > 22 && gift < 27 && boxVariables[1][boxLic] != 0) gift = random(30); printf("%d", gift); if(gift == 0) //5% { format(string, sizeof(string), "GiftBox: %s a castigat un %s din giftbox. Felicitari!", GetName(playerid), VehicleNames[boxVariables[1][boxVehicle] - 400]); SendClientMessageToAll(COLOR_LIGHT, string); } if(gift > 0 && gift < 2) //5% { new pp = 10 + random(50); format(string, sizeof(string), "GiftBox: %s a castigat %d puncte premium din giftbox. Felicitari!", GetName(playerid), pp); SendClientMessageToAll(COLOR_LIGHT, string); } if(gift > 1 && gift < 7) //25% { new money = 200000 + random(1000000); format(string, sizeof(string), "* Ai castigat $%s din giftbox.", NumberFormat(money)); SendClientMessage(playerid, COLOR_YELLOW, string); } if(gift > 6 && gift < 12) //25% { new mats = 5000 + random(30000); format(string, sizeof(string), "* Ai castigat %s materiale din giftbox.", NumberFormat(mats)); SendClientMessage(playerid, COLOR_YELLOW, string); } if(gift > 11 && gift < 14) //10% { SendClientMessage(playerid, COLOR_YELLOW, "* Ai castigat clear warns la giftbox!"); } if(gift > 13 && gift < 16) //10% { SendClientMessage(playerid, COLOR_YELLOW, "* Ai castigat clear fp la giftbox!"); } if(gift > 15 && gift < 21) //25% { new fireworks = 10 + random(30); format(string, sizeof(string), "* Ai castigat %s artificii din giftbox.", NumberFormat(fireworks)); SendClientMessage(playerid, COLOR_YELLOW, string); } if(gift > 20 && gift < 23) //10% { SendClientMessage(playerid, COLOR_YELLOW, "* Ai castigat un hidden din giftbox!"); } if(gift > 22 && gift < 27) //20% { SendClientMessage(playerid, COLOR_YELLOW, "* Ai castigat toate licentele +500 la giftbox!"); } playerVariables[playerid][pGiftHours] = 3; /* } else SCM(playerid,COLOR_YELLOW, szMessage);*/ } else { SCM(playerid,COLOR_WHITE, "You are not at giftbox location. Go to checkpoint."); SetPlayerCheckpoint(playerid, 1129.31531, -1448.38330, 15.43760, 5.0); } } else SCM(playerid,COLOR_YELLOW,"The gift is not active."); } else SCM(playerid,COLOR_WHITE, "Ai nevoie de 3 ore jucate pentru a folosi comanda /getgift."); return 1; }
while(gift == 0 && boxVariables[1][boxVehicle] != 0) gift = random(30);
while(gift > 0 || gift < 2 && boxVariables[1][boxPP] != 0) gift = random(30);
while(gift > 1 && gift < 7 && boxVariables[1][boxMoney] != 0) gift = random(30);
while(gift > 6 && gift < 12 && boxVariables[1][boxMats] != 0) gift = random(30);
while(gift > 11 && gift < 17 && boxVariables[1][boxClearWarns] != 0 && playerVariables[playerid][pWarns] != 0) gift = random(30);
while(gift > 13 && gift < 16 && boxVariables[1][boxClearFP] != 0 && playerVariables[playerid][pFP] != 0) gift = random(30);
while(gift > 15 && gift < 21 && boxVariables[1][boxFireWorks] != 0) gift = random(30);
while(gift > 20 && gift < 23 && boxVariables[1][boxHidden] != 0) gift = random(30);
while(gift > 22 && gift < 27 && boxVariables[1][boxLic] != 0) gift = random(30);
The only problem is, that the variable "gift" is always 0. Even tho I've put "random(30)".
How can I fix this? |
The main problem is your utilisation of while. This make no sence. ^^
Only the last while will be considered. So how could I fix this? |
new money, vehicle, level; money = 0; vehicle = 1; level = 1; CMD:getgift(playerid, params[]) { new rand = random(20); if(rand == 0 && money == 1) { //do this } else if(rand == 1 && vehicle == 1) { //do this } else if(rand == 2 && level == 1) { //do this } return 1; }
What you've made is not what I'm looking for.
All I want is a command that will choose a random value between 0 and 20. Example: Код:
new money, vehicle, level; money = 0; vehicle = 1; level = 1; CMD:getgift(playerid, params[]) { new rand = random(20); if(rand == 0 && money == 1) { //do this } else if(rand == 1 && vehicle == 1) { //do this } else if(rand == 2 && level == 1) { //do this } return 1; } As you can see, you will only get the price if rand == 0 and money == 1. But money is equal to 0 as defined above, so the player would not get anything. How can I make it so it will choose a different random value so the player would get something. |
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;
}
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 Код:
|