Jump to content

DOWNLOAD MODS

Are you looking for something shiny for your load order? We have many exclusive mods and resources you won't find anywhere else. Start your search now...

LEARN MODDING

Ready to try your hand at making your own mod creations? Visit the Enclave, the original ES/FO modding school, and learn the tricks of the trade from veteran modders...

JOIN THE ALLIANCE

Membership is free and registering unlocks image galleries, project hosting, live chat, unlimited downloads, & more...

Get the equipped weapon ObjectReference


Eaglemania
 Share

Recommended Posts

Hi there, just registered because the last week all i been doing with papyrus was hitting walls, hard ones, repeately banging my head at them just won't work. :ouch:

Before i go on an even bigger rant, i just go to the question i'm asking myself right now.

Is there some way to get the currently equipped weapon by an actor as an object reference?

The goal of this is:

I made a sword, which has an enchantment, which has a magic effect, which has a script attached to it. This script counts how often the magic effect is applied to enemies, and do something ones the count reached a certain number. So far the script works great, however what i want it to do is .play (and .stop) an effect shader on the sword.

Function Play(ObjectReference akObject, float afDuration)

Plays this magic effect shader on the specified object for the specified duration in seconds.

there is the problem, i have no idea how to get to the ObjectReference.

I tried .GetEquippedWeapon and cast that as ObjectReference, which i'm sure is utterly stupid, but noobs try stupid things.

I think i can get the object reference with the OnObjectEquipped event, but i can't check this before the magic effect is applied, and when it is applied, the weapon is already equipped so the event will never run.

I also looked at the weapon rack script, this script used .DropObject, wich returns an ObjectReference of the dropped object, but again it's pretty useless. I don't want to drop the sword.

Slowly but surely the thought is creeping up on me, that the equipped weapon can't even be referenced to, that it has to be just lying around in a cell. But why woudn't there be something to do this. :dizzy:

Really hope this is not a total stupid question/issue and that someone can point me in the right direction.

Link to comment
Share on other sites

Objects inside inventories (containers or npc's) don't have object references, unless they happen to be persistent for some reason.

If there's any active script with the object reference stored, or if you use the object ref to pass to a script as a 'property' in the CK, it should be persistent.

So if that magic effect deals only with this unique sword, then set the property directly in the magic effect script.

Link to comment
Share on other sites

Thank you for the insight and quick reply!

That's what i feared, that a equipped weapon can't be referenced to. I do want to make this sword unique, but i thought it would be great if it also worked when smithed / cheated in aswell, but guess that's out of the question then...

EDIT: I don't get it to work, maybe i did something wrong.

I stored the reference, pointing to the sword still lying around in the cell in a property, attached to the magic effect. Now when i equip the sword and get the counter to where it should play the effect shader, nothing happens. I then tried to place another sword in the cell and pick that up, instead of the referenced sword, this time when i got the counter high enough the referenced sword began to glow (as it should). So it's working, but not while it is equipped. So i guess just storing the reference does not make it persistant or i did something wrong?

Also i don't really know how to do it with "any active script with the object reference stored". What would be an "avtive script"? Maybe a never ending loop?

Edited by Eaglemania
Link to comment
Share on other sites

Thank you Leecarter!

However I coudn't find an answer to my problem, your code does quite alot of things. I did a search and read around a bit and, what i think i understand:

You compare .GetEquippedWeapon with weapon types to determine if the player is unarmed or not,

and you .Play Visual Effects on the Game.getPlayer()?

I want to play an Effect Shader on an already equipped sword, ie: theEffectShader.Play(theEquippedSword, 5.0).

The problem being, getting the ObjectReference for theEquippedSword.

Can you explain the solution a little? Or point me to some lines/functions inside your script that does something like this, please?

Again, your code does quite alot of things and i'm new to papyrus and to the whole oop thing. Sorry if i didn't see the answer.

Link to comment
Share on other sites

Sure.

First you cast the weapon as a Form object. Pass (true) in GetEquippedWeapon() if you want the one in the left hand:


form theWeapon = theTarget.GetEquippedWeapon() as Form

Then you load up the shader (I've never used shaders, but I'm assuming they work the same)

theEffect = *your scripts variable"  

Then call play:

theEffect.Play(theWeapon)

Again, I've never worked with shaders, but this is how I would do a VisualEffect or ImpactDataSet so *maybe* they work the same.

Link to comment
Share on other sites

Thank you very much for taking time to explain! But again, i still don't get it to work, i really try not to be dumb but please take a look:

ScriptName MyEffectScript extends ActiveMagicEffect


EffectShader Property theShader Auto

VisualEffect Property theVisual Auto


Event OnEffectStart(Actor akTarget, Actor akCaster)

	Form theWeapon = akCaster.GetEquippedWeapon() as Form

	theShader.Play(theWeapon)

	theVisual.Play(theWeapon)

endEvent

this when compiled spits out error messages:

...\MyEffectScript.psc(8,11): type mismatch on parameter 1 (did you forget a cast?)

...\MyEffectScript.psc(9,11): type mismatch on parameter 1 (did you forget a cast?)

:dizzy:

EDIT:I tried to cast theWeapon as ObjectReference, but Debug.MessageBox(theWeapon) just said "none".

Edited by Eaglemania
Link to comment
Share on other sites

@LeeCarter, I looked at your Papyrus scripts. I couldn't find any effects being applied to weapons either, only Actors.

EDIT: I don't get it to work, maybe i did something wrong.

I stored the reference, pointing to the sword still lying around in the cell in a property, attached to the magic effect. Now when i equip the sword and get the counter to where it should play the effect shader, nothing happens. I then tried to place another sword in the cell and pick that up, instead of the referenced sword, this time when i got the counter high enough the referenced sword began to glow (as it should). So it's working, but not while it is equipped. So i guess just storing the reference does not make it persistant or i did something wrong?

If you're not doing this already, make sure that you're testing with a clean save. ie. your savegame has never seen your mod before.

To test if the sword is actually persistent, then add some events & debug.notification lines to it.

The one that is persistent should have a valid 'self', the one that isn't will show None.


ScriptName mySword extends ObjectReference

{Script added to the swords base "Weapon" object}


EffectShader Property theShader Auto


; Minor alterations to the wiki examples just to show value in "self"

; If self is valid, then try the effects.


Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)

  if akOldContainer && !akNewContainer

    Debug.Notification("We have been dropped! " + self)

  elseif akNewContainer && !akOldContainer

    Debug.Notification("We have been picked up! " + self)

  else

    Debug.Notfication("We have switched containers! " + self)

  endIf

endEvent


Event OnEquipped(Actor akActor)

  if akActor == Game.GetPlayer()

    Debug.Notification("We were equipped by the player! " + self)

    if self

      Debug.Notification("Shader effect being applied")

      theShader.Play(self)

    endif

  endIf

endEvent

Also i don't really know how to do it with "any active script with the object reference stored". What would be an "avtive script"? Maybe a never ending loop?

Yeah, sorry that's not clear. By Active I should have said currently loaded. The swordRef 'should' be persistent by virtue of the Property alone.

Before I confuse the issue even more though it's best to get the info direct from Beth's notes :)

A quest with an Alias can be used to make one instance of the weapon temporarily persistent. ie. as long as the quest is running and the Alias points to a Ref.

So crafting several is possible, and it's possible to keep track of one of them with an Alias. Fiddly though, as you may have to drop it first.

BTW, I've never used shaders before. Maybe they just don't work on equipped items period. The above test script should reveal if that's the case.

Link to comment
Share on other sites

Such a shame, I guess it's just not working with an equipped weapon. The .self worked and also i can pick up, then drop the sword in any cell and make it glow, useing another sword. So i guess the reference does stick with it.

I guess if it would have been possible, the Silent Moon weapons maybe would have used it, as they only do additional damage at night.

Anyways, thanks for all the help! I really appreciate it. Learned alot about papyrus and i understand a bit more about oop. :clap:

Link to comment
Share on other sites

Equipped items basically become a 'part' of the NPC or player model. They are attached to nodes on the skeleton. So I don't see how you would be able to do something to that type of equipment since they are basically now a part of the character skeleton.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...