Jump to content

[LE] [Help Request] Getting NPC to equip an Alias item


Sporny

Recommended Posts

Hello modders, I have run into an issue and I can't find a solution anywhere.

 

I'm trying to get an NPC to equip an item created as an alias in his inventory.

 

I've been trying to tinker with an EquipItem script either on the item/NPC/Alias but nothing seems to work. Does anyone have any idea how to script this, or to design it in a better way?

 

Much appreciated for your time and help!

 

https://ibb.co/jP20sR

Link to comment
Share on other sites

I have looked at the discussion page prior to posting, but the script won't compile. For reference:

 

Scriptname Sporny_VikundEquipScriptVer2 extends ObjectReference  


Quest Property Sporny_BladewindHallsQuest  Auto  


Actor Property Sporny_BWH_Vikund  Auto  


ObjectReference Property VikundREF  Auto  


Alias Property Casque  Auto  


Event OnContainerChanged(ObjectReference newContainer, ObjectReference oldContainer)
if (newContainer == Sporny_BWH_Vikund)
Sporny_BWH_Vikund.GetReference().EquipItem(Casque.GetReference().GetBaseObject())
Endif
EndEvent

The errors I'm getting are:

 

...(13,18): GetReference is not a function or does not exist
...(13,50): GetReference is not a function or does not exist
...(13,65): none is not a known user-defined type
...(13,33): none is not a known user-defined type
Going off of the Papyrus tutorials on the wiki and the topics touching on the subject I'm not sure what's going on but I believe it might be a scripting/property concept I haven't fully grasped. Any ideas?
Link to comment
Share on other sites

Sporny_BWH_Vikund is already defined as an actor reference in your properties. GetReference() is an alias function and therefore neither can or should be used there. So instead:

Event OnContainerChanged(ObjectReference newContainer, ObjectReference oldContainer)
if (newContainer == Sporny_BWH_Vikund)
Sporny_BWH_Vikund.EquipItem(Casque.GetReference().GetBaseObject())
Endif
EndEvent
Edited by wormple12
Link to comment
Share on other sites

Thanks taking the time to help me out and explain Wormple. Getting rid of GetReference on the actor got rid of one pair of errors, but I'm still getting errors on the GetReference on the Casque. Any ideas?

 

...(13,35): GetReference is not a function or does not exist
...(13,50): none is not a known user-defined type
Link to comment
Share on other sites

Oh, I didn't see it the first time around. There's two different alias property types, one called Alias and one called ReferenceAlias. In almost all cases, ReferenceAlias is the one you're looking for. So Casque should be a ReferenceAlias property instead :smile:

Edited by wormple12
Link to comment
Share on other sites

It worked! Changing up the property did it, along with the stuff you linked at the discussion page.

 

Checking for the container change didn't quite work when I spawned the alias in the actor, so I placed it At the actor and used AddItem to put it in his inventory OnInit, but that made for some funky stuff. So here is what I did in the end:

Scriptname Sporny_VikundCasqueEquipScript extends ObjectReference  

ReferenceAlias Property Alias_Casque  Auto  

ReferenceAlias Property Alias_Vikund  Auto  

Quest Property Sporny_BladewindHallsQuest  Auto 

int count 

Event OnInit()
if count == 0
(Alias_Vikund.GetReference() as Actor).EquipItem(Alias_Casque.GetReference().GetBaseObject())
count = count + 1
Endif
EndEvent

There is probably a better way to do this, but it works :D

 

Thanks a lot for the help and attention Wormple. Do you know any good resources to read up on Properties and Scripting in general?

Link to comment
Share on other sites

Instead of

count = count + 1

use

count += 1

It does exactly the same, but is a cleaner way to write it at least :) I'm not sure you'd even need to use a integer check like that. OnInit usually only fires once ever, I think, but you might've done it for a reason I've forgotten.

 

If you want to learn the basics of something in the CK, always check out the wiki tutorials.

 

Apart from that, I have a few other favorite pages on the wiki, that it doesn't link to itself:

  • Script object map. From this page, you can just click whatever type of object you want to add a script to, and it will lead you to a complete list of functions that can be used by that type of object. Remember that if a script object A extends another script object B which extends another script object C, then B can also use every function that C can, and A can use every function that both B and C can.
  • Operator References and keyword references. This page explains the basics you need to know about math operators in scripts, as well as all the common script keywords like "bools", "integers", "while loops" and "states".
  • At last, there are many uses for having two different scripts that you access and edit from within each other. Therefore, I have had much use of this small how-to-guide.
Link to comment
Share on other sites

  • Recently Browsing   0 members

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