Counting days

Post » Mon Jun 18, 2012 9:52 pm

Hello,

I am in need of help. I am working on a script and most of it is finished and working, however, I want to add something every 24 ingame hours and stop adding something after a specific amount of days has passed. I have read all documentation on the subject, but I can't find a working way to count days. Is there anyone who can help me with this?

Thanks in advance!

Silverbird
User avatar
Dewayne Quattlebaum
 
Posts: 3529
Joined: Thu Aug 30, 2007 12:29 pm

Post » Mon Jun 18, 2012 2:02 pm

Can't you just use http://www.creationkit.com/GetCurrentGameTime_-_Utility?

Cipscis
User avatar
Red Bevinz
 
Posts: 3318
Joined: Thu Sep 20, 2007 7:25 am

Post » Mon Jun 18, 2012 10:47 am

I was looking at that one, but I had no idea how to implement it, the way I need it to. Also, it says on the wiki page that it gets messed up with fast travel, is this correct? If you could give me a general example on how to use that function to know how many days have passed and how to let the script do something when the days have passed, I would be very greatful.
User avatar
[ becca ]
 
Posts: 3514
Joined: Wed Jun 21, 2006 12:59 pm

Post » Mon Jun 18, 2012 10:53 am

Int lastTimeAdded;then somewhere in your scriptFunction AddItemAfter1Day ()    Float time = Utility.GetCurrentGameTime ()    If time - lastTimeAdded > 1        ;24 hours has passed        lastTimeAdded = time        ;...add your code here    EndIfEndFunction
User avatar
Crystal Clear
 
Posts: 3552
Joined: Wed Aug 09, 2006 4:42 am

Post » Mon Jun 18, 2012 6:53 pm

Thanks alot! But in this example, has one hour passed or one day? And how would I go about stopping the giving of an item after a certain amount of days?

And also, the object is disabled most of the time, does this block keep running even when the item is disabled?
User avatar
Emily Martell
 
Posts: 3469
Joined: Sun Dec 03, 2006 7:41 am

Post » Mon Jun 18, 2012 10:41 am

GetCurrentGameTime returns number of days. E.g. 4.5 is 4 days and 12 hours.
In regards to your other question, I don't really know.
I don't think OnUpdate () runs on Disabled references even if you call RegisterForUpdate () on it.
Best to have a free standing Quest that tracks the time and adds the item to the Actor.

EDIT:
Or, if the item will be unique (e.g. Excalibur or Melnibone's sword), then just make the item Persistent and attach a script to it's game world Reference instead of it's Base object.
I think this can be done, however, I'm not an Inventory modder, so I could be wrong.
User avatar
Budgie
 
Posts: 3518
Joined: Sat Oct 14, 2006 2:26 pm

Post » Mon Jun 18, 2012 10:33 am

Well, the items are not added to the actor, but to a container. This specific container has a script, where alot of things happen, but where I also want it to add items to the container everyday. But most of the time this container will be disabled, but would it work to have a quest running which handles the adding of items to the container, while the container is disabled?
User avatar
Lovingly
 
Posts: 3414
Joined: Fri Sep 15, 2006 6:36 am

Post » Mon Jun 18, 2012 12:32 pm

Actually, if he wants to get exactly 24 hours each time, he could easily use the Wait in a While loop, this would be preferred as the Wait releases control of the script for something else, rather than massively hitting the global variable and doing equations.

GuruSR.
User avatar
cassy
 
Posts: 3368
Joined: Mon Mar 05, 2007 12:57 am

Post » Mon Jun 18, 2012 5:01 pm

But still I have no clue how I can keep track of all days passed since the objects first use and stop adding items after a certain amount of days.
User avatar
T. tacks Rims
 
Posts: 3447
Joined: Wed Oct 10, 2007 10:35 am

Post » Mon Jun 18, 2012 7:28 pm

Okay, without help, I made a quest, set priority to 60, checked Start Game Enabled, added one quest stage 0 and added a script in the script tab, which looks like this:

 Scriptname MyAddGoldQuestScript extends QuestInt lastTimeAddedObjectReference Property MyContainerREF AutoMiscObject Property Gold001 AutoEvent OnInit()RegisterForUpdate(10.0)EndEventFunction AddItemAfter1Day()Float time = Utility.GetCurrentGameTime ()If time - lastTimeAdded > 1;24 hours has passedlastTimeAdded == timeMyContainerREF.Additem(Gold001, 1000);...add your code hereEndIfEndFunctionEvent OnUpdate()AddItemAfter1Day()EndEvent

Would this quest and script work or have I done something totally wrong? At least it compiled okay.
User avatar
KU Fint
 
Posts: 3402
Joined: Mon Dec 04, 2006 4:00 pm

Post » Mon Jun 18, 2012 1:52 pm

The logic looks good. However, don't take that statement as gospel in regards to it working in game.
From this point on, it'll need debugging, tweaking, etc... and so-on.

E.g. you may wish to add a limiter to the number of Gold in the chest.
I know in Oblivion, an item can only have a limited number of itself in a container.
After that limit, the item will exist in the container negatively - which showed positively in the game.
But the container was corrupted because of the negative amount in it.
I believe Int ranges from -65535 to 65535. When you add more after that max, it'll loop around and become negative.
Of course, this is just all supposition from previous experiences in Oblivion and in other programming frameworks.

So, best to add a limiter (e.g. If number of gold already in the chest + what you're adding > 10000...don't add anymore) now and pre-empt possible problems.
User avatar
DAVId Bryant
 
Posts: 3366
Joined: Wed Nov 14, 2007 11:41 pm


Return to V - Skyrim