Jump to content

[Script] A way to incorporate Game.Getplayer() and the workshop inventory?


Zorkaz

Recommended Posts

I have activators that make food (A toaster, a coffee pot, etc...)

 

The toaster for instance has a script like this

Scriptname FFMakeToastScr extends ObjectReference

Message Property FFNoRazorgrainMsg Auto
Potion Property Razorgrain Auto
Potion Property FFToast Auto
Sound Property FFToasterFX Auto

Event OnActivate (ObjectReference AkActionRef)
If Game.Getplayer().Getitemcount (Razorgrain ) < 2
FFNoRazorgrainMsg.show()
Else
Game.Getplayer().Removeitem (Razorgrain , 2)
Game.Getplayer().Additem (FFToast)
FFToasterFX.play(Self)
Endif
EndEvent

But using Game.Getplayer() only accesses the player inventory. Is there a simple way to check both player and workshop inventory at the same time?

The reason is that I have more complicated scripts like this one...


 

 

Link to comment
Share on other sites

As SKK50 is alluding to, so long as the player is manually placing your activators down in Workshop mode, the workshop in question will inherently be attached to the object. I do this in my fusion core charger mod to look for nuclear material. Anyways by having the script on the activator(as I assume you do), you can utilize the akReference like this:

Scriptname FFMakeToastScr extends ObjectReference

Message Property FFNoRazorgrainMsg Auto
ObjectReference Property WorkshopToCheck Auto
Potion Property Razorgrain Auto
Potion Property FFToast Auto
Sound Property FFToasterFX Auto

Event OnWorkshopObjectPlaced(ObjectReference akReference)
 WorkshopToCheck = akReference
EndEvent

Event OnActivate(ObjectReference AkActionRef)
 If (Game.Getplayer().Getitemcount(Razorgrain)+WorkshopToCheck.GetItemCount(Razorgrain)) < 2
  FFNoRazorgrainMsg.show()
 ElseIf Game.Getplayer().Getitemcount(Razorgrain) >= 2
  Game.Getplayer().Removeitem(Razorgrain, 2)
  FFToasterFX.play(Self)
  Game.Getplayer().Additem(FFToast)
 ElseIf Game.Getplayer().Getitemcount(Razorgrain) == 1 && WorkshopToCheck.GetItemCount(Razorgrain)) >= 1
  WorkshopToCheck.Removeitem(Razorgrain, 1)
  Game.Getplayer().Removeitem(Razorgrain, 1)
  FFToasterFX.play(Self)
  Game.Getplayer().Additem(FFToast)
 ElseIf Game.Getplayer().Getitemcount(Razorgrain) == 0 && WorkshopToCheck.GetItemCount(Razorgrain)) >= 2
  WorkshopToCheck.Removeitem(Razorgrain, 2)
  FFToasterFX.play(Self)
  Game.Getplayer().Additem(FFToast)
 Endif
EndEvent

This could probably be shorter, but I accounted for all the scenarios that jumped out at me.

Link to comment
Share on other sites

I had the workshopobjectscript and workshopresourceobject (Actor Value) attached to it but no luck. Anyway I'll try Fantafaust version.

 

Issue is that I have a script with 24 such items too so the above version is really confusing

Link to comment
Share on other sites

I had the workshopobjectscript and workshopresourceobject (Actor Value) attached to it but no luck. Anyway I'll try Fantafaust version.

 

Issue is that I have a script with 24 such items too so the above version is really confusing

I appreciate the vote of confidence, but I'm going off memory so it might not compile.

I also don't understand what you mean by "a script with 24 such items too"?

 

I can however explain the logic behind my code from above if you like.

Link to comment
Share on other sites

I have the Frying Pan script and it can become very confusing using the method used for the toast

Scriptname FFMakeSteakScr extends ObjectReference


Message Property FFNoMeatMsg Auto
Sound Property FFFryingFX Auto

Potion Property MeatBloatfly Auto
Potion Property MeatBloodbug Auto
Potion Property MeatBrahmin Auto
Potion Property MeatCat Auto
Potion Property MeatDeathclaw Auto
Potion Property Meatdog Auto
Potion Property MeatGorilla Auto
Potion Property MeatMirelurk Auto
Potion Property MeatMirelurkQueen Auto
Potion Property MeatMirelurkSoftshell  Auto
Potion Property MeatMolerat Auto
Potion Property MeatMutanthound Auto
Potion Property MeatRadroach Auto
Potion Property MeatRadscorpion Auto
Potion Property MeatRadstag Auto
Potion Property MeatStingwing Auto
Potion Property MeatYaoGuai Auto
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Potion Property SteakBloatfly Auto
Potion Property SteakBloodbug Auto
Potion Property steakBrahmin Auto
Potion Property SteakDeathclaw Auto
Potion Property steakDog Auto
Potion Property steakMirelurk Auto
Potion Property SteakMirelurkQueen Auto
Potion Property steakMirelurkSoftshell Auto
Potion Property steakMolerat Auto
Potion Property steakMutantHound Auto
Potion Property SteakRadroach Auto
Potion Property SteakRadscorpion Auto
Potion Property steakRadStag Auto
Potion Property steakStingwing Auto
Potion Property steakYaoGuai Auto

Event OnActivate (ObjectReference AkActionRef)
FFFryingFX.play(Self)
If Game.Getplayer().Getitemcount (MeatBloatfly) > 1
Game.Getplayer().removeitem (MeatBloatfly, 2)
Game.Getplayer().Additem (SteakBloatfly)
Elseif Game.Getplayer().Getitemcount (MeatBloodbug) > 0
Game.Getplayer().removeitem (MeatBloodbug, 1)
Game.Getplayer().Additem (SteakBloodbug)
Elseif Game.Getplayer().Getitemcount (MeatBrahmin) > 0
Game.Getplayer().removeitem (MeatBrahmin, 1)
Game.Getplayer().Additem (SteakBrahmin)
Elseif Game.Getplayer().Getitemcount (MeatDeathclaw) > 0
Game.Getplayer().removeitem (MeatDeathclaw, 1)
Game.Getplayer().Additem (SteakDeathclaw)
Elseif Game.Getplayer().Getitemcount (MeatDog) > 0
Game.Getplayer().removeitem (MeatDog, 1)
Game.Getplayer().Additem (SteakDog)
Elseif Game.Getplayer().Getitemcount (MeatMirelurk) > 1
Game.Getplayer().removeitem (MeatMirelurk, 2)
Game.Getplayer().Additem (SteakMirelurk)
Elseif Game.Getplayer().Getitemcount (MeatMirelurkQueen) > 0
Game.Getplayer().removeitem (MeatMirelurkQueen)
Game.Getplayer().Additem (SteakMirelurkQueen, 2)
Elseif Game.Getplayer().Getitemcount (MeatMirelurkSoftshell) > 1
Game.Getplayer().removeitem (MeatMirelurkSoftshell,2)
Game.Getplayer().Additem (SteakMirelurkSoftshell)
Elseif Game.Getplayer().Getitemcount (MeatMolerat) > 1
Game.Getplayer().removeitem (MeatMolerat,2)
Game.Getplayer().Additem (SteakMolerat)
Elseif Game.Getplayer().Getitemcount (MeatMutantHound) > 0
Game.Getplayer().removeitem (MeatMutantHound)
Game.Getplayer().Additem (SteakMutantHound)
Elseif Game.Getplayer().Getitemcount (MeatRadroach) > 2
Game.Getplayer().removeitem (MeatRadroach, 3)
Game.Getplayer().Additem (SteakRadroach)
Elseif Game.Getplayer().Getitemcount (MeatRadscorpion) > 0
Game.Getplayer().removeitem (MeatRadscorpion)
Game.Getplayer().Additem (SteakRadscorpion)
Elseif Game.Getplayer().Getitemcount (MeatRadstag) > 0
Game.Getplayer().removeitem (MeatRadstag)
Game.Getplayer().Additem (SteakRadstag)
Elseif Game.Getplayer().Getitemcount (MeatStingwing) > 0
Game.Getplayer().removeitem (MeatStingwing)
Game.Getplayer().Additem (SteakStingwing)
Elseif Game.Getplayer().Getitemcount (MeatYaoguai) > 0
Game.Getplayer().removeitem (MeatYaoguai)
Game.Getplayer().Additem (SteakYaoguai)
Else
FFNoMeatMsg.show() 
Endif
EndEvent

That's why I hoped there was a more easy solution

Link to comment
Share on other sites

Try something like this:

Scriptname YOURSCRIPTNAME extends ObjectReference Const

Potion Property MirelurkMeat Auto Const
Potion Property RoastedMirelurkMeat Auto Const
Potion Property CatMeat Auto Const
Potion Property CookedCatMeat Auto Const
Keyword Property WorkshopItemKeyword Auto Const


Event OnActivate(ObjectReference akActionRef)
	If akActionRef == Game.GetPlayer()
		CookingTime(MirelurkMeat, 4, RoastedMirelurkMeat, 1)
		CookingTime(CatMeat, 5, CookedCatMeat, 2)
	Else
		; error, Player only
	EndIf
EndEvent

Function CookingTime(Potion RequiredPotion, Int RequiredPotionCount, Potion Food, Int FoodCount)
	;--------------- Get Workshop --------------- 
	ObjectReference WorkshopRef = GetLinkedRef(WorkshopItemKeyword) as ObjectReference
	If !(WorkshopRef as WorkshopScript)
		; error, workshop couldn't be found
		Return None
	EndIf
	;--------------- Inventory data --------------- 
	Actor PlayerRef = Game.GetPlayer()
	Int PItemCount = PlayerRef.GetItemCount(RequiredPotion)
	Int WItemCount = WorkshopRef.GetItemCount(RequiredPotion)
	Int SumItemCount = PItemCount + WItemCount
	;--------------- Compare data --------------- 
	; Try to remove the ingredients from the Player first
	If PItemCount >= RequiredPotionCount
		PlayerRef.RemoveItem(RequiredPotion, RequiredPotionCount)
		PlayerRef.AddItem(Food, FoodCount)
	; Player doesn't have all the required ingredients, check workshop
	ElseIf WItemCount >= RequiredPotionCount
		WorkshopRef.RemoveItem(RequiredPotion, RequiredPotionCount)
		PlayerRef.AddItem(Food, FoodCount)
	; Need to check both
	ElseIf SumItemCount >= RequiredPotionCount
		Int i1
		Int i2
		If PItemCount >= WItemCount
			i1 = PItemCount
			i2 = RequiredPotionCount - PItemCount
		Else
			i1 = WItemCount
			i2 = RequiredPotionCount - WItemCount
		EndIf
		PlayerRef.RemoveItem(RequiredPotion, i1)
		WorkshopRef.RemoveItem(RequiredPotion, i2)
		PlayerRef.AddItem(Food, FoodCount)
	Else
		; no one has the required ingredients
	EndIf
EndFunction 

Fixed some possible errors and added some commented out lines.

Edited by LarannKiar
Link to comment
Share on other sites

Is the intention to instantly cook up all those things on a single click? Because that would affect how the final script is going to be composed. If not, you'll likely want to have a messagebox pop up with specific cooking options. Otherwise LarannKiar's script is very efficient and would only require that you add in the other uncooked/cooked food combos as parameters for the function in the OnActivate block.

ie

CookingTime(MeatBrahmin, 1, SteakBrahmin, 1)

and etc

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...