I added a perk to the player that can let the sole survivor pick up food item and eat directly. Here is my code.
ScriptName GrabAndEat Extends Quest
; Properties
Perk Property GrabAndEatPerk Auto Const
Message Property GrabAndEatMSG_Enabled Auto Const
Message Property GrabAndEatMSG_Disabled Auto Const
; Keyword
Keyword Property ObjectTypeFood Auto const
; variables
Form Item = None
Actor PlayerRef
Event OnQuestInit()
On()
EndEvent
Function On()
If (!Game.GetPlayer().HasPerk(GrabAndEatPerk))
Game.GetPlayer().AddPerk(GrabAndEatPerk,False)
GrabAndEatMSG_Enabled.Show(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0)
EndIf
EndFunction
Function Grab(ObjectReference akTargetRef)
GotoState("Busy")
PlayerRef=Game.GetPlayer()
Debug.trace("Grab() oprerating...")
Item=akTargetRef.GetBaseObject()
Debug.trace("Item is "+Item)
Debug.Trace("prepare to pick up",0)
;game freezes after calling Activate() 11 or 12 times
akTargetRef.Activate(PlayerRef,True);
Debug.Trace("picked up food",0)
Game.GetPlayer().EquipItem(Item,False,True)
Debug.Trace("Equiped",0)
Utility.wait(2.5)
GotoState("")
EndFunction
State Busy
Function Grab(ObjectReference akTargetRef)
Debug.Notification("You are chewing")
Debug.trace("Grab() BUSY state.",0)
EndFunction
EndState
and the perk fragment code that calls GrabController.Grab()
;BEGIN FRAGMENT CODE - Do not edit anything between this and the end comment
Scriptname PRKGrabAndEat Extends Perk Hidden Const
GrabAndEat Property GrabController Auto Const Mandatory
;BEGIN FRAGMENT Fragment_Entry_00
Function Fragment_Entry_00(ObjectReference akTargetRef, Actor akActor)
;BEGIN CODE
GrabController.Grab(akTargetRef)
;END CODE
EndFunction
;END FRAGMENT
;END FRAGMENT CODE - Do not edit anything between this and the begin comment
Everything works fine except that the game always freezes when you pick up 12th or 13th item. After a few trials and errors I found that it has something to do with akTargetRef.Activate(PlayerRef,True) cause freeze always occurs after the game calls that function 11 or 12 times. I can't figure out why Active() causes the problem and why it happens on 12th or 13th call. Is Active() different from pressing active button ? Does anybody know how to solve this problem? I'm not a native speaker and sorry for my poor English. I hope you understand what I say. :smile: