Jump to content

I ask you this. Why is this script not working?


Recommended Posts

I'm trying to have a staff that when equipped adds some spells, abilities and the ability to recharge during certain conditions, in this case during snowy weather, which can be done via a weather spell (Ice Staff Blizzard spell) or just by going somewhere that snows. The addspell and removespell portion of the script work fine it's the rest that doesn't work, I made a recharge spell by copy and pasting the part of the script that deals with the recharging of the weapon and that works fine as a magic effect but its not working when attached to the weapon.

I've just begin to dabble in scripting over the past few weeks so I might be missing something obvious any help would be greatly appreciated.

 

This is script.


ScriptName ElementalIceStaffScript

Short powered

float recharge

ref Weapon

Begin OnEquip

Player.AddSpell IceStaffSpell
Player.AddSpell IceStaffShield
Player.AddSpell IceStaffBlizzard
;Player.AddSpell RechargeWeaponSpell
SelectPlayerSpell IceStaffSpell
Message "ICE ITEMS ADDED" 2
End

Begin GameMode
if powered == 1
If GetIsCurrentWeather Snow == 0
set weapon to GetEquippedObject 16
Set recharge to GetObjectCharge weapon
SetEquippedCurrentCharge recharge 16
Cast RechargeWeaponSpell Player
Player.RemoveSpell IceStaffBlizzardShield
Player.RemoveSpell IceStaffBlizzardSpell
;ElementalIceStaff.SetEnchantment ElementaIceStaffEnchantment
;recharge.SetCurrentCharge 20
;SetEquippedCurrentCharge 22 16
Player.AddSpell IceStaffSpell
Player.AddSpell IceStaffShield
Set powered to 0
Message "Powered set to 0 NORMALITY RETURNED" 2
endif
endif
if powered == 0
If GetIsCurrentWeather Snow == 1
Player.RemoveSpell IceStaffSpell
Player.RemoveSpell IceStaffShield
;ElementalIceStaff.SetEnchantment ElementaIceStaffBlizzardEnchantment
;Set recharge to GetObjectCharge recharge
;SetEquippedCurrentCharge recharge 16
Player.AddSpell IceStaffBlizzardShield
Player.AddSpell IceStaffBlizzardSpell
set powered to 1
Message "Powered set to 1 BLIZZARD ITEMS ADDED" 2
Endif
Endif

End

begin OnUnEquip
Player.RemoveSpell IceStaffSpell
Player.RemoveSpell IceStaffShield
Player.RemoveSpell IceStaffBlizzard
Player.RemoveSpell IceStaffBlizzardShield
Player.RemoveSpell IceStaffBlizzardSpell
;Player.RemoveSpell RechargeWeaponSpell
Message "ICE ITEMS REMOVED" 2

 

 

 

You might have noticed that there are some set enchantment parts in there too, these crash the game as soon as there is snow. I've decided to tackle one problem at a time so I haven't even tried to remedy that problem as of yet, but if anyone can offer some advise on that matter, that too would be greatly appreciated.

Link to comment
Share on other sites

Let's see...

 

First, those "Player." can be a problem. They add the spells/abilities to the player... even if someone else equip the staff. I would do:

ref actor

Begin OnEquip
   Set actor To GetContainer   ;this actor is equipping the staff
   actor.AddSpell IceStaffSpell
   actor.AddSpell IceStaffShield
   actor.AddSpell IceStaffBlizzard
   ;actor.AddSpell RechargeWeaponSpell
   If (actor.GetIsReference PlayerRef)   ;Equip the spell on player, only if player is the actor
     SelectPlayerSpell IceStaffSpell
   EndIf
End

Begin OnUnEquip
   ;No need to use GetContainer again.
   ;The variable was already assigned by the OnEquip block, and the actor who was equipping the staff is the same who is unequipping it now.
   actor.RemoveSpell IceStaffSpell
   actor.RemoveSpell IceStaffShield
   actor.RemoveSpell IceStaffBlizzard
   actor.RemoveSpell IceStaffBlizzardShield
   actor.RemoveSpell IceStaffBlizzardSpell
   ;actor.RemoveSpell RechargeWeaponSpell
   Message "ICE ITEMS REMOVED" 2
End
Also, remove all "Player." and replace them with "actor." also in the GameMode block (Again, there's no need to use GetContainer in the GameMode block)

This way, the staff become usable by NPCs too (including your followers).

 

 

Then:

the problem with SetEnchantment is the wrong usage: http://cs.elderscrolls.com/index.php?title=SetEnchantment

"reference.SetEnchanment nuEnchantment:ref" can only be used with a reference. This is not the case, because ElementalIceStaff is not a reference, but a base object.

To make it work, you need to use the other way: "SetEnchantment nuEnchantment:ref objectID:ref", which means:

SetEnchantment ElementaIceStaffBlizzardEnchantment ElementalIceStaff

 

WARNING 1: whatever you use the reference of base object version of the command, the enchantment is tied to the base object, which means ALL ElementalIceStaff staffs in the game will change their enchantment at once when you call this command.

 

 

WARNING 2: the enchantment is not saved in the savegame, which means every time you reload a save, the staff will revert to its original enchantment (the one assigned in CS). To avoid problems, put a "If GetGameLoaded" condition in that GameMode block, which assign the correct enchantment when game loads.

Edited by forli
Link to comment
Share on other sites

Thanks for your help directly and indirectly, as I read a previous post from last year where you and L were assisting someone with their flaming sword and took away a lot from those post. The clarification on SetEnchantment you gave helped and now that part works fine. In all I was able to go from five separate scripts just to get the staff to work how I wanted ( 1 object, 3 magic, and 1 quest script) to just one, well almost, the recharge portion of the script doesn't work, I can get the staff to work by using a separate scripted ability to recharge it but I want everything to be in the object script.

 

This is staff's currant behaviour

 

OnEquip

Adds
Petite Frost
Ice Staff Shield
Summon Blizzard
Equips Petite Frost

 

Gamemode

 

if snow is falling

(Also adds these on equip instead of the above during snow)

Grand Frost
Stronger ice shield
Summon Blizzard
Equips Grand Frost

Recharges staff (not working)

 

 

if staff has zero uses all spells and abilities are removed until recharged with soul gems (or by being in the snow (not working))

 

This is the script as of now


    ScriptName ElementalIceStaffScript

    Short powered

    short recharge

    ref user

    Begin OnEquip
         Set user To GetContainer
        If GetCurrentCharge >= 125
            Message "minimum charge    check" 1

            If GetIsCurrentWeather Snow == 1
                user.AddSpell IceStaffBlizzardShield
                user.AddSpell IceStaffBlizzardSpell
                user.AddSpell IceStaffBlizzard
                SelectPlayerSpell IceStaffBlizzardSpell            
            Else
                user.AddSpell IceStaffSpell
                user.AddSpell IceStaffShield
                user.AddSpell IceStaffBlizzard
                SelectPlayerSpell IceStaffSpell
                Message "ICE ITEMS ADDED" 1        
            endif
        endif

        If powered == 1
            Set powered to 2
            Message "powered equip check" 1    
        endif
    End

    Begin GameMode
        if user.GetEquipped ElementalIceStaff == 1
            If GetCurrentCharge <= 125
                user.RemoveSpell IceStaffSpell
                user.RemoveSpell IceStaffShield
                user.RemoveSpell IceStaffBlizzard
                user.RemoveSpell IceStaffBlizzardSpell
                user.RemoveSpell IceStaffBlizzardShield
                set recharge to 0
            endif
            if powered == 1
                If GetIsCurrentWeather Snow == 0
                    Message "no power" 1
                    user.RemoveSpell IceStaffBlizzardShield
                    user.RemoveSpell IceStaffBlizzardSpell        
                    user.AddSpell IceStaffSpell
                    user.AddSpell IceStaffShield
                    SetEnchantment ElementaIceStaffEnchantment ElementalIceStaff
                    ModCurrentCharge 3200
                    SelectPlayerSpell IceStaffSpell
                    Set powered to 0
                    Message "Powered set to 0 NORMALITY RETURNED" 1
                endif
            endif
            if powered == 0 || 2
                If GetIsCurrentWeather Snow == 1
                    Message "snow power" 1    
                    user.RemoveSpell IceStaffSpell
                    user.RemoveSpell IceStaffShield
                    user.AddSpell IceStaffBlizzardShield
                    user.AddSpell IceStaffBlizzardSpell
                    SetEnchantment ElementaIceStaffBlizzardEnchantment ElementalIceStaff
                    SelectPlayerSpell IceStaffBlizzardSpell
                    ModCurrentCharge 3200
                    set powered to 1
                    Message "Powered set to 1 BLIZZARD ITEMS ADDED" 1
                Endif
            endif
        endif    
    End

    Begin MenuMode
        if user.GetEquipped ElementalIceStaff == 1
            If GetCurrentCharge >= 125
                if recharge == 0
                    If GetIsCurrentWeather Snow == 1
                        user.AddSpell IceStaffBlizzardShield
                        user.AddSpell IceStaffBlizzardSpell
                        user.AddSpell IceStaffBlizzard
                        SelectPlayerSpell IceStaffBlizzardSpell            
                    Else
                        user.AddSpell IceStaffSpell
                        user.AddSpell IceStaffShield
                        user.AddSpell IceStaffBlizzard
                        SelectPlayerSpell IceStaffSpell
                        Message "Ice staff recharged" 1
                        set recharge to 1
                    endif
                endif
            endif
        endif            
    end

    begin OnUnEquip
        user.RemoveSpell IceStaffSpell
        user.RemoveSpell IceStaffShield
        user.RemoveSpell IceStaffBlizzard
        user.RemoveSpell IceStaffBlizzardSpell
        user.RemoveSpell IceStaffBlizzardShield
        Message "ICE ITEMS REMOVED" 1
    End

Something I just realized is that object scripts apparently don't reset every time you unequip and equip the object which is what I thought so I now had to account for that.

Hence this part

    If powered == 1
        Set powered to 2
        Message "powered equip check" 1    
    endif

So almost to the finish line just have to figure out the recharging portion and everything would be perfect.

Link to comment
Share on other sites

Careful with this:

SelectPlayerSpell IceStaffBlizzardSpell

If you're disarmed in the middle of combat and the enemy steal your staff, he may attempt to equip it and this command will try to equip the spell on the player! And if it can't find the spell, I'm not sure what happens!

Put a check

If user.GetIsReference PlayerRef

to prevent such problems.

 

 

.

GetIsCurrentWeather Snow == 1

You can remove the == 1. Not needed. Every condition is checked implicitly for "!= 0" (and since "!= 0" is equivalent to "== 1" with true/false commands, that's exactly what you need). You can use this trick also to check whatever a numeric variable is not 0 or a reference is not <null>

If someCommand    ;true if the command returns true, or returns any FormID, or any number but 0
If someNumericVariable   ;true if someNumericVariable contains any number but 0
If someRefVariable         ;true if someRefVariable contains any FormID

.

 

 

in GameMode:

if user.GetEquipped ElementalIceStaff == 1

There's another check to add. Check whatever user is <null>.

If user is <null>, and you do "user.<something>" the script may crash for good and never run again for the rest of its life (and this may explains why you can't regenerate the staff's charge).

If user    ;ensure user is not <null>
  If user.GetEquipped ElementalIceStaff   ;now we can do the "equipped" check
    ... ;code
  EndIf
EndIf

Don't put these two conditions on the same line with &&. Oblivion doesn't have shortcircuit && and ||, so it will not stop at the first condition if it's false. This means, even if user is <null> (and thus False) it will still read the second condition and will crash. Writing like my solution instead prevents this problem.

 

 

 

Also more performant and more correct version of this:

if user.GetEquipped ElementalIceStaff == 1   ;true if ANY ElementalIceStaff is equipped

is this:

if IsEquipped    ;true if THIS SPECIFIC ElementalIceStaff is equipped

If multiple staffs exists in the game world, the first condition may be true for them all, even if only one of them is equipped.
Instead the second condition is true only for the specific staff equipped by user (and it's even faster to check).

Edited by forli
Link to comment
Share on other sites

It's done!, thanks for your help Forli the script or scripts (as I should say because I still had to resort to using an automatically applied ability to recharge the staff) are working just as I want them to in game. The tips were helpful and saved me from several potential issues, I added a section to deal with the staff being recharged outside of menu mode, I didn't include it initially because I thought items could only be recharged in menu mode but I think a lot of mods do that and I can't remember but varla stones as well. I still don't understand how a script can be broken forever, and when you say forever what do you mean? once the script is complied and saved by the construction set? when it's loaded in to the game? or when it is save during game play.

 

I think I'm going to create a shock and a fire staff as well using same scripts saving on a new esp will the recharge still not work?

Any how as my first scripted mod I'm pleased with the result and may be releasing it soon again thank for help.

 

These are the scripts

Beside helpful feedback from others I'm putting these up to help others as that is how I am learning.

 

The staff

ScriptName ElementalIceStaffScript

Short powered

short recharge

ref user

Begin OnEquip
	Set user To GetContainer
	If GetCurrentCharge >= 125
		Message "minimum charge	check" 1

		If GetIsCurrentWeather Snow 
			user.AddSpell IceStaffBlizzardShield
			user.AddSpell IceStaffBlizzardSpell
			user.AddSpell IceStaffBlizzard
			If user.GetIsReference PlayerRef
				SelectPlayerSpell IceStaffBlizzardSpell
			endif				
		Else
			user.AddSpell IceStaffSpell
			user.AddSpell IceStaffShield
			user.AddSpell IceStaffBlizzard
			If user.GetIsReference PlayerRef
				SelectPlayerSpell IceStaffSpell
			endif
			Message "ICE ITEMS ADDED" 1		
		endif
	endif

	If powered == 1
		Set powered to 2
		Message "powered equip check" 1	
	endif
End

Begin GameMode
	If user  
		if IsEquipped 
			If GetCurrentCharge <= 125
				if recharge == 0
					user.RemoveSpell IceStaffSpell
					user.RemoveSpell IceStaffShield
					user.RemoveSpell IceStaffBlizzard
					user.RemoveSpell IceStaffBlizzardSpell
					user.RemoveSpell IceStaffBlizzardShield
					set recharge to 1
				endif
			endif
			If GetCurrentCharge >= 125
				if recharge == 1
					If GetIsCurrentWeather Snow 
						user.AddSpell IceStaffBlizzardShield
						user.AddSpell IceStaffBlizzardSpell
						user.AddSpell IceStaffBlizzard
						If user.GetIsReference PlayerRef
							SelectPlayerSpell IceStaffBlizzardSpell
						endif						
					Else
						user.AddSpell IceStaffSpell
						user.AddSpell IceStaffShield
						user.AddSpell IceStaffBlizzard
						If user.GetIsReference PlayerRef
							SelectPlayerSpell IceStaffSpell
						endif
						Message "Ice staff is alive" 1
						set recharge to 0
					endif
				endif
			endif
			if powered == 1
				If GetIsCurrentWeather Snow == 0
					Message "no power" 1
					user.RemoveSpell IceStaffBlizzardShield
					user.RemoveSpell IceStaffBlizzardSpell		
					user.AddSpell IceStaffSpell
					user.AddSpell IceStaffShield
					SetEnchantment ElementaIceStaffEnchantment ElementalIceStaff					
					If user.GetIsReference PlayerRef
						SelectPlayerSpell IceStaffSpell
					endif
					Set powered to 0
					Message "Powered set to 0 NORMALITY RETURNED" 1
				endif
			endif
			if powered == 0 || 2
				If GetIsCurrentWeather Snow 
					Message "snow power" 1	
					user.RemoveSpell IceStaffSpell
					user.RemoveSpell IceStaffShield
					user.AddSpell IceStaffBlizzardShield
					user.AddSpell IceStaffBlizzardSpell
					SetEnchantment ElementaIceStaffBlizzardEnchantment ElementalIceStaff
					user.AddSpell RechargeWeaponAbility
					If user.GetIsReference PlayerRef
						SelectPlayerSpell IceStaffBlizzardSpell
					endif				
					set powered to 1
					Message "Powered set to 1 BLIZZARD ITEMS ADDED" 1
				Endif
			endif
		endif
	endif	
End

Begin MenuMode
	if IsEquipped 
		If GetCurrentCharge >= 125
			if recharge == 1
				If GetIsCurrentWeather Snow 
					user.AddSpell IceStaffBlizzardShield
					user.AddSpell IceStaffBlizzardSpell
					user.AddSpell IceStaffBlizzard
					If user.GetIsReference PlayerRef
						SelectPlayerSpell IceStaffBlizzardSpell
					endif				
				Else
					user.AddSpell IceStaffSpell
					user.AddSpell IceStaffShield
					user.AddSpell IceStaffBlizzard
					If user.GetIsReference PlayerRef
						SelectPlayerSpell IceStaffSpell
					endif
					Message "Ice staff is alive" 1
					set recharge to 0
				endif
			endif
		endif
	endif			
end

begin OnUnEquip
	user.RemoveSpell IceStaffSpell
	user.RemoveSpell IceStaffShield
	user.RemoveSpell IceStaffBlizzard
	user.RemoveSpell IceStaffBlizzardSpell
	user.RemoveSpell IceStaffBlizzardShield
	Message "ICE ITEMS REMOVED" 1
End

The recharge spell

scriptname RechargeWeapon

float MaxCharge

ref staff

Begin ScriptEffectStart
	set staff to GetEquippedObject 16
	Set MaxCharge to GetObjectCharge staff
	SetEquippedCurrentCharge MaxCharge 16
End

begin ScriptEffectUpdate
	dispel RechargeWeaponAbility
end

Begin ScriptEffectFinish

End
Link to comment
Share on other sites

A script may crash and stay broken for good during the execution.

There are many possible way to break a script, mainly by having a condition with an unchecked reference variable. This is a generic example:

If refVar.IsActor   ;refVar has not been checked for null before this

This cause no error when compiling/saving the script and the esp in CS.

When the game runs the script, if refVar is null, the script break and may stay that way for good, with no way to make it run again.

 

If the script is an Object/Magic script, it won't be a permanent damage, as the problem only affect that specific instance of the object/spell/function, which can be destroyed. Other objects with the same script are safe (but of course, they may crash in the same way, if their ref variable is null as well).

 

If the script is a Quest scripts the damage is permanent, as Quests can't be destroyed or resetted, and the problem can only be fixed by reloading a previous save, or if you already saved with the frozen script, you can only the game, disable the esp, make a clean save, and enable the esp back.

 

In the case of your staff, even if your current staff's script is broken, you can always drop/sell it and get another one (even with AddItem).

 

 

 

Of course: the best way is preventing such problems, by checking the variable before using it:

If refVariable
  If refVariable.someCommand
    ...
  EndIf
EndIf

This way, you're safe 100% of times, no matter what.

 

 

 

Of course 2: you can avoid the check if you're 100% SURE the variable won't be null (maybe you just assigned it or the logic of your code is good enough to allow such assumption).

Example:

Set refVariable To <something>
If refVariable.someCommand
 ...
EndIf

This is safe as long as <something> is an EditorID (so the variable is surely not null), or if <something> is a command/function which NEVER return null.

Example: GetCrosshairRef is a function which may return null, if you're not looking at any object.

GetParentCell never return null if called on an object instance, as any instance exists in the gameworld and is contained in a cell (NOTE: objects in containers/inventories are not really instances, and they are handled differently by the game. These objects will transform into real instances when they are dropped from the container/inventory).

 

 

 

In your case, to make an example:

...
Begin OnEquip
  Set user To GetContainer
  ...  ;user is not checked for null
End

The logic here is robust enough: only actors can equip an object and fire the OnEquip event, so you're sure the object is placed in some actor's inventory when you do GetContainer, which will then surely returns a valid reference, and you don't strictly need to check if the variable is null (checking it for null is not a bad idea anyway).

 

 

 

In this case:

...
Begin GameMode
  If user
    ...
  EndIf
End 

In this case, the check is necessary, as GameMode block run continuously when not in Menus, even when the object is not equipped, so the variable "user" may be null at any time here.

 

 

 

Another case in your code:

Begin MenuMode
  if IsEquipped 
    ...  ;you can use "user" without checking for null
  EndIf
End

Here the logic is safe too, as IsEquipped means the object has been equipped, and this means the OnEquip block must have fired at some point before this check, and so the variable "user" has surely been assigned to some actor (as above, checking if user is null is not a bad idea anyway).

 

 

 

I hope this solve most of your doubts!

Edited by forli
Link to comment
Share on other sites

Alas once again my script isn't working, with the help of forli I wrote an amazing script (amazing to me anyways) something I would have had no idea how to do a month ago and after that was pleased with my work but then I thought why not make at least a halfway decent looking staff to go with it and so I did as you can see here

7342688-1499573035.jpg

 

 

So the staff glows now and glow in the dark weapons are not stealthy so the idea that you're sneaking through the darkness with a glowing stick on your back and yet no one sees you is a bit of a immersion breaker, so I added this

			set light to firestaffuser.GetActorLightAmount 

			if light < 25
				if firestaffuser.HasSpell Glow == 0
					firestaffuser.AddSpell Glow
				endif
			endif			
			if light => 25
				if firestaffuser.HasSpell Glow == 1
					firestaffuser.RemoveSpell Glow		
				endif
			endif
			Message "Player's light %.2f " light

The spell is glow an ability that drains sneak 20 pts

I put the sensor just for testing purposes only and would be removed along with all other messages

 

The light sensor and display message work fine but the part that adds the spell does not. Once light reaches <25 it takes about a minute before the message that the spell was added randomly shows up but when I look at the active effects tab it isn't there. I understand that when there are a lot of messages they get queued and sometimes the message that is being displayed is lagging way behind what operation the script is currently on but all other spells are added just fine so I believe its something I'm doing wrong.

 

 

 

The full script

ScriptName ElementalFireStaffScript

Short firepowered

short firerecharge

ref firestaffuser

Float light

Begin OnEquip
	Set firestaffuser To GetContainer
	If GetCurrentCharge >= 125
		Message "minimum charge	check" 1

		If GetIsCurrentWeather OblivionStormTamriel ;|| OblivionStormTamrielMQ16 ;|| OblivionDefault || OblivionElectrical || OblivionMountainFog || OblivionSigil || OblivionStormOblivion 
			firestaffuser.AddSpell FireStaffOblivionShield
			firestaffuser.AddSpell FireStaffOblivionSpell
			firestaffuser.AddSpell FireStaffOblivion
			If firestaffuser.GetIsReference PlayerRef
				SelectPlayerSpell FireStaffOblivionSpell
			endif				
		Else
			firestaffuser.AddSpell FireStaffSpell
			firestaffuser.AddSpell FireStaffShield
			firestaffuser.AddSpell FireStaffOblivion
			If firestaffuser.GetIsReference PlayerRef
				SelectPlayerSpell FireStaffSpell
			endif
			Message "Fire ITEMS ADDED" 1		
		endif
	endif

	If firepowered == 1
		Set firepowered to 2
		Message "firepowered equip check" 1	
	endif
End

Begin GameMode
	If firestaffuser  
		if IsEquipped 
			If GetCurrentCharge <= 125
				if firerecharge == 0
					firestaffuser.RemoveSpell FireStaffSpell
					firestaffuser.RemoveSpell FireStaffShield
					firestaffuser.RemoveSpell FireStaffOblivion
					firestaffuser.RemoveSpell FireStaffOblivionSpell
					firestaffuser.RemoveSpell FireStaffOblivionShield
					set firerecharge to 1
				endif
			endif
			If GetCurrentCharge >= 125
				if firerecharge == 1
					If firestaffuser.IsInOblivion
					elseIf GetIsCurrentWeather OblivionStormTamriel ;|| OblivionDefault || OblivionElectrical || OblivionMountainFog || OblivionSigil || OblivionStormOblivion                                              						
						firestaffuser.AddSpell FireStaffOblivionShield
						firestaffuser.AddSpell FireStaffOblivionSpell
						firestaffuser.AddSpell FireStaffOblivion
						If firestaffuser.GetIsReference PlayerRef
							SelectPlayerSpell FireStaffOblivionSpell
						endif						
					Else
						firestaffuser.AddSpell FireStaffSpell
						firestaffuser.AddSpell FireStaffShield
						firestaffuser.AddSpell FireStaffOblivion
						If firestaffuser.GetIsReference PlayerRef
							SelectPlayerSpell FireStaffSpell
						endif
						Message "Fire staff is alive" 1
						set firerecharge to 0
					endif
				endif
			endif
			if firepowered == 1
				if firestaffuser.GetEquipped ElementalFireStaff == 1
					If GetIsCurrentWeather OblivionStormTamriel == 0  ;|| OblivionStormTamrielMQ16 || OblivionDefault || OblivionElectrical || OblivionMountainFog || OblivionSigil || OblivionStormOblivion == 0
						Message "no power" 1
						firestaffuser.RemoveSpell FireStaffOblivionShield
						firestaffuser.RemoveSpell FireStaffOblivionSpell		
						firestaffuser.AddSpell FireStaffSpell
						firestaffuser.AddSpell FireStaffShield
						SetEnchantment ElementaFireStaffEnchantment ElementalFireStaff					
						If firestaffuser.GetIsReference PlayerRef
							SelectPlayerSpell FireStaffSpell
						endif
						Set firepowered to 0
						Message "Powered set to 0 NORMALITY RETURNED" 1
					endif
				endif
			endif
			if firepowered == 0 || 2
				if firestaffuser.GetEquipped ElementalFireStaff == 1
					If GetIsCurrentWeather OblivionStormTamriel ;|| OblivionStormTamrielMQ16 || OblivionDefault || OblivionElectrical || OblivionMountainFog || OblivionSigil || OblivionStormOblivion 
						Message "fire power" 1	
						firestaffuser.RemoveSpell FireStaffSpell
						firestaffuser.RemoveSpell FireStaffShield
						firestaffuser.AddSpell FireStaffOblivionShield
						firestaffuser.AddSpell FireStaffOblivionSpell
						SetEnchantment ElementaFireStaffOblivionEnchantment ElementalFireStaff
						firestaffuser.AddSpell RechargeWeaponAbility
						If firestaffuser.GetIsReference PlayerRef
							SelectPlayerSpell FireStaffOblivionSpell
						endif				
						set firepowered to 1
						Message "Powered set to 1 Oblivion ITEMS ADDED" 1
					endif
				Endif
			endif
			set light to firestaffuser.GetActorLightAmount 

			if light < 25
				if firestaffuser.HasSpell Glow == 0
					firestaffuser.AddSpell Glow
				endif
			endif			
			if light => 25
				if firestaffuser.HasSpell Glow == 1
					firestaffuser.RemoveSpell Glow		
				endif
			endif
			Message "Player's light %.2f " light
		endif
	endif
End

Begin MenuMode
	if IsEquipped 
		If GetCurrentCharge >= 125
			if firerecharge == 1
				If GetIsCurrentWeather OblivionStormTamriel ;|| OblivionStormTamrielMQ16 || OblivionDefault || OblivionElectrical || OblivionMountainFog || OblivionSigil || OblivionStormOblivion 
					firestaffuser.AddSpell FireStaffOblivionShield
					firestaffuser.AddSpell FireStaffOblivionSpell
					firestaffuser.AddSpell FireStaffOblivion
					If firestaffuser.GetIsReference PlayerRef
						SelectPlayerSpell FireStaffOblivionSpell
					endif				
				Else
					firestaffuser.AddSpell FireStaffSpell
					firestaffuser.AddSpell FireStaffShield
					firestaffuser.AddSpell FireStaffOblivion
					If firestaffuser.GetIsReference PlayerRef
						SelectPlayerSpell FireStaffSpell
					endif
					Message "Fire staff is alive" 1
					set firerecharge to 0
				endif
			endif		
		endif
	endif	
end

begin OnUnEquip
	firestaffuser.RemoveSpell Glow		
	firestaffuser.RemoveSpell FireStaffSpell
	firestaffuser.RemoveSpell FireStaffShield
	firestaffuser.RemoveSpell FireStaffOblivion
	firestaffuser.RemoveSpell FireStaffOblivionSpell
	firestaffuser.RemoveSpell FireStaffOblivionShield
	Message "Fire ITEMS REMOVED" 1
End
Link to comment
Share on other sites

Nope, that's not a "message queueing problem".

 

set light to firestaffuser.GetActorLightAmount 

if light < 25
	if firestaffuser.HasSpell Glow == 0
		firestaffuser.AddSpell Glow
	endif
endif			
if light => 25
	if firestaffuser.HasSpell Glow == 1
		firestaffuser.RemoveSpell Glow		
	endif
endif
Message "Player's light %.2f " light
Let me fix and optimize this for you:

set light to firestaffuser.GetActorLightAmount 

if light < 25
	;AddSpell command and its variants already include the "HasSpell" check, and return 1 if succesfully added, 0 if already present
	firestaffuser.AddSpellNS Glow   ;the -NS version does not show up the message "spell X added to spellbook".
else ;if condition is false, then surely light >= 25
	;same for RemoveSpell command and its variants
	firestaffuser.RemoveSpellNS Glow
endif
Message "Player's light %.2f " light

 

Also this check:

if light => 25
is an error. It should be:

if light >= 25    ;equal character must be placed AFTER greater character
But in the solution this check is not even necessary Edited by forli
Link to comment
Share on other sites

Well I uploaded the mod yesterday I called it elemental staves. Although I really wanted it in there I left out the part about draining sneak from the mod as no matter what I tried it simply did not work, though its still in the fire staff script just its hidden with semi colons. Besides that it works great, so if anyone wants to see the script in action you know what to do.

 

I'm gone.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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