Jump to content

Need help scripting


Extragorey

Recommended Posts

I'm trying to write a script which automatically grants you the "[Rank] [Magic School]" perk without requiring a perk point when you reach the required level (with the exception of the first "Novice" perk, which you'd still have to buy).

For example, you've bought the Novice Destruction perk and you get 25 destruction. The "Apprentice Destruction" perk would automatically be bought.

The script should also be retro-active; that is, when you install the mod and you're already 78 Destruction, you should automatically get the Apprentice, Adept, and Expert Destruction perks.

So I wrote this script, and thought it was pretty good. Then none of the functions worked! Which is weird for me, since they're mostly just console commands.

So here's the script below. I eventually settled for a script which runs every 5 seconds, because I couldn't find one to run upon levelling a skill.

The first part uses one kind of PerkID, and the rest of the script uses another. I wasn't sure which one it accepted, so I tried both.

 

 

  Reveal hidden contents

 

 

Any help would be appreciated. And the Creation Kit wiki is pitifully lacking in scripting tutorials.

Link to comment
Share on other sites

  On 2/8/2012 at 12:41 PM, Teh Masterer said:

I wonder how long it'll take before all the programmers in the modding community become fully savvy with the new scripting language...

 

How are you registering to begin with? who calls this function?

 

Function JulesUpdateGameTimeFunction() 
RegisterForUpdateGameTime(0.00139)
endFunction

 

I think your problem is just that you have the above wrapped up in a function. No one is calling that funciton so you never get registered. Try something like....

 

RegisterForUpdateGameTime(.1)

Event OnUpdateGameTime() ; this event occurs every 5.004 seconds of game time 
if player.getav Destruction >= 25 && player.hasperk DestructionApprentice25 == 0 && player.hasperk DestructionNovice00 == 1
player.addperk DestructionApprentice25
Debug.MessageBox("Congratulations! You have been awarded the Apprentice Destruction perk for reaching 25 Destruction."
endIf
....snip....
UnregisterForUpdateGameTime()
endIf
endEvent

Link to comment
Share on other sites

  On 2/8/2012 at 1:41 PM, MofoMojo said:

I think your problem is just that you have the above wrapped up in a function. No one is calling that funciton so you never get registered. Try something like....

 

Thanks for your reply. And yes, that would have been a problem had I actually gotten around to playtesting, so thanks for pointing that out.

However, my problem was that the script wouldn't actually compile because it claimed the "addperk" and "hasperk" functions didn't exist - though they work perfectly fine in the ingame console.

Do you know why this might be?

 

I'm not worried about where to call the script at this point; I'm just trying to get the level & perk detection and perk adding working properly.

If needs be, I can always add the script to a spell effect or something.

Edited by Teh Masterer
Link to comment
Share on other sites

  On 2/8/2012 at 3:07 PM, Teh Masterer said:
  On 2/8/2012 at 1:41 PM, MofoMojo said:

I think your problem is just that you have the above wrapped up in a function. No one is calling that funciton so you never get registered. Try something like....

 

Thanks for your reply. And yes, that would have been a problem had I actually gotten around to playtesting, so thanks for pointing that out.

However, my problem was that the script wouldn't actually compile because it claimed the "addperk" and "hasperk" functions didn't exist - though they work perfectly fine in the ingame console.

Do you know why this might be?

 

I'm not worried about where to call the script at this point; I'm just trying to get the level & perk detection and perk adding working properly.

If needs be, I can always add the script to a spell effect or something.

 

I'm pretty sure Papyrus doesn't support or in any way use console commands.

Papyrus is an object oriented language, which is great.

 

You need to get a reference to the Player Actor.

Which is done like so:

Game.GetPlayer()

 

You can do this:

Game.GetPlayer().AddPerk(DestructionApprentice25)

instead of

player.addperk DestructionApprentice25

 

Docs:

http://www.creationkit.com/AddPerk_-_Actor

http://www.creationkit.com/GetPlayer_-_Game

 

Hope that helps you on your way.

Edited by grey79
Link to comment
Share on other sites

  On 2/8/2012 at 4:02 PM, grey79 said:
Hope that helps you on your way.

Thank you, it did indeed. Still one more problem, however. The compiler doesn't recognise the skill names or perk names.

Here's my code as it currently stands:

(I had to put RegisterForUpdateGameTime() in an event bracket)

 

 

  Reveal hidden contents

 

 

When I compile this I get the following errors: "variable Destruction is undefined", "variable DestructionApprentice25 is undefined", "variable DestructionNovice00 is undefined" and so on.

So somehow I need to tell the procedure to grab variable names from the game... Does anyone know how I'd go about doing that?

Link to comment
Share on other sites

  On 2/8/2012 at 5:59 PM, Edlennion said:

The problem is the function is

AddPerk(Perk somePerk)

rather than

AddPerk(string somePerkName)

 

So you need to pass the function a Perk Object, not just the name of the perk

 

Basically you need to definte the perk:

 

Scriptname mm_RingOfSunniesWoe extends ObjectReference  
{Script which controls the rings activation, etc,.}

SPELL Property PerkSunniesWoeSpel  Auto  
Perk property SunniesWoePerk auto

Event OnEquipped(Actor akActor)
if akActor== Game.GetPlayer() && Game.GetPlayer().HasPerk(SunniesWoePerk) == 0
	Game.GetPlayer().AddPerk(SunniesWoePerk)
endif
EndEvent

Event OnUnequipped(Actor akActor)
if akActor== Game.GetPlayer()
	Game.GetPlayer().RemovePerk(SunniesWoePerk)
	Game.GetPlayer().RemoveSpell(PerkSunniesWoeSpel)
endif
EndEvent

 

Not sure if it helps, but on the properties of the script you'll see a list of all your defined properties. Make sure they evaluate to the proper Perk there as well. There's probably a more proper way to do it, but that's how I've done it above on a ring that applies a perk only when you're wearing it.

 

-MM

Edited by MofoMojo
Link to comment
Share on other sites

  • Recently Browsing   0 members

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