Jump to content

Weird script getting stuck.


Shaidon7

Recommended Posts

I'm working on a weapon script that add and remove an invisibility spell (ability) when ever who had it equipped enter in sneaking mode.

It's working flawless until I noticed that even with the weapon unequipped or dropped, the script remains. The character can go stealth sneaking and normal don't matter what he have equipped.

It's just don't make sense! At least, I can't figure out. The effect don't work if I just added the item, just when it is proper equipped at first time.

It's like the script got stuck, because the ability should only be added if the character was sneaking. I tested it with different saves and a new one, and all have this bug.

 

I can fix it by adding another condition to work only if the weapon reference is equipped, but still the doubt remains. Why is the entire script still working even without the scripted item?

Link to comment
Share on other sites

Is the script still working or is the ability just not getting removed?

 

You'd have to post the script to get any real help, but my rough guess is you don't have the blocks in place (on unequip) to remove the ability.

 

it should look something like this:

 

scn ...  

short hasequipped  

begin onequip player  
set hasequipped to 1  
end  

begin onunequip player 
set hasequipped to 0  
if player.hasspell ... > 0
 player.removespell ...  
endif  
end  

begin gamemode  
if hasequipped > 0  
 if player.issneaking > 0 
  if player.hasspell ... < 1  
player.addspell ...  
  endif  
 else  
  if player.hasspell ... > 1 
player.removespell ... 
  endif 
 endif 
endif 
end

Edited by Skevitj
Link to comment
Share on other sites

That is the weird part! The ability is getting removed, or else the character should be invisible don't matter if standing or crounching, since there is no condition on the spell making. The condition to make it work is only on the script, so how can it work without the weapon?

 

Here is my script:

ref iUser
short iDoOnceTO

Begin OnEquip

set iUser to GetContainer

End

Begin GameMode

;if iUser.GetEquipped EditorIDWeaponName == 1
	if iDoOnceTO == 1 && iUser.IsSneaking == 1
		iUser.AddSpell EditorIDAbilitySpellName
		set iDoOnceTO to 0
	elseif iDoOnceTO == 0 && iUser.IsSneaking == 0
		iUser.RemoveSpell EditorIDAbilitySpellName
		set iDoOnceTO to 1
	endif
;endif

End

Begin OnUnequip

iUser.RemoveSpell EditorIDAbilitySpellName

End

 

EditorIDAbilitySpellName is a spell selected as ability with only Invisibility.

Now adding the condition for the EditorIDWeaponName equipped, it will work, like I said, but without it, the script keep running like I had the weapon, don't matter how my character is equipped.

Link to comment
Share on other sites

Ya, the reason for that is that you have nothing in there to clear the iUser variable, so once it has been equipped once, your script will track that target constantly, every frame the item is in a NPC's inventory. The getequipped check is a fine solution for what you're trying to achieve.
Link to comment
Share on other sites

Hmmm... and how can I clean the reference iUser. By the way, I'm using the same reference to any script that require that.

Maybe adding a "set iUser to" something else on the OnUnEquip block?

 

And, it's considered to be bad scripting by adding the condition for for the weapons be equipped as the solution? Because I don't want the save to get bloated with a lot of useless pieces of script. :tongue:

Link to comment
Share on other sites

The neatest way is just to set it in the onequip block and have a variable which is set in the onequip block and cleared in the onunequip block which has a value >0 when the iUser is valid (ie equipped) and <1 when invalid.

 

See the script I wrote, basically you just want to have your own version of what I did with the hasequipped variable.

 

EDIT: I just saw your save game comment: It's completely wrong, nothing you have in the script will cause a save game bloat. An extra few lines, or even a hundred extra would cause a negligible increase in the size of the game files. You should be using the base object for the test. If you're creating dynamic, persistent references to use they that's incredibly bad practice and it completely useless anyway.

Edited by Skevitj
Link to comment
Share on other sites

OK, so I did changed the script. I won't use OBSE, and your script wasn't removing the ability when standing, so I did a few changes:

 

ref iUser
short iCTOequip

Begin OnAdd

set iUser to GetContainer

End

Begin OnEquip

set iCTOequip to 1

End

Begin OnUnEquip

set iCTOequip to 0
if iUser.IsSpellTargetEditorIDAbilitySpellName > 0
	iUser.RemoveSpell EditorIDAbilitySpellName
endif

End

Begin GameMode

if iCTOequip > 0  
	if iUser.IsSneaking == 1
		if iUser.IsSpellTarget EditorIDAbilitySpellName == 0
			iUser.AddSpell EditorIDAbilitySpellName
		endif  
	elseif iUser.IsSneaking == 0
		if iUser.IsSpellTarget EditorIDAbilitySpellName == 1 
			iUser.RemoveSpell EditorIDAbilitySpellName
		endif
	endif
endif

End

 

The OnAdd block is required to make it work on NPCs, since they seems to skip OnEquip blocks.

 

More 3 things:

1 - It's necessary to use > and < isntead of ==?. Because I'm not sure if a spell can be added more then once.

2 - the condition on the OnUnEquip block is required?

3 - so, this version of the script is more clean right?

Link to comment
Share on other sites

I've done a fair bit of programming and find it just a useful practice to use <> opposed to =, mostly cause I'm dealing with floats. == should be fine for simple bool tests though.

 

Once again, I just check to make sure they have the spell when it is removed, and don't have it when added. It's mostly redundant, but shouldn't cause problems.

 

Ya, it's looking good, assuming everything works as intended.

Link to comment
Share on other sites

OK, thanks and kudos! :thumbsup:

 

Now that I got more knowledge about Bethesda scripting, gonna rewrite the other working scripts. :sweat:

 

p.s.: geez, more and more work to be done in my Fallout 3 mod...

Link to comment
Share on other sites

  • Recently Browsing   0 members

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