ChewGun Posted August 12, 2019 Share Posted August 12, 2019 So, the player has a piece of an armor equipped which has an attached script and some properties defined Scriptname myArmorScript extends ObjectReference Int Property armormod AutoIs it possible to alter those from another script and how if so? They're stored in save file and can be edited, but can it be done with papyrus scripting? Link to comment Share on other sites More sharing options...
IsharaMeradin Posted August 12, 2019 Share Posted August 12, 2019 Yes it can be done. The second script needs to call upon the first script. An example done as a property: ScriptName myOtherScript Extends Quest myArmorScript Property myAS Auto {assign the correct object holding the script you want to use} ;note will only work with the one instances. ;how to access Function SomeFunction() myAS.armormod = 23 EndFunction I must stress that this process only works for the one instance that is linked. If you have multiple instances of the same armor piece each with their own instance of the script, you will be better off editing that script and have them link to a single other script (like a quest script) where you manipulate and return the new value via a called function. Example: Scriptname myArmorScript extends ObjectReference Int Property armormod Auto myOtherScript Property myOS Auto {assign the object holding the target script} Event OnEquipped(Actor akActor) armormod = myOS.GetNewValue(armormod) EndEvent ScriptName myOtherScript extends Quest Int Function GetNewValue(Int StartValue) Int Num = (StartValue * 2) Return Num EndFunction Link to comment Share on other sites More sharing options...
ChewGun Posted August 12, 2019 Author Share Posted August 12, 2019 I must stress that this process only works for the one instance that is linked. If you have multiple instances of the same armor piece each with their own instance of the script, you will be better off editing that script and have them link to a single other script (like a quest script) where you manipulate and return the new value via a called function.Well, I have exactly that situation, but I do know one thing for sure: the script I'm interested in is attached to an armor worn by PC. How can I target exactly this instance of a script? Link to comment Share on other sites More sharing options...
IsharaMeradin Posted August 12, 2019 Share Posted August 12, 2019 That would be difficult because there is no specific object reference ID for items while in the inventory unless it is already persistent for some reason. If you can some how make the armor piece persistent, then OnObjectEquipped on a player alias script could be used to grab the persistent ObjectReference via the akReference parameter. That could then be cast to the script. Example: myArmorScript myAS Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference) If akReference ; valid persistent object reference myAS = akReference as myArmorScript ;then do whatever you need with any properties / functions on the armor script EndIf EndEvent But if the armor piece is not persistent, that won't work (and it is just theory anyway as I've not actually had to grab a script on an equipped object). You could try to cast the akBaseObject into the script. But there is no guarantee that that will do anything or if it does do something it may not always do it with the desired specific instance. Testing would be required to see what happens. At the very least, you have a method to test and try out. Hopefully, it can work for you. Link to comment Share on other sites More sharing options...
ChewGun Posted August 13, 2019 Author Share Posted August 13, 2019 That would be difficult because there is no specific object reference ID for items while in the inventory unless it is already persistent for some reason.According to the info that I've googled, every item with an attached script is persistent by default. Isn't that so? If you can some how make the armor piece persistent, then OnObjectEquipped on a player alias script could be used to grab the persistent ObjectReference via the akReference parameter. That could then be cast to the script. Example: myArmorScript myAS Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference) If akReference ; valid persistent object reference myAS = akReference as myArmorScript ;then do whatever you need with any properties / functions on the armor script EndIf EndEvent I don't understand this, won't it just execute "whatever you need with any properties / functions on the armor script" part every time the player equips an item with that script? If so, that's not what I'm looking for... I've tried to put these different lines of code under OnEquip event with check whether the armor is equipped by the player (the check itself works, I've attached debug.notification to it) Scriptname myArmorScript extends ObjectReference ... SetFormValue(akActor, "myarmorscriptinstance", Self) Scriptname myArmorScript extends ObjectReference ... SetFormValue(akActor, "myarmorscriptinstance", Self as Form) But GetFormValue(akActor, "myarmorscriptinstance") When launched from other script after the armor was equipped returns 'none'.Can I manually check that value somehow? I was unable to locate it or any other values set by papyrusutils's SetFormValue (from other mods) in the save file by their name... Also Scriptname myArmorScript extends ObjectReference Debug.Notification(Self) Returns '[myArmorScript', is it normal? Also, maybe the GetLinkedRef() from SKSE is what I need?But, for some reason, the script won't compile because that function is unknown, do I have to manually include something in my script for it to work? SKSE's scripts 'source' folder contents is referenced in papyruscompilerplus already... Link to comment Share on other sites More sharing options...
IsharaMeradin Posted August 13, 2019 Share Posted August 13, 2019 Perhaps if you explained in more detail what it is that you want to do. Not just a single step in the process but the whole thing. There is almost always more than one way to do the same thing but knowing which is best... Link to comment Share on other sites More sharing options...
Recommended Posts