trouble with object scripts

Post » Thu May 26, 2011 10:25 pm

I attached the script below, or variants of it, to most of the NV beverages, and made a "RobCo Cold Fission Froster" miscellaneous item that's supposed to turn any non-living container into a refrigerator. The idea is that leaving a beverage in a refrigerator for an hour turns it into the iced version of that beverage. There's a similar script that will turn the iced version back into the non-iced version if it's left unrefrigerated for an hour. It seems pretty straightforward, but it won't work. Are there any problems associated with having a bunch of scripted objects in an inventory at the same time, or something like that?

scn IMCNWarmBeerScriptref rContainershort sDoOncefloat fChillTimershort sWaitedbegin gamemode	IF fChillTimer == 0		set fChillTimer to gamedayspassed	ELSEif rContainer != getcontainer		set rContainer to getcontainer	ELSEif fChillTimer + 0.04 < gamedayspassed && sDoOnce == 0 && sWaited == 0		; roughly 1 hour		set sDoOnce to 1		rContainer.additem BeerIMCNIced 1 1		removeme	ELSEif rContainer.getitemcount IMCNFroster		set sWaited to 0		IF rContainer.isActor == 0 || rContainer == EDE1Ref || rContainer == EDE2Ref || rContainer == EDE3Ref   ; 3 versions of ED-E (robots can be refrigerators)		ELSE			set fChillTimer to gamedayspassed		ENDif	ELSE		set sWaited to 0		set fChillTimer to gamedayspassed	ENDifendbegin menumode	IF menumode 1012		set sWaited to 1	ENDifend

User avatar
Nicole Elocin
 
Posts: 3390
Joined: Sun Apr 15, 2007 9:12 am

Post » Thu May 26, 2011 9:13 pm

I did a test, it seems like they run fine when the objects are in the player's inventory, but sporadically when the objects are elsewhere - like only one object's script will run, if that.
User avatar
Phillip Brunyee
 
Posts: 3510
Joined: Tue Jul 31, 2007 7:43 pm

Post » Fri May 27, 2011 12:17 am

I'm not exactly sure what your process is here but, keep in mind that if your scripted object is not in the same loaded area as the player and you're trying to run timers and such, it's not exactly going to .. work. You'd want to manage the process via a quest script (which will run no matter where the player may be) if you need to do that sort of operation. I couldn't tell you if this is your particular problem but you will need to keep it in mind.
User avatar
WTW
 
Posts: 3313
Joined: Wed May 30, 2007 7:48 pm

Post » Fri May 27, 2011 12:51 am

Thanks. As long as the script variables aren't reset when the player leaves the cell they're running in, it should continue to work. But my test was with my companions, who were both standing right next to me. I'm using the same technique to add food spoilage for a FO3 mod, and I'm pretty sure it worked - I sold some meat to a vendor, and came back a few days later and the vendor had the right number of spoiled food items in their inventory. NV seems to have inventory bugs though, like the way that items will disappear if you have more than one of the same condition in your inventory (even if one of them has mods installed...)

The way the script works, the beverage determines what it's container is via getcontainer. It also stores the current gamedayspassed in a timer variable. For warm beverages, if the container is not an actor, or is one of the ED-E refs, and has a Cold Fission Froster in its inventory, the timer is not updated. Otherwise it is continuously updated with the current number of gamedayspassed. So in the first case, that the item is in a valid refrigerator container, the difference between the stored time value and the current gamedayspassed will increase as gametime passes. Once the difference is greater that 0.04 days (1 hour) the item puts a chilled version of itself into the container, and then removes itself. As far as I know, if the item is not in the same cell as the player and its script is not processing, but the script's variables are not reset, the timer variable will not update while the player is in another cell. When the player reenters the cell, the timer will be updated if the container is not a refrigerator, but if it is a refrigerator, the swap should happen if enough gametime has elapsed. I rewrote the script to make it a bit simpler, but still no luck.

scn IMCNWarmBeerScriptref rContainershort sDoOncefloat fChillTimershort sWaitedbegin gamemode	IF fChillTimer == 0		set fChillTimer to gamedayspassed	ELSEif rContainer != getcontainer || rContainer == 0		set rContainer to getcontainer	ELSEif rContainer.getitemcount IMCNFroster == 0 || (rContainer.isActor && rContainer != EDE1Ref && rContainer != EDE2Ref && rContainer != EDE3Ref)		set fChillTimer to gamedayspassed	ELSEif fChillTimer + 0.04 < gamedayspassed && sDoOnce == 0 && sWaited == 0		; roughly 1 hour		set sDoOnce to 1		rContainer.additem BeerIMCNIced 1 1		removeme	ENDifend

User avatar
Penny Courture
 
Posts: 3438
Joined: Sat Dec 23, 2006 11:59 pm

Post » Fri May 27, 2011 12:28 am

Probably a better game mode block to hang this off of would be the OnLoad event. That fires for every object within the cell whenever the player enters it (or causes it to load). Whether items inside of containers also fire OnLoad(), I'm not 100% sure.
User avatar
Lillian Cawfield
 
Posts: 3387
Joined: Thu Nov 30, 2006 6:22 pm

Post » Fri May 27, 2011 9:02 am

Ok, I think I figured it out. I attached a test script that just pops up a message every 300 frames to giant rat meat (my character happened to have 6 of 'em in his inventory). Loaded the game, and nothing. I tried moving them into other character's inventories and into various containers, still nothing. Then I dropped one from my inventory, and bam, saw the message. I picked it up, and the message kept popping up every few seconds like it should. I dropped a couple more from my inventory, and more messages started popping up, even after I'd moved the objects back into my inventory. I put them into a safe and then left the high roller suite it was in, and the messages stopped, but resumed when I returned. The message that popped up showed a counter of how many times the message had been displayed - when I went back to the cell, the counts picked up where they left off, so the object scripts stop executing when you're not in the cell with them, but their variables don't get reset (so my cold and warm beverage scripts, and food spoilage scripts, will work as intended). I then reloaded the save, and added a giant rat meat to my inventory via the console, and the messages started appearing.

So it looks like a script won't run on an existing object if it was added via a mod after that object was loaded into the game world - meaning the features will probably work fine with new games, but not with any items already in the player's inventory or in a cell that's already been visited. Not the greatest thing, but at least my idea will work (most meat get's introduced into the game by being spawned as a death item, so it's scripts will always work). As for what's in a characters current inventory, I could just include instructions to drop the entire inventory, and then pick it back up. Or write a script that goes through the player's inventory and removes/readds all of the ingestibles at the touch of a button. Boy would that be tedious though - there are a ton of foods. It would be relatively easy with NVSE, but I was hoping to avoid being dependent on that with this mod.
User avatar
tannis
 
Posts: 3446
Joined: Sat Dec 09, 2006 11:21 pm

Post » Fri May 27, 2011 11:27 am

Or write a script that goes through the player's inventory and removes/readds all of the ingestibles at the touch of a button. Boy would that be tedious though - there are a ton of foods. It would be relatively easy with NVSE, but I was hoping to avoid being dependent on that with this mod.


You don't need NVSE for that. RemoveAllTypedItems does what you want - just move all aid items to another container and back and use an empty holdout list.
User avatar
Lewis Morel
 
Posts: 3431
Joined: Thu Aug 16, 2007 7:40 pm

Post » Fri May 27, 2011 12:56 am

I'll try it, that would definitely be simpler, but I'm not sure that would "refresh" the items. Removeallitems (and I'm assuming removealltypeditems) retains the condition of items like weapons and armor - so I think it might be the same as just moving an item from your inventory into another container - which I've verified does not refresh the item.

*Edit - Yeah, no luck, at least with "removeallitems". It's just like moving the items from you inventory into the new container.
User avatar
Kayla Oatney
 
Posts: 3472
Joined: Sat Jan 20, 2007 9:02 pm


Return to Fallout: New Vegas