Jump to content

Scripting help


OminousVoice

Recommended Posts

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

  • Recently Browsing   0 members

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