[Ayuda] Repeticiуn en valores random.
#1

Como dice el titulo, tengo un problema en unos valores random, resulta, que se repiten... y muchas veces. Es un caso de un test de preguntas que hay mбs o menos 15 y se randomizan, pero sale como 5 veces la misma pregunta y eso molesta. їComo puedo hacer para que salga solo una vez esa pregunta y luego salgan mas pero sin repetirse?

El cуdigo es el siguiente.

Код:
stock Test(playerid, section)
{
	
    if(section == 1)
	{
	    Dialog_Show(playerid, QUIZ1, DIALOG_STYLE_LIST, "Antes que nada, їsabes de rol?"," (A) Sн\n (B) No","Seleccionar","");
	}
        else
	{
	    new rand = random(sizeof(QuizQuestions)); <-- valor random de las preguntas.

	    CreateSpacer(playerid, 10); <-- espaciador de chat, no interfiere.

	    format(QAnswer[playerid], 2, "%d", strval(QuizQuestions[rand][0]));

	    Dialog_Show(playerid, QUIZ2, DIALOG_STYLE_LIST, QuizQuestions[rand][1], QuizQuestions[rand][2],"Seleccionar","");

	    SendSplitMessage(playerid, COLOR_SLATEGRAY, QuizQuestions[rand][1]); <- no interfiere
	    SendSplitMessage(playerid, COLOR_WHITE, QuizQuestions[rand][2]); <- no interfiere
	}
	return 1;
}
Reply
#2

Код:
// ** Declarando la variable.

new bool:preguntas_test[MAX_PLAYERS][MAX_PREGUNTAS];

// ** OnPlayerConnect o en la funciуn donde reseteas las variables.

for(new x = 0; x < MAX_PREGUNTAS; x++) preguntas_test[playerid][x] = false;

// ** Funciуn

stock Test(playerid, section)
{
    if(section == 1) return Dialog_Show(playerid, QUIZ1, DIALOG_STYLE_LIST, "Antes que nada, їsabes de rol?"," (A) Sн\n (B) No", "Seleccionar", "");

	new rand = random(sizeof(QuizQuestions));
	if(preguntas_test[playerid][rand] == true) return Test(playerid, section);
	preguntas_test[playerid][rand] = true;

	CreateSpacer(playerid, 10);

	format(QAnswer[playerid], 2, "%d", strval(QuizQuestions[rand][0]));

	Dialog_Show(playerid, QUIZ2, DIALOG_STYLE_LIST, QuizQuestions[rand][1], QuizQuestions[rand][2], "Seleccionar", "");

	SendSplitMessage(playerid, COLOR_SLATEGRAY, QuizQuestions[rand][1]);
	SendSplitMessage(playerid, COLOR_WHITE, QuizQuestions[rand][2]);
	return 1;
}

// ** OnPlayerDisconnect

for(new x = 0; x < MAX_PREGUNTAS; x++) preguntas_test[playerid][x] = false;
Йsta es una manera, en MAX_PREGUNTAS debes colocar el valor total de las preguntas, ya sea colocando el #define encima de todo o cambiбndolo sуlo por el nъmero total de las preguntas, saludos.
Reply
#3

Quote:
Originally Posted by LatinZ
Посмотреть сообщение
Код:
// ** Declarando la variable.

new bool:preguntas_test[MAX_PLAYERS][MAX_PREGUNTAS];

// ** OnPlayerConnect o en la funciуn donde reseteas las variables.

for(new x = 0; x < MAX_PREGUNTAS; x++) preguntas_test[playerid][x] = false;

// ** Funciуn

stock Test(playerid, section)
{
    if(section == 1) return Dialog_Show(playerid, QUIZ1, DIALOG_STYLE_LIST, "Antes que nada, їsabes de rol?"," (A) Sн\n (B) No", "Seleccionar", "");

	new rand = random(sizeof(QuizQuestions));
	if(preguntas_test[playerid][rand] == true) return Test(playerid, section);
	preguntas_test[playerid][rand] = true;

	CreateSpacer(playerid, 10);

	format(QAnswer[playerid], 2, "%d", strval(QuizQuestions[rand][0]));

	Dialog_Show(playerid, QUIZ2, DIALOG_STYLE_LIST, QuizQuestions[rand][1], QuizQuestions[rand][2], "Seleccionar", "");

	SendSplitMessage(playerid, COLOR_SLATEGRAY, QuizQuestions[rand][1]);
	SendSplitMessage(playerid, COLOR_WHITE, QuizQuestions[rand][2]);
	return 1;
}

// ** OnPlayerDisconnect

for(new x = 0; x < MAX_PREGUNTAS; x++) preguntas_test[playerid][x] = false;
Йsta es una manera, en MAX_PREGUNTAS debes colocar el valor total de las preguntas, ya sea colocando el #define encima de todo o cambiбndolo sуlo por el nъmero total de las preguntas, saludos.
Debes tener en cuenta que si sobrepasa el mбximo de MAX_PREGUNTAS no va a funcionar, y por ende, causa un crash. Siempre se va a repetir la condiciуn porque ya todos estan en 1.
Reply
#4

Creo que la mejor forma es almacenar de la forma en que LatinZ detectaba si un valor ya se habнa utilizado, pero desde un bucle pasar a otro array temporal de forma ordenada los datos y obtener los datos de las preguntas basandoce en ese nuevo array y la cantidad de datos que posee (en el parбmetro random) asн basicamente va eliminando datos que ya se utilizaron.

edit: en cuanto llegue a casa pongo un ejemplo en caso de que no se entienda
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)