gerg357 Posted August 11, 2016 Share Posted August 11, 2016 Im having some issues with game time.. and game days passed what im wanting to do is create a activator that when you click it.. it first checks to see if a time was set.. maybe using a global variable.. and if one wasnt set it sets that variable to current time.. basically this is what im trying to do click a activatorget game hour it was clicked and set a global variable as thatcheck for globalvariable let say on patrolif onpatrol =1subtract stored variable for when activator was clicked fromwhen you was set to on patrolif >= 8 hoursgive goldelse(means we aint on duty onpatrol == 0)we set on patrol and get current game hour set that as variableelse ir hours is <<8display message saying you havent been on patrol long enoughvariable i think this is about what im after but i dont think the time code is right can someone help me and explain what the function is and how it works in a code comment.. Scriptname GuardJobScript extends ObjectReferenceImport UtilityMessage Property worklonger AutoMessage Property dojob AutoMessage Property jobdone AutoGlobalVariable Property GameHour AutoGlobalVariable Property patrol AutoGlobalVariable Property starttime AutoGlobalVariable Property completedtime Auto Event OnActivate(ObjectReference akActionRef) completedtime.SetValue(GameHour.GetValue()) ;set completetime to current game hour if(Patrol.GetValue == 1) ; patrol variable is 1 ill set to 0 in ck so this would be second time they clicked activator completedtime.SetValue(starttime.Getvalue() - completedtime.GetValue());subtract completedtime from start time if(completedtime.GetValue() >= 8); if 8 hours or more has passed jobdone.Show();shows a message saying your patrol is over Game.GetPlayer().AddItem(gold001, 250);adds gold EndIf elseif(completedtime.GetValue() <= 8); 8 hours hasnt passed yet worklonger.Show(); message saying you havent worked enough hours. EndIf EndIf if(patrol.GetValue == 0);since patrol is gonna be 0 in ck this will be first time they have used script so this should run first patrol.SetValue(1); set our patrol to 1 so now we are on patrol starttime.SetValue(GameHour.GetValue()); set starttime to current game hour dojob.Show();message saying patrol has started EndIf endEvent Link to comment Share on other sites More sharing options...
cdcooley Posted August 12, 2016 Share Posted August 12, 2016 Assuming there's just one activator, skip the global variable and just let a variable in the activator script keep track. Scriptname GuardJobScript extends ObjectReference Message Property DoJobMSG Auto Message Property JobDoneMSG Auto Message Property WorkLongerMSG Auto MiscObject Property Gold001 Auto float FinishTime ; the only status variable needed Event OnActivate(ObjectReference akActionRef) if akActionRef != Game.GetPlayer() ; do not let other NPCs trigger this return endif if FinishTime == 0.0 ; starting a shift FinishTime = 8.0 + Utility.GetCurrentGameTime() * 24.0 ; converts days to hours DoJobMSG.Show(8.0) ; JobTime value can be shown in message. elseif Utility.GetCurrentGameTime() * 24.0 >= FinishTime ; have worked long enough FinishTime = 0.0 ; reset for next time JobDoneMSG.Show() akActionRef.AddItem(Gold001, 250) ;adds gold else ; not done yet! The message can show how many hours are left WorkLongerMSG.Show(FinishTime - Utility.GetCurrentGameTime() * 24.0) endif endEvent Event Personally I would add the player to an alias when the job starts that then monitors for location change, sleeping, waiting, etc. to make sure the player actually does the job. If anything goes wrong I would then have the alias script force the player back out. Then this script could be used to decide if payment was actually appropriate: Scriptname GuardJobScript extends ObjectReference Message Property GuardJobStartMSG Auto Message Property GuardJobSuccessMSG Auto Message Property GuardJobFailureMSG Auto Message Property GuardJobWorkLongerMSG Auto ReferenceAlias Property GuardJobAlias Auto MiscObject Property Gold001 Auto float FinishTime ; the only status variable needed Event OnActivate(ObjectReference akActionRef) if akActionRef != Game.GetPlayer() ; do not let other NPCs trigger this return endif if FinishTime == 0.0 ; starting a shift FinishTime = 8.0 + Utility.GetCurrentGameTime() * 24.0 ; converts days to hours GuardJobStartMSG.Show(8.0) ; JobTime value can be shown in message. GuardJobAlias.ForceRefTo(akActionRef) elseif GuardJobAlias.GetReference() != akActionRef ; failed the job assignment! FinishTime = 0.0 GuardJobFailureMSG.Show() ; no rewards for those who abandon their duties ; add any other consequences here! elseif Utility.GetCurrentGameTime() * 24.0 >= FinishTime ; have worked long enough FinishTime = 0.0 ; reset for next time GuardJobSuccessMSG.Show() akActionRef.AddItem(Gold001, 250) ;adds gold else ; not done yet! The message can show how many hours are left GuardJobWorkLongerMSG.Show(FinishTime - Utility.GetCurrentGameTime() * 24.0) endif endEvent Event Link to comment Share on other sites More sharing options...
gerg357 Posted August 12, 2016 Author Share Posted August 12, 2016 i Assuming there's just one activator, skip the global variable and just let a variable in the activator script keep track. Scriptname GuardJobScript extends ObjectReference Message Property DoJobMSG Auto Message Property JobDoneMSG Auto Message Property WorkLongerMSG Auto MiscObject Property Gold001 Auto float FinishTime ; the only status variable needed Event OnActivate(ObjectReference akActionRef) if akActionRef != Game.GetPlayer() ; do not let other NPCs trigger this return endif if FinishTime == 0.0 ; starting a shift FinishTime = 8.0 + Utility.GetCurrentGameTime() * 24.0 ; converts days to hours DoJobMSG.Show(8.0) ; JobTime value can be shown in message. elseif Utility.GetCurrentGameTime() * 24.0 >= FinishTime ; have worked long enough FinishTime = 0.0 ; reset for next time JobDoneMSG.Show() akActionRef.AddItem(Gold001, 250) ;adds gold else ; not done yet! The message can show how many hours are left WorkLongerMSG.Show(FinishTime - Utility.GetCurrentGameTime() * 24.0) endif endEvent Event Personally I would add the player to an alias when the job starts that then monitors for location change, sleeping, waiting, etc. to make sure the player actually does the job. If anything goes wrong I would then have the alias script force the player back out. Then this script could be used to decide if payment was actually appropriate: Scriptname GuardJobScript extends ObjectReference Message Property GuardJobStartMSG Auto Message Property GuardJobSuccessMSG Auto Message Property GuardJobFailureMSG Auto Message Property GuardJobWorkLongerMSG Auto ReferenceAlias Property GuardJobAlias Auto MiscObject Property Gold001 Auto float FinishTime ; the only status variable needed Event OnActivate(ObjectReference akActionRef) if akActionRef != Game.GetPlayer() ; do not let other NPCs trigger this return endif if FinishTime == 0.0 ; starting a shift FinishTime = 8.0 + Utility.GetCurrentGameTime() * 24.0 ; converts days to hours GuardJobStartMSG.Show(8.0) ; JobTime value can be shown in message. GuardJobAlias.ForceRefTo(akActionRef) elseif GuardJobAlias.GetReference() != akActionRef ; failed the job assignment! FinishTime = 0.0 GuardJobFailureMSG.Show() ; no rewards for those who abandon their duties ; add any other consequences here! elseif Utility.GetCurrentGameTime() * 24.0 >= FinishTime ; have worked long enough FinishTime = 0.0 ; reset for next time GuardJobSuccessMSG.Show() akActionRef.AddItem(Gold001, 250) ;adds gold else ; not done yet! The message can show how many hours are left GuardJobWorkLongerMSG.Show(FinishTime - Utility.GetCurrentGameTime() * 24.0) endif endEvent Event FinishTime == 0.0 guess that means 0 hours???FinishTime = 8.0 + Utility.GetCurrentGameTime() * 24.0 ; converts days to hoursi understand that line partially im guessing if finish time is 0 then it becomes 8 hours plus what the game time is currently added together??? kinda lost on that.. GuardJobAlias.ForceRefTo(akActionRef) elseif GuardJobAlias.GetReference() != akActionRef ; failed the job assignment!that line of code im not sure what it means Utility.GetCurrentGameTime() * 24.0 >= FinishTimeto me it looks like if current game time is greater or equal to finish time?After looking up at the finishtime variable i thnk i get it.. FinishTime = 8.0 + Utility.GetCurrentGameTime() * 24.0this line is setting finishtime to 8 hours plus adding the current game time hour to it as well?like if it is 4:12 pm when i use this in game finish time is now 12:12 am??? GuardJobWorkLongerMSG.Show(FinishTime - Utility.GetCurrentGameTime() * 24.0)if im using a msg in ck for this what would i need to put in ck? anything leave it blank orhow does the variables get used with ck msg... sorry for all the questions but im trying to learn why the things you did to the script are there so i can learn it myself and not beg people to do it for me.. i like to learn on my own so ive managed to piece together things and make it work by reading and looking at some source Link to comment Share on other sites More sharing options...
cdcooley Posted August 12, 2016 Share Posted August 12, 2016 Yes, I think you've already figured it out. The logic is that FinishTime should be the time the job will be complete or 0 if the job isn't started. It starts at 0 by default so the first time you activate the container the action is to calculate when the job will be complete and store it. (And yes, that means if you start late one day your shift might end in the early morning of the next.) In the basic version of the script there are really only three possibilities when you activate the object.FinishTime is 0 so you're just starting. The current time is after the job FinishTime so you're done. You still have some time left.The advanced version adds the idea of an Alias you can force the player into. That alias would then have a script that detects if the player leaves the area or does anything else you would consider a violation of being "on duty." If it detects something it doesn't like it can clear the alias. Then when the player comes back and activates the object there's an extra possibility. If the alias got cleared early then the player broke your rules and won't get the reward. As for the messages, the formatting options are described on the Show page on the Wiki. The short version is that if you put a message like "You still have %.1f hours of duty left." as the message then the %.1f will be replaced by the hours passed in from the script (with the minutes expressed as tenths of an hour). That formatting isn't ideal, but it should work. If you wanted something fancier like hours and minutes the message would be "You still have %.0f hours and %.0f minutes of duty left." and that last block of code would be: else ; not done yet! The message can show how many hours are left float hoursLeft = FinishTime - Utility.GetCurrentGameTime() * 24.0 float minutesLeft = (hoursLeft - (hoursLeft as int)) * 60.0 GuardJobWorkLongerMSG.Show(hoursLeft, minutesLeft) endif Link to comment Share on other sites More sharing options...
gerg357 Posted August 12, 2016 Author Share Posted August 12, 2016 Hey thanks alot for the info u rock... alias has me intrigued I'm trying to find some info on it now.. you are a huge help Link to comment Share on other sites More sharing options...
Recommended Posts