Script Help

Post » Mon May 02, 2011 3:13 am

Hi. I have a trader who sells the player an item. The item has a script attached to it, and the script appears to do exactly what I want, except for one thing:

The traders purchase window is still open, and the script falls down because the player needs to manually close the purchase window AND click the big X button to return to the normal game mode. Is there a way to close the window and return to the game from within a script?

cheers

MVK
User avatar
Deon Knight
 
Posts: 3363
Joined: Thu Sep 13, 2007 1:44 am

Post » Sun May 01, 2011 5:56 pm

Without OBSE, I don't think so. I'm not even all too sure if scripts are allowed to run in the menu mode, because the game is technically paused. I've got a feeling that things update after the window is closed, when the game is unpaused.
Having said that, I could be very wrong! I'll have a little investigate though.

EDIT Okay, the only things I've found are http://cs.elderscrolls.com/constwiki/index.php/MenuMode_(Function) and http://cs.elderscrolls.com/constwiki/index.php/MenuMode, which are both functions to see whether you're in a menu or not (so I'd guess scripts still work in a menu mode!), but not to force putting them in. You could always use the http://cs.elderscrolls.com/constwiki/index.php/TapKey function (as esc) to get them out of the menu though, if worst comes to worst.
User avatar
Stephy Beck
 
Posts: 3492
Joined: Mon Apr 16, 2007 12:33 pm

Post » Sun May 01, 2011 7:02 pm

Without OBSE, I don't think so. I'm not even all too sure if scripts are allowed to run in the menu mode, because the game is technically paused. I've got a feeling that things update after the window is closed, when the game is unpaused.
Having said that, I could be very wrong! I'll have a little investigate though.


Thanks Kengon. Iv been trawling through the script commands on the Wiki but Iv not found anything. The script uses MoveTo to place the Player AND the NPC at a specific location and juggles a couple of items in the players inventory (gold and the item that was bought - both removed), but of course the effect is pretty useless if the 'Sales' window is still open!

[EDIT]
It occurred to me that if I told you what I was doing, you might have a better idea of what needs to be done:
1) The Trader has an item for sale. It is a single item that doesn't actually get taken by the player, only paid for.
2) When the player pays for the item the item is removed from the player inventory (It might also need replacing in the NPC trader chest, but I'm not sure just yet - The trader needs to sell the item many times but only has one of them and Iv not gotten far enough to see if it has actually gone!)
3) The player and the trader are transported to a specific location.
4) That's it! The player should now be able to run off and carry on with whatever he likes, while the trader will return to their starting point and carry on trading.

What actually happens is that the MoveTo seems to work and the item is removed from the player, along with the cost of the item.

However, the trader window is still open and needs 'Exit' to close it, and the player topic is still open, needing the big X to close that. If I do both of those things then both player and NPC appear stuck in place and are unable to move.
[EDIT]

MVK
User avatar
Katy Hogben
 
Posts: 3457
Joined: Mon Oct 30, 2006 12:20 am

Post » Sun May 01, 2011 9:40 pm

To run scripts in menus just use

Begin MenuMode   .....End

User avatar
A Dardzz
 
Posts: 3370
Joined: Sat Jan 27, 2007 6:26 pm

Post » Mon May 02, 2011 1:19 am

OBSE's TapKey should work for closing the menu, as mentioned.

I've found that MoveTo sometimes cause the script to run again, causing all kinds of bad effects if the MoveTo is used twice in a row.
Make sure you add a condition that prevents the MoveTo from running again for a few frames (a count or a timer would do).

Something like
Set MyCount to MyCount - 1 If MyCount < 0	Set MyCount to 5	NPC.Moveto xxx	Player.Moveto xxxendif

User avatar
Kirsty Collins
 
Posts: 3441
Joined: Tue Sep 19, 2006 11:54 pm

Post » Sun May 01, 2011 9:07 pm

Thanks all.

Iv started this mod without OBSE, so Ill carry on that way for now. Next time maybe...

Yes, I found both pages on the Wiki, but they didn't really help unfortunately, however, I managed to blag my way around the problem with some creative thinking:

The Trader only sells the one item, so rather than have the usual traders chest, list of items for sale etc, etc, I removed the chest entirely (and the custom item I was using to do this) and instead simply added the item as a choice on the NPC's dialog (along with another choice to turn it down).

Setting this choice item to be the 'Goodbye' item automatically closes the NPC dialog window (Saving me from having to press the big X), and in the script result box I added the following

Player.RemoveItem Gold001 16NPCPodTrader.MoveTo PodTradedMarker01Player.MoveTo PCPodTradedMarker01


This left one issue, in the the trader was originally sitting and appeared at the new location in the same position, where he seemed to get stuck until I left the cell and then returned, at which time he would get up from the invisible chair and make his way to where he sits and trades normally.

I got around that by tacking NPCPodTrader.EvaluatePackage on the end of the previous bit of script, so now he appears as he is getting up, and immediately makes his way back again, which is exactly what I wanted him to do.

Many thanks for your efforts everyone.

MVK
User avatar
Beat freak
 
Posts: 3403
Joined: Thu Dec 14, 2006 6:04 am


Return to IV - Oblivion