Jump to content

Stop a script from executing once all conditions are met?


Gunrock

Recommended Posts

I have a door (non repeatable) script that prints the following message:


script 7 (void)
{
 ambientsound("amb9",127);
 hudmessage(s:"This object requires a sacrifice to open."; HUDMSG_FADEOUT, 1, CR_gray, 0.5, 0.5, 4.0,
 1.0 // Time to fade to nothingness.
);
}
 

This script opens that door and prints a message:

 

script 8 (void)
{
 ambientsound("amb9",127);
 hudmessage(s:"Sacrifice accepted. Your pathway has now opened."; HUDMSG_FADEOUT, 1, CR_gray, 0.5, 0.5, 4.0,
 1.0 // Time to fade to nothingness.
);

Door_Open(20,32);
}

 

The problem is script 7 can still print the message even though the door is already opened. How can I cancel out script 7 when all conditions are met?

 

Thanks guys as always!!

Share this post


Link to post
script 7 (void)
{
	ambientsound("amb9",127);
	hudmessage(s:"This object requires a sacrifice to open."; HUDMSG_FADEOUT, 1, CR_gray, 0.5, 0.5, 4.0,
		1.0 // Time to fade to nothingness.
	);
}

script 8 (void)
{
	ambientsound("amb9",127);
	hudmessage(s:"Sacrifice accepted. Your pathway has now opened."; HUDMSG_FADEOUT, 1, CR_gray, 0.5, 0.5, 4.0,
		1.0 // Time to fade to nothingness.
	);
	Door_Open(20,32);
}

There are several different possibilities here. Perhaps the simplest would be with a variable.

bool doorOpened = false;

script 7 (void)
{
	if (doorOpened)
		terminate;
	ambientsound("amb9",127);
	hudmessage(s:"This object requires a sacrifice to open."; HUDMSG_FADEOUT, 1, CR_gray, 0.5, 0.5, 4.0,
		1.0 // Time to fade to nothingness.
	);
}

script 8 (void)
{
	doorOpened = true;
	ambientsound("amb9",127);
	hudmessage(s:"Sacrifice accepted. Your pathway has now opened."; HUDMSG_FADEOUT, 1, CR_gray, 0.5, 0.5, 4.0,
		1.0 // Time to fade to nothingness.
	);
	Door_Open(20,32);
}

But IMO the most elegant is to clear script 7 out of the lines that trigger it. But this require said lines to have a line ID. If your map format is UDMF, that's simple enough, with Hexen format it's more complex, you have to use special 121:Line_SetIdentification on them (instead of the ACS_Execute special that they currently have), and then have an OPEN script to attach ACS_Execute to them. But anyway, assuming your script-7-running lines have line ID 1337, then your scripts will look like this:

 

script 7 (void)
{
	ambientsound("amb9",127);
	hudmessage(s:"This object requires a sacrifice to open."; HUDMSG_FADEOUT, 1, CR_gray, 0.5, 0.5, 4.0,
		1.0 // Time to fade to nothingness.
	);
}

script 8 (void)
{
	SetLineSpecial(1337, 0)
	ambientsound("amb9",127);
	hudmessage(s:"Sacrifice accepted. Your pathway has now opened."; HUDMSG_FADEOUT, 1, CR_gray, 0.5, 0.5, 4.0,
		1.0 // Time to fade to nothingness.
	);
	Door_Open(20,32);
}

And there you go, the lines are made entirely inert when the door is opened.

Share this post


Link to post

Thanks as always Gez. It finally fixed the issue I was having throughout most of my mods in the past too. I was looking through the zdoom wiki and couldn't fully figure out about using "bool doorOpened = false;"

 

I guess after all these years of mapping I still have much to learn ;)

Share this post


Link to post

Join the conversation

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

Guest
Reply to this topic...

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

×
×
  • Create New...