[Duda] Como hacer esto.
#1

Estoy intentando hacer un random con unos nъmeros que yo proporcione pero no doy con la forma.

pawn Код:
new NumeroObtenido[MAXIMO_NEGOCIOS] = 0;
for (new i = 0; i < MAXIMO_NEGOCIOS; i ++)
{
    if (NegociosInfo[i][bizType] == 1)
    {
        NumeroObtenido[i] = 1;
    }
}
//Aquн irнa el random ...
Hasta aquн todo correcto pero la duda es, ї como puedo crear un randon con la funciуn NumeroObtenido en 1 ?.
+Rep quien me ayude.
Reply
#2

No entiendo que quieres hacer, dime un ejemplo o algo
Reply
#3

No has especificado bien o no entendemos lo que quieres hacer pero te dejo algo de utilidad a ver si te sirve:

pawn Код:
new numerosRandom[] = { 10, 20, 35, 75 };

main()
{
    new rand = random(sizeof(numerosRandom));
    printf("El numero es %d", numerosRandom[rand]);
}
Reply
#4

Mi idea es hacer un bucle que recorre todos los negocios del tipo 1 y almacene sus IDS.
Ejemplo:
Negocio 1, 5, 8, 20.

Como puedo almacenar esas imбgenes y luego crear un bucle que vaya en orden correlativo si no el 1, 5, 8, 20 (serнan las IDS almacenadas con el tipo 1).

Mi idea es para el trabajo de camionero, que busque ciertos negocios y lo envie a uno obtenido al azar a traves del bucle.
Reply
#5

Код:
new NumeroObtenido[MAXIMO_NEGOCIOS] = 0;


new negocios_tipo_1;
for (new i = 0; i < MAXIMO_NEGOCIOS; i ++)
{
	NumeroObtenido[i] = -1;
	
	if (NegociosInfo[i][bizType] == 1)
	{
		NumeroObtenido[negocios_tipo_1] = i;
		negocios_tipo_1 ++;
	}
}

for (new i = 0; i < MAXIMO_NEGOCIOS; i ++)
{
	if(NumeroObtenido[i] != -1)
	{
		printf("%d", NumeroObtenido[i]);
	}
}
Reply
#6

Hasta ahн llego pero, ї ahora como puedo hacer un random con lo que se almacene en NumeroObtenido[i] ?

Suponiendo que obtenga por ejemplo:
5,8,20,40.

ї Como hago un random con esos resultados ?. Esa es la duda.
Reply
#7

NumeroObtenido[random(cantidad negocios tipo 1)] ?
Reply
#8

El cуdigo lo tengo asн:

pawn Код:
new NumeroObtenido[MAXIMO_NEGOCIOS] = 0;
            new negocios_tipo_1;

            for (new i = 0; i < MAXIMO_NEGOCIOS; i ++) if (NegociosInfo[i][bizExists])
            {
                NumeroObtenido[i] = -1;
                if (NegociosInfo[i][bizType] == 1)
                {
                    NumeroObtenido[negocios_tipo_1] = i;
                    negocios_tipo_1 ++;
                }
            }

            for (new i = 0; i < MAXIMO_NEGOCIOS; i ++) if (NegociosInfo[i][bizExists])
            {
                if(NumeroObtenido[i] != -1)
                {
                    printf("%d", NumeroObtenido[i]);
                }
            }
            new Valor2 =        random(negocios_tipo_1);
            MensajeDebug(Jugador, "Valor2 - %d", Valor2);
            printf("Valor2 %d", Valor2);
            DisablePlayerCheckpoint(Jugador);
            SetPlayerCheckpoint(Jugador, NegociosInfo[Valor2][bizDeliver][0], NegociosInfo[Valor2][bizDeliver][1], NegociosInfo[Valor2][bizDeliver][2], 3.0);
            SendInfoMensaje(Jugador, " El negocio fue marcado en tu gps.");
            EnDestinoCamionero[Jugador] = true;
Segъn la consola marca esto:

Код:
[01:54:45] 2
[01:54:45] 5
[01:54:45] 13
[01:54:45] 18
[01:54:45] 22
[01:54:45] 25
[01:54:45] 26
[01:54:45] 27
[01:54:45] 36
[01:54:45] 37
[01:54:45] Valor2 7
El random busca el negocio 7 pero como podrбs ver, dicho negocio no tiene el tipo 1 y por eso no aparece en la consola.
Reply
#9

Serнa asн:
Код:
new Valor2 =		NumeroObtenido[random(negocios_tipo_1)];
Reply
#10

Lo intentй de mil maneras y al final funcionу como decнas.

Menos mal que resucitaste para ayudarme xD.

Gracias.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)