Jump to content

AddItem at certain times after conditions


Meridias561

Recommended Posts

Just a little question that I would like some help on, and if something like it has been asked already I apologize.

 

I'm new to modding so I don't have major grasp on the CK and papyrus systems just yet. In the mod I'm making, I'm going to try to get a script set up for a chest that: every day at noon, after some conditions are met, adds an item(s) to a specific chest regardless of whether the cell it's in is loaded or not. The question being, is this possible? Pretty sure the whole adding the item part is (once I figure it out or get help), but is there a way for scripts to run for events or objects that are outside the currently loaded cells?

Link to comment
Share on other sites

 

;assuming I understand this right, the function sets the timer and
;when the timer ends, fires the event allowing for fast travel ends, etc

function Testname()
HoursTilNextNoon = GetCurrentHourOfDay()
if HoursTilNextNoon < 12
;it is before noon
	RegisterForSingleUpdateGameTime(HoursTilNextNoon)
elseif HoursTilNextNoon == 12
;it is noon, set for next day
	RegisterForSingleUpdateGameTime(24)
else
;it is after noon
	HoursTilNextNoon = 36 - HoursTilNextNoon
	RegisterForSingleUpdateGameTime(HoursTilNextNoon)
endif
endFunction




Event OnUpdateGameTime()

;actual stuff for AddItem and such goes here

endEvent

 

 

Ok, here's the bare bones of the start of the script. Anyone willing to let me know if I'm even on the right track? And if I am, my next questions are gonna be how to re-call the script for the next day and where to put the script in the first place (on the chest objref, in a quest just to run the script on the chest, etc).

Edited by Meridias561
Link to comment
Share on other sites

That looks right to me.

 

Put the script on the chest, then it'll become active the first time the chest is loaded in the game. You don't need to re-call the sgript, that's done by the RegisterForSingleUpdateGameTime Function. Just make sure you allow for more than one day to pass by adding a RegisterForSingleUpdateGameTime (24) line in the OnUpdateGameTime() Event, assuming you want the 'actual stuff for AddItem and such' to run every Noon and not just once.

Link to comment
Share on other sites

Wouldn't it be better to run the TestName() function, to check when noon actually happens next? Because if I understand OnUpdateGameTime right, if I happen to be fast traveling when noon comes around, the event will fire when I get to where I'm going. Which means it might not actually be noon right then.
Link to comment
Share on other sites

One last question. :) I think I have it all sorted out as far as getting the basic script written (it's on the the chest and I don't have any compile errors) but it's not running in the game and I'm pretty sure I know why. The function and event are there, but there's nothing to call the function the first time to get things going. Is there an event for 'run this code (function) only this one time when it becomes enabled'? Once the function actually starts, it should keep itself going with no problems.

 

semi-edit: Just went back through the list of events. Would OnInit work?

 

edit: Yeah, got the script working except for the part where it actually puts the item into the chest. Now just have to figure out why the AddItem isn't working.

Edited by Meridias561
Link to comment
Share on other sites

Event OnUpdateGameTime()
if (HavenSiteMarker.IsEnabled())
	if (Embershard.IsCleared())
		chest.AddItem(OreIron, 1, true)
		Debug.Notification("Adding....?")
	endif

;actual stuff for AddItem and such goes here
endif
SetTimerForHavenKeepSupply()
endEvent

 

The event fires and I see the debug message, but the item doesn't show up in the chest like it's supposed to. (and I know I could have put the isenabled in the same if as the iscleared, but there's gonna be more stuff in there once I get this bit working)

Link to comment
Share on other sites

Yes, OnInit is the one to use, though AddItem doesn't work properly within an OnInit event, but I see you're not doing that there.

 

Have you declared OreIron as a property of the script?

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...