How should I do this?
#1

Hello, I'm working on my giftbox system.
The command /getgift should select a random value between 0 and 10, and give him the random generated gift.
Now I know how to make that command, but I would want it to do the following thing.
* Check if the gift is available, else re-roll till you have an available gift.
So let's say the random generated value is 5.
My code would be like this:
Код:
CMD:getgift(playerid, params[])
{
      new rand = random(10);
      if(rand == 5)
      {
             SendClientMessage(playerid, -1, "You have won $500,000!");
      }
      return 1;
}
But, let's say that "money" isn't available right now.
- Giftbox money gift is defined as "boxVariables[1][boxMoney]".
How would I re-generate the value and make sure he will get a different gift if the other ones are not available?
Reply
#2

Alright. I don't sure I have understand everything.
You want make something which is checking if the money of a gift is available to give him to the player?
If I'm totally wrong; can you, please, make a example ?
Reply
#3

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
Alright. I don't sure I have understand everything.
You want make something which is checking if the money of a gift is available to give him to the player?
If I'm totally wrong; can you, please, make a example ?
So let's say we have this command.

Код:
CMD:getgift(playerid, params[])
{
	new rand = random(10);
	if(rand == 5 && boxVariables[1][boxMoney] == 1)
	{
		SendClientMessage(playerid, -1, "You have won $500,000!");
	}
	else if(rand == 0 && boxVariables[1][boxVehicle] == 1)
	{
		SendClientMessage(playerid, -1, "You have won a car!");
	}
	return 1;
}
As you can see, if the random value is 5 and boxMoney == 1, it will give him the money.
But let's say he gets the value 5, but boxMoney is 0, how could I make it so it will choose a different number and give him a different price.
Right now, if he rolls 5 and boxMoney is equal to 0, he won't get anything.
Reply
#4

Alright.. I still reticent.
PHP код:
CMD:getgift(playeridparams[])
{
    new 
bool:done false;
    while(!
done)
    {
        new 
rand random(10);
        switch(
rand)
        {
            case 
:
            {
                if(
boxVariables[1][boxMoney] == 1)  SendClientMessage(playerid, -1"You have won $500,000!"), GivePlayerMoney(playeridrand*1000), done true;
                else if (
boxVariables[1][boxVehicle] == 1SendClientMessage(playerid, -1"You have won a car!"), done true;
                else 
rand random(10);
            }
            
// case ...
        
}
    }
    return 
1;

Something like that?
Reply
#5

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
Alright.. I still reticent.
PHP код:
CMD:getgift(playeridparams[])
{
    new 
bool:done false;
    while(!
done)
    {
        new 
rand random(10);
        switch(
rand)
        {
            case 
:
            {
                if(
boxVariables[1][boxMoney] == 1)  SendClientMessage(playerid, -1"You have won $500,000!"), GivePlayerMoney(playeridrand*1000), done true;
                else if (
boxVariables[1][boxVehicle] == 1SendClientMessage(playerid, -1"You have won a car!"), done true;
                else 
rand random(10);
            }
            
// case ...
        
}
    }
    return 
1;

Something like that?
No. How about.
How could I make a command that will choose a random value till it hits number 3 for example?
So for example:

Код:
CMD:test(playerid, params[])
{
     new rand = random(10);
     if(rand == 3)
     {
           SendClientMessage(playerid, -1, "It has hit number 3!");
     }
     else
     {
           //Re-choose a random number till the number is 3.
     }
     return 1;
}
Reply
#6

OH!
This is more simple.
PHP код:
CMD:test(playeridparams[])
{
    new 
rand random(10);
    while(
rand != 3rand random(10);
    
printf("Rand = %i"rand);

Reply
#7

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
OH!
This is more simple.
PHP код:
CMD:test(playeridparams[])
{
    new 
rand random(10);
    while(
rand != 3rand random(10);
    
printf("Rand = %i"rand);

Yes! This is what I'm looking for.
Would this work?
Код:
CMD:test(playerid, params[])
{
	new rand = random(10);
	while(rand == 5 && boxVariables[1][boxMoney] == 0) rand = random(10);
	while(rand == 2 && boxVariables[1][boxVehicle] == 0) rand = random(10);
	return 1;
}
Reply
#8

Hmm.. If
PHP код:
boxVariables[1][boxMoney] == 
will be an infinite loop because the condition will never be verified.
This one : boxVariables[1][boxMoney] == 0 mean there is no money in the gift ?
Reply
#9

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
Hmm.. If
PHP код:
boxVariables[1][boxMoney] == 
will be an infinite loop because the condition will never be verified.
This one : boxVariables[1][boxMoney] == 0 mean there is no money in the gift ?
Yes.
Reply
#10

So, you should change your function to:
PHP код:
CMD:test(playeridparams[])
{
    new 
rand random(10);
    while(
rand == && boxVariables[1][boxMoney] != 0rand random(10);
// While rand is equal to 5 and box's money isn't equal to 0 - attribute to random a new value
    
while(rand == && boxVariables[1][boxVehicle] != 0rand random(10);
    return 
1;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)