Wierd bug.
#1

I've made a giftbox command. Here it is:

Код:
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;
}
The only problem is, that the variable "gift" is always 0. Even tho I've put "random(30)".
How can I fix this?
Reply
#2

Look at what I posted on your other thread: http://forum.sa-mp.com/showpost.php?...2&postcount=12

This is just a pure mess:
pawn Код:
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);
Reply
#3

Uhm first thing get rid off those 256 strings, u are using like 80-100 characters so like more than half is waste. Second, remove while. I recommend doing a switch there instead.
Reply
#4

The only problem is, that the variable "gift" is always 0. Even tho I've put "random(30)".
How can I fix this?[/QUOTE]

The main problem is your utilisation of while. This make no sence. ^^
Only the last while will be considered.
Reply
#5

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
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.[/QUOTE]

So how could I fix this?
Reply
#6

Quote:
Originally Posted by danielpalade
Посмотреть сообщение
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?
Ignoring possible solutions isn't going to fix it.
Reply
#7

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
Ignoring possible solutions isn't going to fix it.
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;
}
So let's say the random value is 0.
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.
Reply
#8

Quote:
Originally Posted by danielpalade
Посмотреть сообщение
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;
}
So let's say the random value is 0.
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.
How is it not what you're looking for? It's exactly what you want. Just use RemoveRandomAvailability(0) [instead of setting "money" to 0], and it will choose between other available options (randomly).

You would just have to add the available options with AddRandomAvailability, this can be done by loading some sort of configuration or doing it directly (if static), but it can be changed whenever you want as well.

prize^
Reply
#9

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;
}
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)