Rizalgar Posted June 24, 2019 Share Posted June 24, 2019 So I'm basically writing a furniture mining script from scratch, and I can't seem to figure out how they got the strikes to count for each hit during the animation. Here's the script, point me to my ignorance, as usual. -- Note -- I tried using RegisterForUpdate(X.X) Then doing the Mine function inside of OnUpdate(), but couldn't get the update to cancel once the furniture was left. Any help is appreciated. The function in question is Mine() Scriptname RS_Mining_Ore extends ObjectReference {Mining script} FormList Property RS_FL_Pickaxe Auto FormList Property RS_FL_Toolbag Auto Activator Property RS_Rock_Depleted Auto ObjectReference ObjSelf ObjectReference Property LastRef Auto Hidden GlobalVariable Property RS_Player_cInventorySize Auto GlobalVariable Property RS_SV_MiningLvl Auto GlobalVariable Property RS_GV_mCounter Auto MiscObject Property Ore Auto Int Property RLvl Auto Float Property Exp Auto String Property Name Auto Weapon Property RS_Pickaxe_Bronze Auto Event OnActivate(ObjectReference Player) If Player == Game.GetPlayer() If RS_SV_MiningLvl.GetValue() < RLvl Debug.MessageBox("You lack the required level of " + RLvl + " to mine this ore.") ElseIf RS_FL_Pickaxe.HasForm(Player) Debug.MessageBox("You do not have a pickaxe to mine with.") Else ObjSelf = GetLinkedRef() ObjSelf.Activate(Player) Mine() EndIf EndIf EndEvent Function Mine() If RS_Player_cInventorySize.GetValue() < 28 If RS_GV_mCounter.GetValue() <= 0 Float mod = GetToolStrength() Int Delay = (20 - ((RS_SV_MiningLvl.GetValue()) / 10) - Mod + RLvl) as Int Int Chance = Utility.RandomInt(0, Delay) RS_GV_mCounter.SetValue(Chance) Else Int Chance = RS_GV_mCounter.GetValue() as Int Chance = (Chance - 1) If Chance > 0 RS_GV_mCounter.SetValue(Chance) ElseIf Chance <= 0 RS_GV_mCounter.SetValue(0) Game.GetPlayer().AddItem(Ore, 1) rsFrameworkMain.XPS("mining", Exp) EndIf EndIf Else Debug.MessageBox("You have run out of inventory slots. Consider depositing your ore into your ore bank.") EndIf EndFunction Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked) If RS_Player_cInventorySize.GetValue() < 28 If RS_GV_mCounter.GetValue() <= 0 Float mod = GetToolStrength() Int Delay = (20 - ((RS_SV_MiningLvl.GetValue()) / 10) - Mod + RLvl) as Int Int Chance = Utility.RandomInt(0, Delay) RS_GV_mCounter.SetValue(Chance) Else Int Chance = RS_GV_mCounter.GetValue() as Int Chance = (Chance - 1) If Chance > 0 RS_GV_mCounter.SetValue(Chance) ElseIf Chance <= 0 RS_GV_mCounter.SetValue(0) Game.GetPlayer().AddItem(Ore, 1) rsFrameworkMain.XPS("mining", Exp) EndIf EndIf Else Debug.MessageBox("You have run out of inventory slots. Consider depositing your ore into your ore bank.") EndIf EndEvent Float Function GetToolStrength() If RS_FL_Toolbag.HasForm(RS_Pickaxe_Bronze) Return 0.0 EndIf EndFunction Link to comment Share on other sites More sharing options...
IsharaMeradin Posted June 25, 2019 Share Posted June 25, 2019 The ore vein activator which holds MineOreScript is linked with a furniture marker which determines how the animation plays out (i.e. floor, wall, etc). These pickaxe markers hold the script MineOreFurnitureScript. As near as I can tell the MineOreFurnitureScript handles the entering and exiting of the ore vein. Between the two scripts there are a lot of Activate calls. I'm not sure if the player actually activates the ore vein or if they activate the furniture. But it seems that with all the heavy conditioning going on that it may bounce between the two. Thus one gets activated and the other gets activated and then the first again, repeating until the ResourceCountTotal on MineOreScript reaches zero that the MineOreFurnitureScript is told to go to the depleted state. Not sure how that actually helps... Link to comment Share on other sites More sharing options...
Rizalgar Posted June 27, 2019 Author Share Posted June 27, 2019 That actually helps quite a bit. So they more or less bounce back and forth between activations. So I need to modify my script, as well as create a new furniture and script it with returns to the activator that calls back to the furniture, rinse and repeat. Kinda. Something like that. I'm sure I can come up with something, if not, you'll see me again here. Link to comment Share on other sites More sharing options...
Rizalgar Posted June 27, 2019 Author Share Posted June 27, 2019 (edited) Okay so I managed to get it linked, but now every time I call the Mine() function, it stops the animation. Any ideas? Here's the updated script (for a different mod I'm working on lol) as well as the new Furniture script. Activator script Scriptname F_Script_MiningActivator extends ObjectReference {Mian script to send to furniture} GlobalVariable Property F_Skill_Mining Auto GlobalVariable Property F_GV_mCounter Auto Formlist Property F_FL_Pickaxe Auto Formlist Property F_FL_Toolbag Auto ObjectReference Property ObjSelf Auto Hidden ObjectReference Property LastRef Auto Hidden MiscObject Property Ore Auto Int Property rLvl Auto Float Property Exp Auto String Property rockName Auto Weapon Property F_Pickaxe Auto F_Script_MiningFurniture Property Furn Auto Hidden Event OnActivate(ObjectReference actRef) If actRef as Actor If actRef == Game.GetPlayer() If F_Skill_Mining.GetValue() < rLvl Debug.Messagebox("You lack the required level of " + rLvl as Int + " to mine " + rockName + ".") ElseIf F_FL_Toolbag.HasForm(F_Pickaxe) == False Debug.Messagebox("Your toolbag doesn't have a pickaxe in it!") Else If getLinkedRef() Furn = getLinkedRef() as F_Script_MiningFurniture Furn.lastRef = ObjSelf getLinkedRef().activate(actRef) EndIf EndIf Else If getLinkedRef() getLinkedRef().Activate(actRef) EndIf EndIf ElseIf actRef == getLinkedRef() Mine() EndIf EndEvent Function Mine() Debug.Notification("Mining") If F_GV_mCounter.GetValue() <= 0 Int Delay = (20 - ((F_Skill_Mining.GetValue()) / 10) + rLvl) as Int Int Chance = Utility.RandomInt(0, Delay) F_GV_mCounter.SetValue(Chance) Else Int Chance = F_GV_mCounter.GetValue() as Int Chance = (Chance - 1) If Chance > 0 F_GV_mCounter.SetValue(Chance) ElseIf Chance <= 0 F_GV_mCounter.SetValue(0) Game.GetPlayer().AddItem(Ore, 1) F_Script_Framework_Level.XPS("mining", Exp) EndIf EndIf EndFunction The furniture script Scriptname F_Script_MiningFurniture extends ObjectReference {Mining script to send back to activator} ObjectReference Property lastRef Auto Hidden ObjectReference Property ObjSelf Auto Hidden Bool Property isRegisteredForEvents = False Auto Hidden bool property playerIsLeavingFurniture = false auto hidden bool property playerIsInFurniture = false auto hidden idle property PickaxeExit auto bool property canBeActivated = true auto hidden F_Script_MiningActivator Property Mine Auto Hidden Event OnLoad() ObjSelf = Self as ObjectReference EndEvent Event OnUnload() UnregisterForEvents() EndEvent Event OnAnimationEvent(ObjectReference akSource, string asEventName) If asEventName == "AddToInventory" lastRef.activate(ObjSelf) EndIf If asEventName == "IdleFurnitureExit" || asEventName == "IdlePickaxeExit" || asEventName == "IdlePickaxeFloorExit" || asEventName == "IdlePickaxeTableExit" UnregisterForEvents() EndIf EndEvent ;||State|| Auto State Normal Event OnBeginState() canBeActivated = True EndEvent Event OnActivate(ObjectReference actRef) If canBeActivated GoToState("Busy") canBeActivated = False If actRef == Game.GetPlayer() && !IsFurnitureInUse() RegisterForEvents() Activate(actRef, true) EndIf EndIf canBeActivated = True EndEvent EndState State Busy Event OnBeginState() canBeActivated = True EndEvent Event OnActivate(ObjectReference actRef) If canBeActivated && IsFurnitureInUse() canBeActivated = False If isRegisteredForEvents If actRef == lastRef PlayerIsLeavingFurniture = True GoToState("Resetting") ElseIf actRef == Game.GetPlayer() PlayerIsLeavingFurniture = True GoToState("Resetting") EndIf ElseIf actRef == Game.GetPlayer() Activate(Game.GetPlayer(), True) EndIf EndIf canBeActivated = True EndEvent EndState state reseting event onBeginState() if playerIsLeavingFurniture playerIsLeavingFurniture = false Game.GetPlayer().PlayIdle(PickaxeExit) else UnregisterForEvents() endif endEvent endState Function RegisterForEvents() If !isRegisteredForEvents isRegisteredForEvents = True RegisterForAnimationEvent(Game.GetPlayer(), "AddToInventory") RegisterForAnimationEvent(Game.GetPlayer(), "IdlePickaxeExit") RegisterForAnimationEvent(Game.GetPlayer(), "IdlePickaxeFloorExit") RegisterForAnimationEvent(Game.GetPlayer(), "IdlePickaxeTableExit") RegisterForAnimationEvent(Game.GetPlayer(), "IdleFurnitureExit") EndIf EndFunction function UnregisterForEvents() If isRegisteredForEvents isRegisteredForEvents = false UnRegisterForAnimationEvent(Game.GetPlayer(), "AddToInventory") UnRegisterForAnimationEvent(Game.GetPlayer(), "IdlePickaxeExit") UnRegisterForAnimationEvent(Game.GetPlayer(), "IdlePickaxeFloorExit") UnRegisterForAnimationEvent(Game.GetPlayer(), "IdlePickaxeTableExit") UnRegisterForAnimationEvent(Game.GetPlayer(), "IdleFurnitureExit") EndIf EndFunction Edit - Updated furniture script. The mine() function is never called at all. I'm at a loss. Edit -- Threw debugs every where, the Furniture reference isn't being returned to the activator. I have no idea what to do next /sigh Edited June 27, 2019 by Rizalgar Link to comment Share on other sites More sharing options...
Rizalgar Posted June 28, 2019 Author Share Posted June 28, 2019 (edited) Here is the trace log if it helps. IDK why it is returning None. [ (0602F23B)].f_script_miningfurniture.OnAnimationEvent() - "F_Script_MiningFurniture.psc" Line 31 [06/27/2019 - 08:39:12PM] warning: Assigning None to a non-object variable named "::temp1" Edit - This whole time it's just because I'm a damn moron and forgot to link ObjSelf to itself in the activator script. GFG Riz. Edited June 28, 2019 by Rizalgar Link to comment Share on other sites More sharing options...
IsharaMeradin Posted June 28, 2019 Share Posted June 28, 2019 So it is working then? Link to comment Share on other sites More sharing options...
Rizalgar Posted June 28, 2019 Author Share Posted June 28, 2019 So it is working then? Mostly. Now when I leave the activator, I can't reenter it. Dunno what's up with that. Sigh. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted June 28, 2019 Share Posted June 28, 2019 That is the way ore veins always worked. Once mined and depleted it cannot be re-entered until cell reset. Unless you mean that you've exited before it was depleted and cannot re-enter. In that case, no idea. I'm not too sure why you wanted to completely rewrite the scripts. There might be a way to modify the original scripts to do what you want. Even if they're renamed so as to not overwrite the stock scripts you'll still have a working process without having to recreate the wheel as it were. Link to comment Share on other sites More sharing options...
Rizalgar Posted June 28, 2019 Author Share Posted June 28, 2019 (edited) Hmm touche. I wanted to write them new because it uses a math formula for chance to mine as well as being an endless resource. It also has a skill requirement and inventory check requirement before gathering. I'll check when I get off work and see if I can maybe modify the original to get what I want.Edit -- So I debugged my script some more and it's not returning to the Normal state despite being explicitly told to after modifying it.Edit --- Sigh. It's because I spelled "Resetting" wrong and I once again prove to myself how much of a dummy I can be. For Googlers - A working custom activator and furniture script The activator script - Replace function with what you want your activator to do. Scriptname F_Script_MiningActivator extends ObjectReference {Mian script to send to furniture} GlobalVariable Property F_Skill_Mining Auto GlobalVariable Property F_GV_mCounter Auto Formlist Property F_FL_Pickaxe Auto Formlist Property F_FL_Toolbag Auto ObjectReference Property ObjSelf Auto Hidden ObjectReference Property LastRef Auto Hidden MiscObject Property Ore Auto Int Property rLvl Auto Float Property Exp Auto String Property rockName Auto Weapon Property F_Pickaxe Auto F_Script_MiningFurniture Property Furn Auto Hidden Event OnCellAttach() BlockActivation() SetNoFavorAllowed() objSelf = Self as ObjectReference EndEvent Event OnActivate(ObjectReference actRef) If actRef as Actor If actRef == Game.GetPlayer() If F_Skill_Mining.GetValue() < rLvl Debug.Messagebox("You lack the required level of " + rLvl as Int + " to mine " + rockName + ".") ElseIf F_FL_Toolbag.HasForm(F_Pickaxe) == False Debug.Messagebox("Your toolbag doesn't have a pickaxe in it!") Else If getLinkedRef() Furn = getLinkedRef() as F_Script_MiningFurniture Furn.lastRef = ObjSelf getLinkedRef().activate(actRef) EndIf EndIf Else If getLinkedRef() getLinkedRef().Activate(actRef) EndIf EndIf ElseIf actRef == getLinkedRef() Mine() EndIf EndEvent Function Mine() If F_GV_mCounter.GetValue() <= 0 Int Delay = (20 - ((F_Skill_Mining.GetValue()) / 10) + rLvl) as Int Int Chance = Utility.RandomInt(0, Delay) F_GV_mCounter.SetValue(Chance) Else Int Chance = F_GV_mCounter.GetValue() as Int Chance = (Chance - 1) If Chance > 0 F_GV_mCounter.SetValue(Chance) ElseIf Chance <= 0 Debug.Notification("You mine some " + rockName + " ore.") F_GV_mCounter.SetValue(0) Game.GetPlayer().AddItem(Ore, 1) F_Script_Framework_Level.XPS("mining", Exp) EndIf EndIf EndFunction Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked) If akAggressor == Game.GetPlayer() If F_Skill_Mining.GetValue() < rLvl Debug.Messagebox("You lack the required level of " + rLvl as Int + " to mine " + rockName + ".") ElseIf akSource != F_FL_Pickaxe Debug.Messagebox("Try using a pickaxe instead!") Else Mine() EndIf EndIf Self.Reset() EndEvent The furniture script - Keep as is. DO NOT MODIFY unless you have found a way to improve on it. Scriptname F_Script_MiningFurniture extends ObjectReference {Mining script to send back to activator} ObjectReference Property lastRef Auto Hidden ObjectReference Property ObjSelf Auto Hidden Bool Property isRegisteredForEvents = False Auto Hidden bool property playerIsLeavingFurniture = false auto hidden bool property playerIsInFurniture = false auto hidden idle property PickaxeExit auto bool property canBeActivated = true auto hidden F_Script_MiningActivator Property Mine Auto Hidden Event OnLoad() BlockActivation(True) ObjSelf = Self as ObjectReference EndEvent Event OnUnload() UnregisterForEvents() EndEvent Event OnAnimationEvent(ObjectReference akSource, string asEventName) If asEventName == "AddToInventory" lastRef.activate(ObjSelf) EndIf If asEventName == "IdleFurnitureExit" || asEventName == "IdlePickaxeExit" || asEventName == "IdlePickaxeFloorExit" || asEventName == "IdlePickaxeTableExit" UnregisterForEvents() EndIf EndEvent ;||State|| Auto State Normal Event OnBeginState() canBeActivated = True EndEvent Event OnActivate(ObjectReference actRef) If canBeActivated GoToState("Busy") canBeActivated = False If actRef == Game.GetPlayer() && !IsFurnitureInUse() RegisterForEvents() Activate(actRef, true) EndIf EndIf canBeActivated = True EndEvent EndState State Busy Event OnBeginState() canBeActivated = True EndEvent Event OnActivate(ObjectReference actRef) If canBeActivated && IsFurnitureInUse() canBeActivated = False If isRegisteredForEvents If actRef == lastRef PlayerIsLeavingFurniture = True GoToState("Resetting") ElseIf actRef == Game.GetPlayer() PlayerIsLeavingFurniture = True GoToState("Resetting") EndIf ElseIf actRef == Game.GetPlayer() Activate(Game.GetPlayer(), True) EndIf EndIf canBeActivated = True EndEvent EndState state Resetting event onBeginState() if playerIsLeavingFurniture playerIsLeavingFurniture = false Game.GetPlayer().PlayIdle(PickaxeExit) GoToState("Normal") canBeActivated = True else UnregisterForEvents() endif endEvent endState Function RegisterForEvents() If !isRegisteredForEvents isRegisteredForEvents = True RegisterForAnimationEvent(Game.GetPlayer(), "AddToInventory") RegisterForAnimationEvent(Game.GetPlayer(), "IdlePickaxeExit") RegisterForAnimationEvent(Game.GetPlayer(), "IdlePickaxeFloorExit") RegisterForAnimationEvent(Game.GetPlayer(), "IdlePickaxeTableExit") RegisterForAnimationEvent(Game.GetPlayer(), "IdleFurnitureExit") EndIf EndFunction function UnregisterForEvents() If isRegisteredForEvents isRegisteredForEvents = false UnRegisterForAnimationEvent(Game.GetPlayer(), "AddToInventory") UnRegisterForAnimationEvent(Game.GetPlayer(), "IdlePickaxeExit") UnRegisterForAnimationEvent(Game.GetPlayer(), "IdlePickaxeFloorExit") UnRegisterForAnimationEvent(Game.GetPlayer(), "IdlePickaxeTableExit") UnRegisterForAnimationEvent(Game.GetPlayer(), "IdleFurnitureExit") EndIf EndFunction Edited June 28, 2019 by Rizalgar Link to comment Share on other sites More sharing options...
ReDragon2013 Posted July 5, 2019 Share Posted July 5, 2019 DO NOT MODIFY unless you have found a way to improve on it. F_Script_MiningActivator Scriptname F_Script_MiningActivator extends ObjectReference {Main script to send to furniture} ; https://forums.nexusmods.com/index.php?/topic/7762863-need-help-for-a-repeating-function/ ;F_Script_MiningFurniture PROPERTY Furn auto Hidden ; UnUSED by now GlobalVariable PROPERTY F_Skill_Mining auto GlobalVariable PROPERTY F_GV_mCounter auto Formlist PROPERTY F_FL_Pickaxe auto Formlist PROPERTY F_FL_Toolbag auto Weapon PROPERTY F_Pickaxe auto MiscObject PROPERTY Ore auto String PROPERTY rockName auto Float PROPERTY Exp auto Int PROPERTY rLvl auto ;ObjectReference PROPERTY LastRef auto Hidden ; UnUSED by default ;ObjectReference PROPERTY ObjSelf auto Hidden ; UnUSED by now ; -- EVENTs -- based on vanilla script "MineOreScript.psc" EVENT OnCellLoad() self.BlockActivation() self.SetNoFavorAllowed() IF self.GetLinkedRef() RETURN ; - STOP - ENDIF ;--------------------- ;;; Debug.Trace(" OnCellLoad() - self does not have a linkedRef, ore will be depleted. " +self) ;depleteOreDueToFailure() self.DamageObject(50) ; Damages this object, which may fire off OnDestructionStageChanged() events. self.SetDestroyed(TRUE) ENDEVENT EVENT OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, Bool b1, Bool b2, Bool b3, Bool b4) IF (akAggressor == Game.GetPlayer() as ObjectReference) ELSE RETURN ; - STOP - not the player, hit by someone else ENDIF ;--------------------- IF F_FL_Pickaxe.HasForm(akSource) ELSE Debug.Messagebox("Try using a pickaxe instead!") RETURN ; - STOP - not a pickaxe ENDIF ;--------------------- IF myF_SkillReady() myF_Mining(self.GetLinkedRef()) ;;; self.Reset() ENDIF ENDEVENT EVENT OnActivate(ObjectReference akActionRef) IF (akActionRef as Actor) ELSE myF_Mining(akActionRef) RETURN ; - STOP - triggered by Activate() ENDIF ;--------------------- int i = myF_Test(akActionRef as Actor) IF (i > 0) myF_Activate(akActionRef, i) ENDIF ENDEVENT ; -- FUNCTIONs -- 5 ;-------------------------------------------------------- FUNCTION myF_Activate(ObjectReference akActionRef, Int i) ; internal helper ;-------------------------------------------------------- objectReference oRef = self.GetLinkedRef() IF ( oRef ) oRef.Activate(akActionRef) ELSE Debug.Trace(" OnActivate() - Error: Missing linkedRef detected! ("+i+") " +self) ENDIF ENDFUNCTION ;----------------------------- Bool FUNCTION myF_SkillReady() ; internal helper ;----------------------------- IF (F_Skill_Mining.GetValueInt() < rLvl) Debug.Messagebox("You lack the required level of " + rLvl as Int + " to mine " + rockName + ".") Return False ENDIF ;--------- Return TRUE ENDFUNCTION ;-------------------------------- Int FUNCTION myF_Test(Actor aRef) ;-------------------------------- IF aRef.IsSneaking() ; ### USKP 1.3.1 ### check for sneaking before mining to prevent sneak issues. aRef.StartSneaking() ; remove idle sneaking RETURN -3 ENDIF ;--------- IF (Game.GetPlayer() == aRef) ELSE RETURN 2 ; [2] track non-player activity ENDIF ;========= from here actionRef is the player IF F_FL_Toolbag.HasForm(F_Pickaxe) Debug.Messagebox("Your toolbag does not have a pickaxe!") RETURN -2 ENDIF ;--------- IF myF_SkillReady() ELSE RETURN -1 ENDIF ;--------- F_Script_MiningFurniture ps = self.GetLinkedRef() as F_Script_MiningFurniture ; MineOreFurnitureScript IF ( ps ) ps.lastRef = self as ObjectReference ; handshake with furniture script ENDIF RETURN 1 ; [1] track player activity ENDFUNCTION ;---------------------------------------- FUNCTION myF_Mining(ObjectReference oRef) ;---------------------------------------- IF (self.GetLinkedRef() == oRef) Debug.Notification("Mining") ELSE Debug.Trace(" OnActivate() - unexpected ore activation has been registered.. " +self) RETURN ; - STOP - ENDIF ;--------------------- float f = F_GV_mCounter.GetValue() ; get the current counter, f = chance IF (f <= 0) myF_ResetCounter() RETURN ; - STOP - ENDIF ;--------------------- f = f - 1 IF (f > 0) F_GV_mCounter.SetValue(f) ELSE F_GV_mCounter.SetValue(0) Game.GetPlayer().AddItem(Ore, 1) ;;; F_Script_Framework_Level.XPS("mining", Exp) ; use external script to increase player experience ENDIF ENDFUNCTION ;-------------------------- FUNCTION myF_ResetCounter() ; internal helper ;-------------------------- float f = F_Skill_Mining.GetValue() * 0.1 int i = 20 - (f as Int) + rLvl IF (i > 0) F_GV_mCounter.SetValue( Utility.RandomInt(0, i) as Float ) ELSE F_GV_mCounter.SetValue(1) ; at least one attack ENDIF ENDFUNCTION F_Script_MiningFurniture Scriptname F_Script_MiningFurniture extends ObjectReference {Mining script to send back to activator} ; https://forums.nexusmods.com/index.php?/topic/7762863-need-help-for-a-repeating-function/ ;F_Script_MiningActivator PROPERTY Mine auto Hidden ; UnUSED by default Idle PROPERTY PickaxeExit auto ObjectReference PROPERTY lastRef auto Hidden ;ObjectReference PROPERTY ObjSelf auto Hidden ; UnUSED by now ;Bool PROPERTY playerIsLeavingFurniture auto Hidden ; UnUSED by now ;Bool PROPERTY playerIsInFurniture auto Hidden ; UnUSED by now Bool PROPERTY isRegisteredForEvents auto Hidden Bool PROPERTY canBeActivated = TRUE auto Hidden ; -- EVENTs -- based on vanilla script "MineOreFurnitureScript" EVENT OnLoad() self.BlockActivation(TRUE) IF self.IsFurnitureInUse() gotoState("Busy") ; ### STATE ### ENDIF ENDEVENT EVENT OnUnload() UnregisterForEvents() ENDEVENT EVENT OnAnimationEvent(ObjectReference akSource, String asEventName) IF (asEventName == "AddToInventory") IF ( lastRef ) lastRef.Activate(self as ObjectReference) ENDIF RETURN ; - STOP - ENDIF ;--------------------- UnregisterForEvents() ; do it for any other registered animation ENDEVENT ;==================================== auto State Normal ;================ EVENT OnBeginState() canBeActivated = TRUE ENDEVENT EVENT OnActivate(ObjectReference akActionRef) IF ( canBeActivated ) ELSE RETURN ; - STOP - out of order! ENDIF ; ---------------------- canBeActivated = False gotoState("Busy") ; ### STATE ### IF (akActionRef == Game.GetPlayer() as ObjectReference) && !self.IsFurnitureInUse() RegisterForEvents() ENDIF self.Activate(akActionRef, TRUE) canBeActivated = TRUE ENDEVENT ;======= endState ;==================================== State Busy ;========= EVENT OnBeginState() canBeActivated = TRUE ENDEVENT EVENT OnActivate(ObjectReference akActionRef) bool bOK = (akActionRef == Game.GetPlayer() as ObjectReference) IF self.IsFurnitureInUse() ELSEIF ( bOK ) RegisterForEvents() self.Activate(akActionRef, TRUE) canBeActivated = TRUE RETURN ; - STOP - activated by player and furniture was not in use ENDIF ; ---------------------- IF ( canBeActivated ) ELSE RETURN ; - STOP - I am busy! ENDIF ; ---------------------- canBeActivated = False IF ( isRegisteredForEvents ) ELSEIF ( bOK ) self.Activate(akActionRef, TRUE) canBeActivated = TRUE RETURN ; - STOP - activated by player, but not already registered for animations ENDIF ; ---------------------- IF (bOK) || (akActionRef == lastRef) gotoState("Reseting") ; ### STATE ### Game.GetPlayer().PlayIdle(PickaxeExit) gotoState("Normal") ; ### STATE ### ??? ENDIF canBeActivated = TRUE ENDEVENT ;======= endState ;==================================== state Reseting ;============= endState ; -- FUNCTIONs -- 2 ;--------------------------- FUNCTION RegisterForEvents() ;--------------------------- IF ( isRegisteredForEvents ) RETURN ; - STOP - already done! ENDIF ;--------------------- isRegisteredForEvents = TRUE objectReference playerRef = Game.GetPlayer() as ObjectReference RegisterForAnimationEvent(playerRef, "AddToInventory") RegisterForAnimationEvent(playerRef, "IdlePickaxeExit") RegisterForAnimationEvent(playerRef, "IdlePickaxeFloorExit") RegisterForAnimationEvent(playerRef, "IdlePickaxeTableExit") RegisterForAnimationEvent(playerRef, "IdleFurnitureExit") ENDFUNCTION ;----------------------------- FUNCTION UnregisterForEvents() ;----------------------------- IF ( isRegisteredForEvents ) ELSE RETURN ; - STOP - ENDIF ;--------------------- isRegisteredForEvents = False objectReference playerRef = Game.GetPlayer() as ObjectReference UnRegisterForAnimationEvent(playerRef, "AddToInventory") UnRegisterForAnimationEvent(playerRef, "IdlePickaxeExit") UnRegisterForAnimationEvent(playerRef, "IdlePickaxeFloorExit") UnRegisterForAnimationEvent(playerRef, "IdlePickaxeTableExit") UnRegisterForAnimationEvent(playerRef, "IdleFurnitureExit") ENDFUNCTION Link to comment Share on other sites More sharing options...
Recommended Posts