Jump to content
  • 0
Khazou

Go to a label stored as a string and preserve Npc temp var

Question

Hi everybody :)
Does someone know a way to go to a label stored as a string and preserve Npc temp var.

I know about *doevent and *donpcevent, but as they start a new instance of a npc, npc temp var (.@var), are reset when i hit the label.

*goto preserve npc temp var but it can't be used with string like: goto "OnMyLabel"

Thx in advance ^^

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 1

Hi there, I refactored your script

rothyr,210,146,4	script	Styliste#rot	2_M_DYEINGER,{

	function changeSingleStyle {
		.@backup = getlook(getarg(0));
		.@current = getarg(1);

		do {
			setlook(getarg(0), .@current);
			mesf("C'est le style #%i.", .@current);

			select((.@current + 1) <= getarg(2) ? "Suivant" : "",
				(.@current - 1) >= getarg(1) ? "Précédent" : "",
				"Aller à...",
				.@current > getarg(1) ? "Aller au début" : "",
				.@current < getarg(2) ? "Aller à la fin" : "",
				"Parfait!",
				"Annuler!");

			switch (@menu) {
			case 1: ++.@current; break;
			case 2: --.@current; break;
			case 3: input(.@current, getarg(1), getarg(2)); break;
			case 4: .@current = getarg(1); break;
			case 5: .@current = getarg(2); break;
			case 7: setlook(getarg(0), .@backup); // fallthrough
			case 6:
				mes("Ok, c'est fait.");
				mes("Besoin d'autre chose?");
				next();
				return;
			}
		} while (true);
	}

	function changeAllStyles {
		setarray(.@backup[0], getlook(LOOK_HAIR), getlook(LOOK_HAIR_COLOR), getlook(LOOK_CLOTHES_COLOR));

		do {
			if (getarg(0)) {
				setlook(LOOK_HAIR, rand(.min_style, .max_style));
				setlook(LOOK_HAIR_COLOR, rand(.min_color, .max_color));
				setlook(LOOK_CLOTHES_COLOR, rand(.min_cloth, .max_cloth));
			} else {
				mes("Veuillez entrer le N° de couleur de vêtement:");
				input(.@i, .min_cloth, .max_cloth);
				setlook(LOOK_CLOTHES_COLOR, .@i);

				mes("Veuillez entrer le N° de style de cheveux:");
				input(.@i, .min_style, .max_style);
				setlook(LOOK_HAIR, .@i);

				mes("Veuillez entrer le N° de couleur de cheveux:");
				input(.@i, .min_color, .max_color);
				setlook(LOOK_HAIR_COLOR, .@i);
			}

			mesf("Vous avez présentement la coupe #%i de couleur #%i, avec des vêtements de couleur #%i.",
				getlook(LOOK_HAIR), getlook(LOOK_HAIR_COLOR), getlook(LOOK_CLOTHES_COLOR));

			select("Recommencer",
				"Parfait!",
				"Annuler!");

			switch (@menu) {
			case 3:
				setlook(LOOK_HAIR, .@backup[0]);
				setlook(LOOK_HAIR_COLOR, .@backup[1]);
				setlook(LOOK_CLOTHES_COLOR, .@backup[2]);
			case 2: return;
			}
		} while (true);
	}

	cutin("job_alche_vincent", 2);
	mesf("[ %s ]", strnpcinfo(NPC_NAME));

	// OnClick
	mes("Bonjour, que puis-je faire pour vous?");
	next();

	do {
		mesf("Vous avez présentement la coupe #%i de couleur #%i, avec des vêtements de couleur #%i.",
			getlook(LOOK_HAIR), getlook(LOOK_HAIR_COLOR), getlook(LOOK_CLOTHES_COLOR));

		select("Couleur de vêtement",
			"Coupe de cheveux",
			"Couleur de cheveux",
			"Tout changer d'un coup",
			"Au hasard",
			"Quitter");

		switch (@menu) {
		case 1:
			changeSingleStyle(LOOK_CLOTHES_COLOR, .min_cloth, .max_cloth);
			break;
		case 2:
			changeSingleStyle(LOOK_HAIR, .min_style, .max_style);
			break;
		case 3:
			changeSingleStyle(LOOK_HAIR_COLOR, .min_color, .max_color);
			break;
		case 4:
			changeAllStyles(false);
			break;
		case 5:
			changeAllStyles(true);
			break;
		default:
			close;
		}
	} while (true);

OnInit:
	.min_style = max(1, getbattleflag("min_hair_style"));
	.max_style = getbattleflag("max_hair_style");
	.min_color = max(1, getbattleflag("min_hair_color"));
	.max_color = getbattleflag("max_hair_color");
	.min_cloth = max(1, getbattleflag("min_cloth_color"));
	.max_cloth = getbattleflag("max_cloth_color");
}

Down from 326 lines to just 121 lines, while still preserving functionality and while avoiding the goto spaghetti

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.