Run Script After Container is Closed

Post » Fri Apr 30, 2010 5:28 am

Is it possible to run a script on a container after it is closed using the OnActivate Block? Currently I have a script that does a bunch of stuff and then activates the container. If I activate the container first the script executes before any items are added to the container which is not helpful.

Basically what I want to know: Is there any way to delay the start of the script until after I activate the container and it is subsequently closed?

(sorry if I cause any confusion, I know what I want, but sometimes don't explain things thoroughly/correctly)
User avatar
Jade Payton
 
Posts: 3417
Joined: Mon Sep 11, 2006 1:01 pm

Post » Thu Apr 29, 2010 11:54 pm

You would need two scripts, a script on the container, an a quest script.

The script on the container would be:

begin onactivateactivateset [QuestName].chestopened to 1end


then in your quest script you have a variable called chestopened and refer to like so:
begin gamemodeif chestopened == 1[do stuff]set chestopened to 0endifend


what this does; whenever the container is opened, a variable is set in a quest script, that script in the quest script will run every time you close the container. If you dont want to deal with multiple scripts, then you could put both parts into the container scirpt. I hope this is what you were talking about.
User avatar
Rebekah Rebekah Nicole
 
Posts: 3477
Joined: Fri Oct 13, 2006 8:47 pm

Post » Thu Apr 29, 2010 2:31 pm

Tried this real quickly, but it does not appear to be working either... I'll have to due more thorough testing and recheck my code in the morning

Also, in the wiki for startquest "Avoid calling this function to start a quest which is already running. If there is a script attached to the quest, any variables will be reset to 0 when the saved game is reloaded." Quest variables are deleted when you reload the game? That would mess up my script if it is true, though would make sense. Any way around that if this is the case?
User avatar
Poetic Vice
 
Posts: 3440
Joined: Wed Oct 31, 2007 8:19 pm

Post » Thu Apr 29, 2010 3:24 pm

Tried this real quickly, but it does not appear to be working either... I'll have to due more thorough testing and recheck my code in the morning
It should work, I do similar timing tricks all the time. There MAY be a problem with the timing though, maybe the engine lets the gamemode block run for a couple of frames AFTER the onActivate block has run, but before the container is fully opened. To ensure that this is not a problem you could expand the code a bit. Use da mage's code, but add a small menumode block as well, and change the check in the gamemode block. This way you are 100% sure that the gamemode block doesn't get to run until the container has been actiavated, opened and closed.

begin menumode  if chestopened == 1    set chestopened to 2  endifend



begin gamemodeif chestopened == 2[do stuff]set chestopened to 0endifend


Also, in the wiki for startquest "Avoid calling this function to start a quest which is already running. If there is a script attached to the quest, any variables will be reset to 0 when the saved game is reloaded." Quest variables are deleted when you reload the game? That would mess up my script if it is true, though would make sense. Any way around that if this is the case?
They are only deleted if you have called Startquest on the quest before the last save. So just don't call Startquest more than once (All my gametweak scripts are enabled from the start of the game, and I never call startquest on them), and you avoid the problem.
User avatar
Paula Rose
 
Posts: 3305
Joined: Fri Feb 16, 2007 8:12 am

Post » Thu Apr 29, 2010 3:35 pm

To expand a little on TheNiceOne's point. If you have a need for the quest's activity to wait for the opening of the chest, you can just short-circuit the quest script with a test at the top of the gamemode block;
If chestOpened == 0   returnendif

Any code below this won't happen until chestOpened has become non-zero, so setting it becomes the equivalent of starting the quest. In this case you'd never set it back to zero, you'd use 3,4,or 5 as the "done with chest stuff" setting.
User avatar
James Hate
 
Posts: 3531
Joined: Sun Jun 24, 2007 5:55 am

Post » Fri Apr 30, 2010 5:10 am

They are only deleted if you have called Startquest on the quest before the last save. So just don't call Startquest more than once (All my gametweak scripts are enabled from the start of the game, and I never call startquest on them), and you avoid the problem.


That is what I thought, but just wanted to make sure

And I'm pretty sure that it is because activate takes a few seconds to open, so hopefully what ghastly said will work, will try it and see if it works, thanks for the help :)

To expand a little on TheNiceOne's point. If you have a need for the quest's activity to wait for the opening of the chest, you can just short-circuit the quest script with a test at the top of the gamemode block;

If chestOpened == 0
return
endif


Any code below this won't happen until chestOpened has become non-zero, so setting it becomes the equivalent of starting the quest. In this case you'd never set it back to zero, you'd use 3,4,or 5 as the "done with chest stuff" setting.

User avatar
Svenja Hedrich
 
Posts: 3496
Joined: Mon Apr 23, 2007 3:18 pm


Return to IV - Oblivion