Jump to content

Weapon script compiles but doesn't seem to do anything


Recommended Posts

So I've attached the following script to a test weapon. The idea is that it's supposed to modify the value of the weapon based on whether it has been upgraded or not. It compiles just fine but when tested in game doesn't do anything. I can drop the weapon, pick it up, remove it from a container... nada.

 

Here's the full script:

 

Scriptname SMEC_AddValueWeaponT extends ObjectReference  
{Modifies the object's value in line with its upgrades}


WEAPON Property SMEC_OldWeapon  Auto  
{Gets the weapon's base value}


Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
Float SMEC_Modifier
Float SMEC_NewValue
SMEC_Modifier = Self.GetItemHealthPercent() - 1
SMEC_NewValue = SMEC_OldWeapon.GetGoldValue() * (2 * SMEC_Modifier)
SMEC_OldWeapon = akItemReference.GetBaseObject() as Weapon
Self.SetGoldValue(SMEC_NewValue as Int)
endEvent
I'm a total papyrus rookie so I'm not certain what I'm doing wrong here. I've also tried the following variant:
Scriptname SMEC_AddValueWeaponT extends ObjectReference  
{Modifies the object's value in line with its upgrades}


WEAPON Property SMEC_OldWeapon  Auto  
{Gets the weapon's base value}


Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
Float SMEC_Modifier
Float SMEC_NewValue
SMEC_Modifier = Self.GetItemHealthPercent() - 1
SMEC_NewValue = SMEC_OldWeapon.GetGoldValue() * (2 * SMEC_Modifier)
SMEC_OldWeapon = akItemReference.GetBaseObject() as Weapon
akItemReference.SetGoldValue(SMEC_NewValue as Int)
endEvent
But it nets the same total lack of results.

It it possible that I need to start a new game or find a new instance of the weapon to get this script to fire? Will it just not be attached to an existing item in an existing save? Is there something else I'm doing wrong? Is it that I'm drawing on an incomplete function in SKSE64? Am I misusing OnItemAdded?
Thanks in advance!
Edited by ElizabethSterling
Link to comment
Share on other sites

Okay, as I realised I was totally misusing OnItemAdded I switched up the script to the following and it still does nothing:

Scriptname SMEC_AddValueWeaponT extends ObjectReference  
{Modifies the object's value in line with its upgrades}


WEAPON Property SMEC_OldWeapon  Auto  
{Gets the weapon's base value}


Event OnEquipped(Actor akActor)
if akActor == Game.GetPlayer()
Float SMEC_Modifier
Float SMEC_NewValue
SMEC_Modifier = Self.GetItemHealthPercent() - 1
SMEC_OldWeapon = Self.GetBaseObject() as Weapon
SMEC_NewValue = (SMEC_OldWeapon.GetGoldValue() * (2 * SMEC_Modifier)) + 1
Self.SetGoldValue(SMEC_NewValue as Int)
endIf
endEvent

Is SetGoldValue just not working at this time? I added a debug messagebox to the code that read out SMEC_NewValue when the weapon was equipped and that worked as expected so I suspect that SetGoldValue just hasn't been implemented in SKSE64 yet.

Edited by ElizabethSterling
Link to comment
Share on other sites

If you are able to successfully get the gold value you should be able to set the gold value. Wouldn't make sense for one to work and the other not.

 

Try using SMEC_OldWeapon to set the gold instead of using self. After all it is what you used to get the gold value in the first place.

 

i.e.

SMEC_OldWeapon.SetGoldValue(SMEC_NewValue as Int)

Link to comment
Share on other sites

The thing is that SetGoldValue is an SKSE command and GetGoldValue isn't so there's every chance that SetGoldValue simply hasn't been made functional again yet. Plus SMEC_OldWeapon is a base item reference and Self is a game object and SetGoldValue; aside from the fact that changing the base object would throw off all future calculations according to its wiki entry SetGoldValue only works on extant objects, not base items.

Edited by ElizabethSterling
Link to comment
Share on other sites

SetGoldValue is on the FORM script. Thus it edits the base form rather than specific object references. It even states on the wiki that it edits the base form (see spoiler below for specific line of text). And it will throw off all future instances of said object during the current session. That is how it is intended to work for Skyrim. F4SE has a version that can also work on specific instances, perhaps that is where confusion lies?

 

 

 

 

 

  • This function is performed on a base Form, meaning changes will not save.

 

 

 

At any rate, try it with the base form to see whether or not it works that way. If it does not, report that as something to be looked into by the SKSE64 team.

Link to comment
Share on other sites

That one I'm downright counting on. I want to offset the price based on what the basic item costs, not the reference object. Guess I'm going to have to find another way to modify the reference object item price though. I've been experimenting with the idea of a dummy enchantment...

Edited by ElizabethSterling
Link to comment
Share on other sites

  • Recently Browsing   0 members

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