Jump to content

[LE] Script scanning weapon on (re)equipping


Recommended Posts

Hi all.

In short, I'm trying to create a spell added to player with magic effect, on which is a script scanning (in theory) weapon and set his attack speed calculated according to formula. All is OK - I successfully scan the weapon, calculate and set its speed, but exclude the start of this effect - I cannot understand how rightly write event or function working on (re)equipping weapon (now I for checking the script made a Lesser Power with this effect). I'll be very thankful, if anyone tell me example of "on equip" function or event.


Most likely, I need to use OnObjectEquipped event, but I would be glad if someone showed an example of how to CORRECTLY write this event because I have tried and failed (am I noob? dont' answer to this question, please).


I ask to forgive my bad english (it is not my native). And I hope someone can tell me a solution.

Edited by Vitalyudin
Link to comment
Share on other sites

  • 2 weeks later...

I'm not 100% sure what you're asking. I take it you have some scripts you want to execute when a weapon is equipped, but don't know how to set up the trigger?

 

You're correct that OnObjectEquipped is the event to use. Copying the code on the wiki should get you a working event. Seeing your code might be helpful in figuring out what is going wrong with your script.

Link to comment
Share on other sites

I take it you have some scripts you want to execute when a weapon is equipped, but don't know how to set up the trigger?

Thanks for answer!

Yes. Now I have a magic effect with next script:

 

 

scriptname wsc_maineff extends activemagiceffect

globalvariable property WSC_deb auto
float weapspeed
float weapweight
float wwsrarfm
float wssrarfm
float wsloose
int weaptype


Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference)
  if akBaseObject as Weapon


if (WSC_deb.value == 1)
endif

if game.getplayer().getequippedweapon().IsSword()
wwsrarfm = 13
wssrarfm = 1
wsloose = 0.03
elseif game.getplayer().getequippedweapon().IsDagger()
wwsrarfm=4
wssrarfm=1.3
wsloose = 0.03
elseif game.getplayer().getequippedweapon().IsWarAxe()
wwsrarfm=15
wssrarfm=0.9
wsloose = 0.03
elseif game.getplayer().getequippedweapon().IsMace()
wwsrarfm=17
wssrarfm=0.8
wsloose = 0.03
elseif game.getplayer().getequippedweapon().IsGreatsword()
wwsrarfm=20
wssrarfm=0.8
wsloose = 0.02
elseif game.getplayer().getequippedweapon().IsBattleAxe()
wwsrarfm=24
wssrarfm=0.7
wsloose = 0.02
elseif game.getplayer().getequippedweapon().IsWarhammer()
wwsrarfm=28
wssrarfm=0.6
wsloose = 0.02
endif

if (WSC_deb.value == 1)
endif

if (WSC_deb.value == 1)
endif
weapspeed = game.getplayer().getequippedweapon().getspeed()
weapweight = game.getplayer().getequippedweapon().getweight()
if (WSC_deb.value == 1)
endif  

if (WSC_deb.value == 1)
endif

weapspeed = (wssrarfm + (wwsrarfm - weapweight) * wsloose)

if (WSC_deb.value == 1)
debug.notification("Задаем скорость...")
endif

game.getplayer().getequippedweapon().setspeed(weapspeed)

if (WSC_deb.value == 1)
endif

endif 
endevent 

 

 

The effect is in everlasting hided spell. I left my last attempt to run script in the script code - OnObjectEquipped event. What's wrong? I cannot understand.
Edited by Vitalyudin
Link to comment
Share on other sites

Okay, firstly, why are you checking for the value of a global variable without doing anything with it constantly..? It's quite confusing.

In these "if ... endif" blocks were placed notifications for checking if it work or not, but I just remove it to post the code here.

Thanks for the tip, but it doesn't real matter - the code (without "Event OnObjectEquipped...") works if I put this effect in a lesser power.

Only in permanent (and with "Event OnObjectEquipped...") spell it doesn't work, and that's what I'm asking - how rightly apply the OnEquippedObject event? In my code it doesn't work, what there wrong?

Edited by Vitalyudin
Link to comment
Share on other sites

Vitalyudin: As an optimization, don't use the Game.GetPlayer().GetEquippedWeapon() construction. It's slow and this is a script you'll want to run fast. Everything I see your script doing can be done by:

 

 

Weapon kBaseWeapon = akBaseObject as Weapon

if kBaseWeapon
    if kBaseWeapon.IsSword()
        ;set values
    elseif     ;... all other cases
    endif
endif

 

That should be much, much faster. You can also, if you wish, replace the SKSE functions with the HasKeyword equivalents, removing your dependence on SKSE in this script. If your mod otherwise does not require SKSE I'd do so; if it does, it's less of an issue but still generally a good practice.

 

 

As far as not working at all goes:

 

1. Does the magic effect have the script attached to it in the CK?

 

2. Does your magic effect have the correct types for use as an ability (constant effect, self)?

 

3. Does your ability spell have the magic effect added to it?

 

4. Are there conditions on either in the CK? If so, what are they?

 

5. Does the player have the ability or magic effect on them? Unhide it to see, or use the console command HasMagicEffect to check. You can get your magic effect's ID by using the command "help effectname" in the console.

 

6. Have you tried a Debug.Trace() statement right at the beginning of the OnObjectEquipped event, outside of any conditionals, to see if it fires at all?

 

7. Is your GlobalVariable property filled out? You might be getting false debug statements if it is not.

 

I'll second wormple's request for screenshots of the stuff in the CK as well.

Link to comment
Share on other sites

foamyesque:

>> As an optimization...

OK, thank you, I will know.

 

Your questions:

1, 2, 3: yes, of course. 4: there's no conditions.

 

6: no, 7: yes.
And...

5: MAN! I checked - at first it was not effect on the character. I decided to investigate, recreate the spell and the effect. I admit that I was a fool. Forgive me. The spell was exactly "SPELL" but not "ABILITY" (like racial abilities for example). As ability it's working! I'm glad, you helped me to solve this issue. Thank you!

 

And thanks for the tip about optimization and SKSE-independence again.

Screenshots if you both still interested:

 

 

Magic Effect: constant effect, self. I unchecked "hide in UI"

http://images.vfl.ru/ii/1504989418/a885e053/18543694.png

 

Spell: IT WAS A SPELL! But not ability :facepalm: :psyduck: http://images.vfl.ru/ii/1504989420/712accdd/18543695.png

 

 

 

Thank you wormple12, foamyesque!

Edited by Vitalyudin
Link to comment
Share on other sites

  • Recently Browsing   0 members

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