Need a little mathematicalscripting help

Post » Mon Dec 09, 2013 12:57 am

Okay, so I should preface by saying that I need to "do stuff" after the player has exited jail. To detect if the player has served their sentence I have to use the fact that 1 in-game day passes (register for sleep doesn't work). The problem is I need to also track whether it goes past midnight while the player is still in jail.

Here are my scripts so far:

Spoiler


Scriptname spike_cs_PrisonSleep Extends QuestReferenceAlias Property Spike_cs_PlayerAlias Auto ;Player alias - used to register for update game timeInt Property CrimeGold Auto Hidden ;Will store player bounty before arrestEvent OnStoryJail(ObjectReference akGuard, Form akCrimeGroup, Location akLocation, Int aiCrimeGold)    debug.Notification("spike_cs - the Jail event has triggered")        ;Used to store game time each hour on player alias script then compare on location change    Spike_cs_PlayerAlias.RegisterForUpdateGameTime(1)    CrimeGold = aiCrimeGold    EndEvent



Spoiler


Scriptname spike_cs_PlayerAliasScript Extends ReferenceAliasReferenceAlias Property Spike_cs_PlayerAlias Auto ;Player alias - needed to apply effects to playerQuest Property Spike_cs_JailQuest Auto ;Jail quest - needed to stop the quest after player has served sentenceInt Property GameTime Auto Hidden ;Tracks hours passedEvent OnUpdateGameTime()        GameTime = utility.GetCurrentGameTime() as Int    debug.Notification("spike_cs - " + GameTime + " in-game hours have passed")EndEventEvent OnLocationChange(Location akOldLoc, Location akNewLoc)    Spike_cs_PlayerAlias.UnregisterForUpdateGameTime()    if (utility.GetCurrentGameTime() as Int) > GameTime ;Player has served sentence            ;Retrieve player's bounty before sent to jail        int playerbounty = (Spike_cs_JailQuest as spike_cs_PrisonSleep).CrimeGold        debug.Notification("spike_cs - Player served sentence, player bounty was " + playerbounty)        else ;Player has escaped            debug.Notification("spike_cs - Player escaped jail")        endif    Spike_cs_JailQuest.Stop()    EndEvent


As you can see I've set the player alias to register for update every 1 in-game hour. This allows me to keep track of what day it was while the player was still in jail then compare that against the day it is when the player exits the cell (in theory that means the value will be 1 greater only if they served their sentence).

The issue is if the player is arrested within the time period 2300-2400, the day will roll over but the script won't realize this until a full hour has passed since the player was arrested. Which means the maximum possibly period in which the script can't detect a day is 59 in-game minutes. There are various solutions running through my head for this, but I'm just not in the state of mind to follow along with them right now.
User avatar
Rudy Paint fingers
 
Posts: 3416
Joined: Sun Nov 11, 2007 1:52 am

Post » Mon Dec 09, 2013 12:56 pm

Ignore the

debug.Notification("spike_cs - " + GameTime + " in-game hours have passed")

I was experimenting with converting the days past to hours and then adding on each hour that passed in jail and forgot to change that back.

User avatar
Prisca Lacour
 
Posts: 3375
Joined: Thu Mar 15, 2007 9:25 am

Post » Mon Dec 09, 2013 8:43 am

Heh, once again it seems the solution is to forget all about the problem until your brain just figures it out. I've just came to the conclusion that it's not possible to solve this using maths since I can only perform things each hour interval. Instead I'll need to use a quest with the Escape jail event that tells simply tells the script if the player escaped

User avatar
Catherine N
 
Posts: 3407
Joined: Sat Jan 27, 2007 9:58 pm

Post » Mon Dec 09, 2013 12:33 pm

While I know little about Papyrus, I think I may be able to help with the logic.

When you set the script to run every hour, you'll want to toss that into a conditional. Before you do that, you'll want to get the current game time and check to see if it's between 2300 and 2400.

From my searches, GetCurrentGameTime returns a float telling you how many days have passed. So you multiply that by 24 to get the hours. You'll want this value in minutes to fully check the time, so you multiply this by 60. 2300 is 1380 minutes, 2400 is 1440 minutes.

For your conditional, you check to see if the current time is between those two values. If it is, you make it so that the script runs the check at midnight. So 24 - (minutes / 60). The resulting decimal is what you'd use as your delay.

If it's not between those times, you would set it to run as you have it.

Edit:

So that was useless. At least it gave me something to do. :tongue:
User avatar
Joe Alvarado
 
Posts: 3467
Joined: Sat Nov 24, 2007 11:13 pm

Post » Mon Dec 09, 2013 3:49 pm

Closed per OP request.

User avatar
Marie
 
Posts: 3405
Joined: Thu Jun 29, 2006 12:05 am


Return to V - Skyrim