Jump to content

How to get Object ID for Player Made Potions?


DavaScript

Recommended Posts

That runs on a reference which you won't have in this case (you have a base object when you get the potion's object ID). Your formula would still fail as its only finding one unique object ID

 

Would it be possible, through script, to set the object id of a player made potion to the same id of, let's say, a novice Potion of Healing?

Edited by DavidSkx
Link to comment
Share on other sites

I mean yes, but that sounds like more worth than needed. An inventory reference walk is much simpler and catches any potion with the appropriate magic effect you want. No need to worry about object IDs with it

 

Oh ok. I'm not really familiar with Oblivion scripting. Would you be kind enough to demonstrate how it would be done, and how I would connect it to HUD Status Bars?

Link to comment
Share on other sites

This raw script shows how I used an inventory walk with inventory references to pick up magic items by magic effect. It checks if the inventory reference is an ingredient, and compares the magic effects it has to the one we want. If it has it the item is removed from the source and added to the player.

What you want is quite a bit simpler at the core script. You only need to walk through the players inventory, see if any potion in the player's inventory has "Restore Health (REHE)", then increment a flag, and finally offload this flag to how HUD Status Bars works (since we can't use the ini file). Where this gets tricky is implementing this into HUD Status Bars

The script - OBSE allows us to treat items in an inventory as references. To do this we need a few components. We need a reference to offload the item too, "iter", the container in question, "PlayerREF", and your flag, "potionCount". We then iterate (aka walk) through the inventory and take every reference found and plug it into "iter". We can then pretend that "iter" is a normal reference and do whatever:

;; we need to set up variables

ref iter
; PlayerREF is an explicit reference, it can't be a variable

int potionCount

;; we are just structuring the idea of the script, it needs to be inside a begin block at some point
; here we set potionCount to 0 at some point, not sure when
; scripting can be annoying

foreach iter <- PlayerREF ; take each reference in "PlayerREF" and assign it to the ref var "iter"
;; we only care about one thing, potions with REHE
   if (iter.IsAlchemyItem == 1) ; see if the reference is an alchemy item aka potion
      if (MagicItemHasEffect REHE iter) ; see if it has the effect we want
         let potionCount += 1 ; += stands for compound assignment, addition in this case. lets us simplify let x := x + 1 to let x += 1
      endif
   endif
loop

It's late so I'm posting what I have rn in case my computer decides not to turn on properly, the other half I'll finish tomorrow

Link to comment
Share on other sites

Implementing into HUD Status Bars - We need to modify two things, the ini to get the menu element and plugin scripts itself. The ini is simple, you only need to add the following block:

; ==== Display number of available health potions
set tnoHSB.hud_type to HUDtxtNoBar
set tnoHSB.hud_color to sv_Construct "HUDcolorBlue"		
set tnoHSB.hud_val to sv_Construct "tnoHSB.potion_val" ; this actually gives us the value we need
set tnoHSB.hud_x to 50 ; choose wherever
set tnoHSB.hud_y to 70 ; choose wherever
set tnoHSB.hud_name to sv_Construct "Potions: "
set tnoHSB.hud_textColor to sv_Construct "tnoHSB.color" ; Color matches bar color	
set tnoHSB.hud_textDisplay to HUDtxtValue ; Display as value
	SetStage tnoHSB 10

You can play around with the design as you please

To implement we need to take the script made above, with the appropriate changes cause Oblivion scripting is painful, and then call it somehow. We will call it on the main quest script so that it runs all the time, its inefficient but shouldn't be a massive drag on CPU time. I'm also going to assume you have some sort of experience using the CS in script extender mode/CSE to modify/add scripts. There's not much we need to do

 

The modified script:

scn HUDPotion

;; we need to set up variables
ref iter ; our passed inventory reference
ref ItemID ; the base object reference for our inventory reference
; PlayerREF is an explicit reference, it can't be a variable

int potionCount ; the number of potions
int magicCode ; we need a code for the magic effect

begin function {}
let potionCount := 0
let magicCode := MagicEffectCodeFromChars "REHE" ; we need to get the integer code because this plugin does not use Oblivion.esm as master
foreach iter <- PlayerREF ; take each reference in "PlayerREF" and assign it to the ref var "iter"
	let ItemID := iter.GetBaseObject ; we need to ge the base object in some cases
; we only care about one thing, potions with REHE
	if (iter.IsAlchemyItem == 1) ; see if the reference is an alchemy item aka potion
		if (MagicItemHasEffectCode magicCode ItemID) ; see if it has the effect we want using the base object
			let potionCount += iter.GetRefCount ; += stands for compound assignment, addition in this case. lets us simplify let x := x + 1 to let x += 1
		endif
	endif
loop
setfunctionvalue potionCount ; we need to return this so the main script can set the variable
end

Copy and paste this into a new script and save it, this is our user function to be called

 

Next open up the script "HUDMain", this is the main script so it runs on some interval. At the end of variable declaration, around line 260 before the "Begin GameMode" line, add "int potion_val". Then below the begin line add "let tnoHSB.potion_val := Call HUDPotion". Save the script and plugin and everything should work as I presented, the HUD ini settings are a bit weird and might not show up idk how they work exactly

This ended up taking a while because this mod is masterless, so it makes working with magic effects really annoying since Oblivion.esm contains most of the magic effects for some stupid reason. I had do to some chatting around to figure that out and how to work around it. This is also not the most efficient way to do this but eh, shouldn't be too bad

Edited by KatsAwful
Link to comment
Share on other sites

Implementing into HUD Status Bars - We need to modify two things, the ini to get the menu element and plugin scripts itself. The ini is simple, you only need to add the following block:

; ==== Display number of available health potions
set tnoHSB.hud_type to HUDtxtNoBar
set tnoHSB.hud_color to sv_Construct "HUDcolorBlue"		
set tnoHSB.hud_val to sv_Construct "tnoHSB.potion_val" ; this actually gives us the value we need
set tnoHSB.hud_x to 50 ; choose wherever
set tnoHSB.hud_y to 70 ; choose wherever
set tnoHSB.hud_name to sv_Construct "Potions: "
set tnoHSB.hud_textColor to sv_Construct "tnoHSB.color" ; Color matches bar color	
set tnoHSB.hud_textDisplay to HUDtxtValue ; Display as value
	SetStage tnoHSB 10

You can play around with the design as you please

 

To implement we need to take the script made above, with the appropriate changes cause Oblivion scripting is painful, and then call it somehow. We will call it on the main quest script so that it runs all the time, its inefficient but shouldn't be a massive drag on CPU time. I'm also going to assume you have some sort of experience using the CS in script extender mode/CSE to modify/add scripts. There's not much we need to do

 

The modified script:

 

scn HUDPotion

;; we need to set up variables
ref iter ; our passed inventory reference
ref ItemID ; the base object reference for our inventory reference
; PlayerREF is an explicit reference, it can't be a variable

int potionCount ; the number of potions
int magicCode ; we need a code for the magic effect

begin function {}
let potionCount := 0
let magicCode := MagicEffectCodeFromChars "REHE" ; we need to get the integer code because this plugin does not use Oblivion.esm as master
foreach iter <- PlayerREF ; take each reference in "PlayerREF" and assign it to the ref var "iter"
	let ItemID := iter.GetBaseObject ; we need to ge the base object in some cases
; we only care about one thing, potions with REHE
	if (iter.IsAlchemyItem == 1) ; see if the reference is an alchemy item aka potion
		if (MagicItemHasEffectCode magicCode ItemID) ; see if it has the effect we want using the base object
			let potionCount += iter.GetRefCount ; += stands for compound assignment, addition in this case. lets us simplify let x := x + 1 to let x += 1
		endif
	endif
loop
setfunctionvalue potionCount ; we need to return this so the main script can set the variable
end

Copy and paste this into a new script and save it, this is our user function to be called

 

Next open up the script "HUDMain", this is the main script so it runs on some interval. At the end of variable declaration, around line 260 before the "Begin GameMode" line, add "int potion_val". Then below the begin line add "let tnoHSB.potion_val := Call HUDPotion". Save the script and plugin and everything should work as I presented, the HUD ini settings are a bit weird and might not show up idk how they work exactly

 

This ended up taking a while because this mod is masterless, so it makes working with magic effects really annoying since Oblivion.esm contains most of the magic effects for some stupid reason. I had do to some chatting around to figure that out and how to work around it. This is also not the most efficient way to do this but eh, shouldn't be too bad

 

Ok so I copied the modified script into a new script in the HUD Status Bars.esp. Then I opened up the HUDMain script and added 'int potion_val' at the end of the variable declaration before the Begin GameMode function. Then I added 'let tnoHSB.potion_val := Call HUDPotion' right after the Begin GameMode function, but it gives me an error when I hit save, saying that 'potion_val' is an unknown variable.

Edited by DavidSkx
Link to comment
Share on other sites

  • Recently Browsing   0 members

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