Jump to content

Recommended Posts

Posted

I'm trying to write a script for a book so that it grants a perk when you read it. Now, I'm an utter noob when it comes to scripting, so I need all the help I can get.

 

Here's what I have. What am I doing wrong?

 


Scriptname AddThunderPerk extends ObjectReference



SPELL Property ThunderReward Auto 
Perk property ThunderPerk auto 

Event OnRead()
if akActor== Game.GetPlayer() && Game.GetPlayer().HasPerk(ThunderPerk) == 0
               Game.GetPlayer().AddPerk(ThunderPerk)
		Debug.Trace("Heart of Thunder added")
       endif
EndEvent


 

Any help would be greatly appreciated.

Posted (edited)

The compile fails. The compiler output tells me that the variable akActor is undefined.

As for asscociating my perk, I think that's what I'm doing with the first two lines, though I'm not entirely sure.

 

I've had a look at the wiki but that's a lot of info to digest.

 

[Edit] I've figured out associating my perk. It's just defining akActor now.

Edited by OminousVoice
Posted (edited)

Ok, I added an actor property and the script compiles, however in-game it doesn't have the desired effect. Do I need to add anything?

 

Scriptname AddThunderPerk extends ObjectReference

Actor property akActor auto 
Perk property ThunderPerk auto 

Event OnRead()
       if akActor== Game.GetPlayer() && Game.GetPlayer().HasPerk(ThunderPerk) == 0
               Game.GetPlayer().AddPerk(ThunderPerk)
		Debug.Trace("Heart of Thunder added")
       endif
EndEvent

Edited by OminousVoice
Posted

Oh, of course! You were treating akActor as though OnRead has such a parameter that lets you use the actor doing the reading, but this event will only run when the player reads a book.

 

Because your akActor property is never set, it will default to None, and your condition of "if akActor == Game.GetPlayer()" can never be true.

 

This should work:

Scriptname AddThunderPerk extends ObjectReference

Perk property ThunderPerk auto 

Event OnRead()
   if Game.GetPlayer().HasPerk(ThunderPerk) == false
       Game.GetPlayer().AddPerk(ThunderPerk)
       Debug.Trace("Heart of Thunder added")
   endif
EndEvent

Note that I changed "== 0" to "== false". We have proper boolean types in Skyrim, so using "== 1" or "== 0" is now semantically incorrect, even if the automatic cast will make it work. If nothing else, this is something you should be aware of.

 

Cipscis

Posted

Is that no effect including no sign of the debug message in the logs? Have you set up your property in the editor correctly?

 

Cipscis

I managed to do this by using an event of OnInit :) try that

Posted

Is that no effect including no sign of the debug message in the logs? Have you set up your property in the editor correctly?

 

Cipscis

 

I picked my perk from the dropdown box when editing the property. I assume that's how it's supposed to work, but evidentally it's not. How would I go about defining the property in the script itself?

  • Recently Browsing   0 members

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