Jump to content

Help with Scripting an object effect on to a weapon


drithius

Recommended Posts

I've been looking to patch Dragbody's CNR RioT Scutum (shield) to include DR and -1 agility. However, I'm having a couple issues:

 

ref rSelf

Begin OnEquip
set rSelf to GetContainer
rSelf.modav DamageThreshold 10
rSelf.modav Agility -1
End


Begin OnUnEquip
set rSelf to GetContainer
rSelf.modav DamageThreshold -10
rSelf.modav Agility 1
End

 

The above has two problems that I'm aware of:

1. if a person already has a shield equipped when starting up the patch, they'll be at a permanent stat deficit.

2. OnUnEquip doesn't work for an item getting dropped while equipped :(

 

Any pointers?

Link to comment
Share on other sites

How about something like this...

ref rSelf
int iStatus

Begin OnEquip
	set rSelf to GetContainer
	rSelf.modav DamageThreshold 10
	rSelf.modav Agility -1
	set iStatus to 1
End


Begin OnUnEquip
	if iStatus
		set rSelf to GetContainer
		rSelf.modav DamageThreshold -10
		rSelf.modav Agility 1
		set iStatus to 0
	endif
End

Begin OnDrop
	if iStatus && rSelf != 0
		rSelf.modav DamageThreshold -10
		rSelf.modav Agility 1
		set iStatus to 0
	endif
end
Link to comment
Share on other sites

Hey Claustro.

 

That's really elegant logic and it should work...

 

...but I've tried all sorts of things and that final IF statement refuses to let anything through. Even if I break it up into two separate IF statements, the characters stats don't revert back to normal when Equipping --> Dropping. I don't see why it's not working!

Edited by drithius
Link to comment
Share on other sites

Hey Claustro.

 

That's really elegant logic and it should work...

 

...but I've tried all sorts of things and that final IF statement refuses to let anything through. Even if I break it up into two separate IF statements, the characters stats don't revert back to normal when Equipping --> Dropping. I don't see why it's not working!

That's really odd :confused:. Hmm...

 

The script must be crashing at some point.. you could try this instead:

ref rSelf
int iStatus

Begin OnEquip
	set rSelf to GetContainer
	if rSelf != 0
		rSelf.modav DamageThreshold 10
		rSelf.modav Agility -1
		set iStatus to 1
	endif
End


Begin OnUnEquip
	if iStatus && rSelf != 0
		rSelf.modav DamageThreshold -10
		rSelf.modav Agility 1
		set iStatus to 0
	endif
End

Begin OnDrop
	if iStatus && rSelf != 0
		rSelf.modav DamageThreshold -10
		rSelf.modav Agility 1
		set iStatus to 0
	endif
end

Also, if you don't mind your mod requiring NVSE you could use IsFormValid and/or IsReference to ensure that the variable is not invalid.

 

If none of that works there's probably something else messing with the item externally.

Edited by claustromaniac
Link to comment
Share on other sites

That did it! Thank you, thank you!

 

The added error checking saved the day - I'm just really confused as to why/how since the OnDrop block is identical. So strange.

 

Thank you again, I was really at my wit's end with this.

 

Very glad :cool:

 

Since I was quite sure the script should be working, I just figured the reference variable was - for some alien reason - not storing a valid reference at some point when the script tried to call those ModAV functions in the OnEquip and/or the OnUnequip block. That caused the script to crash, thus preventing the OnDrop block from running altogether.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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