Hey again everyone,
I'm trying to track how many times the player helps out at the lumber mill. Two simple things count as helping: Loading a log onto the sawmill, and pulling the lever to send them through the blade.
However, as the sawmill object is a heavily scripted 'resource' object, I had my work cut out for me. So, I combined the ResourceObjectScript and ResourceObjectSawmillScript into one custom script, and then cut out all the extra garble about sabotage, repairing, etc. So, I have two questions:
1. Can this script be simplified any more? It was around 350 lines when I combined the two, but I've managed to cut out the excess stuff and I'm down to a mere 106 lines, but I'm not an expert on a lot of the stuff used here (Like states) so I was wondering if I could remove/combine/optimize anything else here. Sorry for the lack of indentation, pasting into the browser doesn't seem to carry that over. I'll edit this post and add it in to the best of my abilities so you guys can read it more easily. Also, I just tested in game and this script seems to work just fine with my modifications thus far.
Spoiler Scriptname FSKR_SawmillScript extends ObjectReference Message property BusyMessage AutoMessage property ReadyMessage AutoObjectReference Property Worker Auto ;Hidden Propertiesint Property ResourceState Auto Hidden Conditionalint property waiting = 0 Auto Hiddenint property busy = 1 Auto Hiddenint property ready = 2 Auto Hiddenstring property strWaiting = "waiting" Auto Hiddenstring property strBusy = "busy" Auto Hiddenstring property strReady = "ready" Auto HiddenAuto State waitingEndStateState readyEndStateState busyEndStatefunction ChangeState(int newState)if newState == waitinggotoState(strWaiting)ResourceState = waitingelseif newState == busygotoState(strBusy)ResourceState = busyelseif newState == readygotoState(strReady)ResourceState = readyendifActor workerActor = (Worker as Actor)if workerActorworkerActor.EvaluatePackage()endifendFunctionState ready; log is loaded into tray, waiting to be cutEvent onActivate ( objectReference triggerRef ); if activated by an actor, do nothing special. If activated by non-actor, assume trying to sawActor triggerActor = triggerRef as Actorif triggerActor == None; debug.trace(self + "activated by something other than player"); saw the log:ChangeState(busy)work()ChangeState(waiting)elseif triggerActor == Game.GetPlayer(); show READY messageReadyMessage.Show()endifEndEventEndStateState busyEvent onActivate ( objectReference triggerRef ); if activated by an actor, do nothing special. If activated by non-actor, assume trying to sawif triggerRef == Game.GetPlayer(); show BUSY messageBusyMessage.Show()endifEndEventendStateFunction Work()playAnimationAndWait("MillLogChuteCut", "MillLogIdleReset")EndFunctionEvent OnLoad()RegisterForAnimationEvent(self, "MillLogChuteIdle") ; log is loaded, ready to cutRegisterForAnimationEvent(self, "MillLogIdleReset") ; log cutting animation completeRegisterForAnimationEvent(self, "MillLogPileLoadStart") ; log loading animation startedendEventEvent OnUnload()UnRegisterForAnimationEvent(self, "MillLogChuteIdle")UnRegisterForAnimationEvent(self, "MillLogIdleReset")UnRegisterForAnimationEvent(self, "MillLogPileLoadStart") endEventEvent OnAnimationEvent(ObjectReference akSource, string asEventName)if asEventName == "MillLogPileLoadStart"ChangeState(busy)elseif asEventName == "MillLogChuteIdle"ChangeState(ready)elseif asEventName == "MillLogIdleReset"ChangeState(waiting)endifEndEvent
2. How can I add my own script fragments into this to increase a global variable by 1 every time the player does one of the two aforementioned actions? I'm using a global to track their 'help' so they can collect pay from the lumberjack (Thus resetting the global to 0). There doesn't seem to be any event for loading the log in originally, and activation is done from a lever to put the saw through the mill. Do I need to put a script on the lever that checks the mill's state, then adjusts the global accordingly? And what about tracking when the player loads a log in?
I appreciate any help!
Thanks,
Alexander J. Velicky