Jump to content

What am I doing wrong with these scripts?


bwins95

Recommended Posts

I've got two scripts that partially work.

 

First

 

scn aaaaGlowingItems

ref rCurrentRef

Begin OnEquip player

;---------
;Armor
;---------

set rCurrentRef to GetFirstRef 24 1 0
Label 1
if IsFormValid rCurrentRef
if aaaaGlowingItemsArmor == 1
rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderRed
rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderGreen
elseif aaaaGlowingItemsArmor ==0
rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderBlue
set rCurrentRef to Pencil01
set rCurrentRef to GetNextRef

GoTo 1
endif
endif

;----------------
;Weapons
;----------------

set rCurrentRef to GetFirstRef 40 1 0
Label 2
if IsFormValid rCurrentRef
rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderRed
rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderGreen
rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderBlue
set rCurrentRef to Pencil01
set rCurrentRef to GetNextRef
GoTo 2
endif

;----------
;Books
;----------

set rCurrentRef to GetFirstRef 25 1 0
Label 3
if IsFormValid rCurrentRef
rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderRed
rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderGreen
rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderBlue
set rCurrentRef to Pencil01
set rCurrentRef to GetNextRef
GoTo 3
endif

;-------------
;Clothing
;--------------

set rCurrentRef to GetFirstRef 26 1 0
Label 4
if IsFormValid rCurrentRef
rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderRed
rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderGreen
rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderBlue
set rCurrentRef to Pencil01
set rCurrentRef to GetNextRef
GoTo 4
endif

;------------------
;Containers
;----------------

set rCurrentRef to GetFirstRef 27 1 0
Label 5
if IsFormValid rCurrentRef
rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderRed
rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderGreen
rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderBlue
set rCurrentRef to Pencil01
set rCurrentRef to GetNextRef
GoTo 5
endif

;-----------------
;Ingredient
;------------------

set rCurrentRef to GetFirstRef 29 1 0
Label 6
if IsFormValid rCurrentRef
rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderRed
rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderGreen
rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderBlue
set rCurrentRef to Pencil01
set rCurrentRef to GetNextRef
GoTo 6
endif

;-------
;Misc
;--------

set rCurrentRef to GetFirstRef 31 1 0
Label 7
if IsFormValid rCurrentRef
rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderRed
rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderGreen
rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderBlue
set rCurrentRef to Pencil01
set rCurrentRef to GetNextRef
GoTo 7
endif

;----------
;Ammo
;----------

set rCurrentRef to GetFirstRef 41 1 0
Label 8
if IsFormValid rCurrentRef
rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderRed
rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderGreen
rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderBlue
set rCurrentRef to Pencil01
set rCurrentRef to GetNextRef
GoTo 8
endif

End

 

this one should be applying a shader to all the items that it finds, but when I added the global variable it only applies the shader to a single item of the type.

 

Second

 

scn aaaaGlowingItemsMCM

short iMaster
short iMouseover
short iOption
short iTemp
float fTemp
float fValue
reference rList

Begin GameMode
if GetGameRestarted
if IsModLoaded "The Mod Configuration Menu.esp"
set iMaster to GetModIndex "The Mod Configuration Menu.esp"
set rList to BuildRef iMaster 2790
ListAddForm rList aaaaGlowingItemsMiscItem
endif
endif
End

Begin MenuMode 1013
if IsModLoaded "The Mod Configuration Menu.esp"
else
Return
endif

if GetUIFloat "StartMenu/MCM/_ActiveMod" == GetModIndex "Glowing items V2menu prep.esp"
set iOption to GetUIFloat "StartMenu/MCM/_ActiveOption"
set fValue to GetUIFloat "StartMenu/MCM/_Value"
;-----------------------------------------------------------------------------------------------------------
;===========================================================================================================
if GetUIFloat "StartMenu/MCM/_Reset" ;1 - RESET
SetUIFloat "StartMenu/MCM/_Reset" 0

SetUIFloat "StartMenu/MCM/*:1/_columns" 2

set itemp to aaaaGlowingItemsArmor == 1
SetUIFloat "StartMenu/MCM/*:1/*:4/_enable" 1
SetUIString "StartMenu/MCM/*:1/*:4/_title" "Turn glowing armor on"
SetUIFloat "StartMenu/MCM/*:1/*:4/_type" 4
SetUIFloat "StartMenu/MCM/*:1/*:4/_value" aaaaGlowingItemsArmor
;-----------------------------------------------------------------------------------------------------------
;===========================================================================================================
elseif GetUIFloat "StartMenu/MCM/_Default" ;2 - DEFAULT
SetUIFloat "StartMenu/MCM/_Default" 0
SetUIFloat "StartMenu/MCM/_Reset" 1

set aaaaGlowingItemsArmor to 0
;-----------------------------------------------------------------------------------------------------------
;===========================================================================================================
elseif GetUIFloat "StartMenu/MCM/_NewValue" ;3 - NEW VALUE
SetUIFloat "StartMenu/MCM/_NewValue" 0
SetUIFloat "StartMenu/MCM/_Reset" 1

if iOption == 1
set aaaaGlowingItemsArmor to 1
elseif ioption == 2
set aaaaGlowingItemsArmor to 0
endif
endif
;-----------------------------------------------------------------------------------------------------------
;===========================================================================================================
if iMouseover != GetUIFloat "StartMenu/MCM/*:1/_optionID" ;7 - MOUSE-OVER
set iMouseover to GetUIFloat "StartMenu/MCM/*:1/_optionID"
if iMouseover
SetUIFloat "StartMenu/MCM/MCM_Info/visible" 1

if iMouseover == 1
SetUIString "StartMenu/MCM/MCM_Info/string" "Makes armor glow"
else
SetUIFloat "StartMenu/MCM/MCM_Info/visible" 0
endif
else
SetUIFloat "StartMenu/MCM/MCM_Info/visible" 0
endif
endif
endif
End

 

This mcm script only switches to on. I can't change it back to off.

 

I have a feeling it's something small hat I'm overlooking.

 

How do I add more items to the mcm page? I need to add more on/off switches.

Link to comment
Share on other sites

For your first script, why are you using IsFormValid? From a quick look on the wiki it looks as thought this would stop your shader from being applied to anything that wasn't a persistent reference, which is most things.

 

As for your second, these lines:

if iOption == 1
    set aaaaGlowingItemsArmor to 1
elseif ioption == 2
    set aaaaGlowingItemsArmor to 0
endif

would imply that you've set up two buttons, one to turn off the effect and one to turn it on. However, you've only made one entry, therefore, iOption will never be 2. It should read:

 

 

if iOption == 1
   if aaaaGlowingItemsArmor
        set aaaaGlowingItemsArmor to 0
    else
        set aaaaGlowingItemsArmor to 1
    endif
endif

 

I'd recommend reading the MCM guide, it's very helpful. :smile:

Edited by Jojash
Link to comment
Share on other sites

First:

I suppose loops and/or REF walking may not work properly when inside an OnEquip block. Try moving it to a GameMode block:

scn	aaaaGlowingItems

short	bScan
ref	rCurrentRef

begin OnEquip player

	set bScan to 1

end

begin GameMode

	if bScan
		set bScan to 0

		(Move everything from the OnEquip block here)

	endif

end

Second:

You only have a single ON/OFF setting there, and its index is 4, so it should be:

if iOption == 4
	set aaaaGlowingItemsArmor to fValue
endif
Edited by jazzisparis
Link to comment
Share on other sites

isFormValid checks to see if the form is loaded into memory. This is helpful in cases where you've set a ref variable to a temporary ref or a placeatme in the game world and you want to come back to it later - well, the game might have unloaded it by that time, so you check to see if the ref is still valid form before doing anything with it. Not for Refwalks.

Link to comment
Share on other sites

 

First:

I suppose loops and/or REF walking may not work properly when inside an OnEquip block. Try moving it to a GameMode block:

scn	aaaaGlowingItems

short	bScan
ref	rCurrentRef

begin OnEquip player

	set bScan to 1

end

begin GameMode

	if bScan
		set bScan to 0

		(Move everything from the OnEquip block here)

	endif

end

Second:

You only have a single ON/OFF setting there, and its index is 4, so it should be:

if iOption == 4
	set aaaaGlowingItemsArmor to fValue
end

Thank you. you saved me a few days of reading for the switch.

 

The ref walking seems to work the same with a direct onequip or gamemode. the first global variable in the armor part only targets a single item. the second global variable in the armor part hits everything that it should.

Edited by bwins95
Link to comment
Share on other sites

For the record, and to extend the explanation, rickerhk is correct. IsFormValid is a perfectly valid function to use there, though as far as I know doing a simple if <item> works almost the same. IsFormValid does give a more consistent feel to scripts, and keeps them more self documenting, so I use it.

 

It is also valid to use on any form in every circumstance I've encountered. I use it for list walking of both static and dynamic lists (detects the end of the list just fine). I use it in other places too, and have found that other types of checks can actually cause a crash where IsFormValid will not.

 

Another point to consider, for anyone else referencing in the future is that if your script is crashing for some unknown reason, and you are doing something with potentially non-persistent refs, throw an IsFormValid check in just to make sure.

Link to comment
Share on other sites

Each time I try this it keeps applying the red shader to the exact same item until i pick up the item then it applies it to a different item. it is still a single item instead of all the armor in the cell. I have tracked it down to this.

 

if aaaaGlowingItemsArmor == 1
rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderRed

 

I tried both if rcurrentref and if isvalidform and the both give the same result.

Link to comment
Share on other sites

I figured it out. the problem was a misplaced end if.

 

set rCurrentRef to GetFirstRef 24 1 0
Label 1
if IsFormValid rCurrentRef
if aaaaGlowingItemsArmor == 1
rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderRed
rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderGreen
elseif aaaaGlowingItemsArmor ==0
rCurrentRef.PlayMagicShaderVisuals aaaaGlowingItemsShaderBlue
set rCurrentRef to Pencil01
set rCurrentRef to GetNextRef

GoTo 1
endif
endif

 

this part the two end if's at the bottom is wrong. one of them should have been after the second global variable.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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