First papyrus script not working in game

Post » Thu Jun 21, 2012 8:31 am

This is my first attempt at scripting, and I'm not sure why it's not working.

I have an item in-game that I'm trying to curse, so when equipped it kills the player (with fair warning!)

The item is armor. I select the armor, then I click "Add" in the scripts section of the item to add a new script. I then select new script, and type my script, which is:

Scriptname CurseScript extends ObjectReference  {Event OnEquipped (Actor AkActor)if AkActor == Game.GetPlayer()Game.GetPlayer().SetActorValue("health", 0)endifEndEvent}

I then click compile, and then save.

I then create a new magic effect (I call it CurseEffect) which has effect archetype paralysis, constant effect on self - so under magic item description I can have details about the curse as an additional warning before equipping. I don't mind if the paralysis effect takes place before killing, or if the killing happens straight away.

I then create a new enchantment and add the above CurseEffect to it (magnitude 50, for 5 seconds).

I then add this enchantment to my armor.

So now I should have two effects on my armor - the paralysis and the scripted papyrus effects. However when I go into game and try to wear the armor, I get the correct description from the armor, warning me about the curse - but all that happens is the paralysis - which seems to be permanent, even if I tell the CurseEffect to allow recovery...

I'm obviously doing something wrong, most probably a very simple mistake - any ideas? Thanks!
User avatar
SamanthaLove
 
Posts: 3565
Joined: Mon Dec 11, 2006 3:54 am

Post » Thu Jun 21, 2012 2:42 pm

Curly brackets {} indicate comments which are not processed--so your event function, which is enclosed by them, is being ignored.
User avatar
Smokey
 
Posts: 3378
Joined: Mon May 07, 2007 11:35 pm

Post » Thu Jun 21, 2012 11:32 am

Ah! Thank you very much for pointing that out! Noob mistake, obviously.

Edit: I removed the curly brackets, recompiled and saved again - but unfortunately it's still not working - the paralysis effect seems to be permanent, and the papyrus script doesn't kick in. Do you have any other suggestions?
User avatar
ezra
 
Posts: 3510
Joined: Sun Aug 12, 2007 6:40 pm

Post » Thu Jun 21, 2012 10:05 am

Objects that are added to the player using http://www.creationkit.com/AddItem_-_ObjectReference do not always have their scripts working until the item is dropped and then picked up again.

Since you're putting an enchantment on the armor anyway, you should just add a script to the magic effect like this:

Scriptname Example extends ActiveMagicEffectEvent OnEffectStart(Actor akTarget, Actor akCaster)akTarget.Kill()EndEvent
User avatar
Nichola Haynes
 
Posts: 3457
Joined: Tue Aug 01, 2006 4:54 pm

Post » Thu Jun 21, 2012 6:55 pm

Ok, will try that - thanks. In the meantime I' had been trying to get the previous script to work and I found that it did seem to work if I didn't add an enchantment as well - it decreased my health to 0 but I was still free to wander around, and it didn't kill me.

Will report back once I've tried your "Kill" suggestion - I wasn't aware that could be applied to the player!

Edit - Bingo - it works perfectly! Thanks ever so much for your help.
User avatar
sophie
 
Posts: 3482
Joined: Fri Apr 20, 2007 7:31 pm

Post » Thu Jun 21, 2012 8:19 am

I've noticed an unusual thing - whenever I get killed by this script, I get an instant CTD - when I die normally in-game I get back to the main menu, but using this script appears just to crash the game.
User avatar
Juanita Hernandez
 
Posts: 3269
Joined: Sat Jan 06, 2007 10:36 am

Post » Thu Jun 21, 2012 12:15 pm

The CTD could be caused by the game expecting player to be alive as it has max hit points after all. Try using damageactorvalue instead of setactorvalue.
User avatar
YO MAma
 
Posts: 3321
Joined: Thu Dec 21, 2006 8:24 am

Post » Thu Jun 21, 2012 10:00 am

Thanks, I think I've got it all fixed - and now uploaded to the Nexus!

I have a few other "cursed" items using the same script or variants of it, so will be using the same procedure - thanks again!

Moon-And-Star Ring - Not The Nerevarine Edition - http://skyrim.nexusmods.com/downloads/file.php?id=17634
User avatar
Sammykins
 
Posts: 3330
Joined: Fri Jun 23, 2006 10:48 am

Post » Thu Jun 21, 2012 2:07 pm

Ok, so I've had a request to make a more sophisticated version of the script - basically to add a perk, and if the player has the perk then the script doesn't kill them...

I've set up a new ability and applied it to a new perk called "Nerevarine" (formID "MaSNerevarine", FormID 0200331E).

Basically I want it do this:
If actor has perk, then give message and let the player live (ie. do nothing else). If actor does not have perk, then kill actor.
Scriptname MaSCurseEffectReal extends activemagiceffect perk property MaSNerevarine autoEvent OnEffectStart(Actor akTarget, Actor akCaster)if Game.GetPlayer().HasPerk(MaSNerevarine) ==1  Debug.Message("You Are The Nerevarine!")elseakTarget.Kill()endIfEndEvent

I read somewhere that it helps to define the perk property at the top of the script (although I must admit I have no idea why, or whether I should be doing this - it doesn't work either way!)

The compile fails and compiler output is:

Starting 1 compile threads for 1 files...Compiling "MaSCurseEffectReal"...c:\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\MaSCurseEffectReal.psc(7,28): variable MaSNerevarine is undefinedc:\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\MaSCurseEffectReal.psc(8,8): Message is not a function or does not existc:\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\MaSCurseEffectReal.psc(8,8): cannot call the member function Message alone or on a type, must call it on a variableNo output generated for MaSCurseEffectReal, compilation failed.Batch compile of 1 files finished. 0 succeeded, 1 failed.
User avatar
Charlotte Buckley
 
Posts: 3532
Joined: Fri Oct 27, 2006 11:29 am

Post » Thu Jun 21, 2012 10:50 am

"Message" is not a function. Use "Notification" or "MessageBox". No idea why the "HasPerk" line is not compiling.
User avatar
IM NOT EASY
 
Posts: 3419
Joined: Mon Aug 13, 2007 10:48 pm

Post » Thu Jun 21, 2012 6:32 pm

ScriptName MaSCurseEffectReal extends ActiveMagicEffectPerk Property MaSNerevarine AutoEvent OnEffectStart(Actor akTarget, Actor akCaster) 	If Game.GetPlayer().HasPerk(MaSNerevarine) 		Debug.MessageBox("You Are The Nerevarine!") 	Else 		akTarget.Kill() 	EndIfEndEvent
' ==1' was the problem with line 6. You want 'If Game.GetPlayer().HasPerk(MaSNerevarine) == True' or, better still, 'If Game.GetPlayer().HasPerk(MaSNerevarine)'.
User avatar
Tai Scott
 
Posts: 3446
Joined: Sat Jan 20, 2007 6:58 pm

Post » Thu Jun 21, 2012 12:10 pm

Thank you! It now compiles correctly.
User avatar
Kirsty Collins
 
Posts: 3441
Joined: Tue Sep 19, 2006 11:54 pm

Post » Thu Jun 21, 2012 8:45 am

You'd probably want

If akTarget.HasPerk(MaSNerevarine)

Right? The player being the Nerevarine shouldn't stop someone else from killing themselves with the ring.
User avatar
meghan lock
 
Posts: 3451
Joined: Thu Jan 11, 2007 10:26 pm

Post » Thu Jun 21, 2012 11:24 am

^Good call.

ScriptName MaSCurseEffectReal extends ActiveMagicEffectPerk Property MaSNerevarine AutoEvent OnEffectStart(Actor akTarget, Actor akCaster)	If akTarget.HasPerk(MaSNerevarine)		If akTarget == Game.GetPlayer()			Debug.MessageBox("You Are The Nerevarine!")		EndIf	Else		akTarget.Kill()	EndIfEndEvent
User avatar
Latino HeaT
 
Posts: 3402
Joined: Thu Nov 08, 2007 6:21 pm

Post » Thu Jun 21, 2012 9:25 pm

Ok, thanks - that's a very good point, and one I didn't think it would be possible to achieve that easily - will try that out!

I just tried your earlier suggestion and the ring still killed me, even though I'd added the perk to my character (the perk appeared in active affects). Any idea why this would happen?

I also removed the paralysis effect to MaSCurse and replaced it with a fortify speech, so the player would get the new increased speech - or would it be better to achieve this via the script too? My main reason in creating a new effect was so when you look at the ring in the inventory, it says that the magic effect is "fortify speech - only for nerevarine, fatal for all others" or something like that. It's a bit of a warning to the player.


Edit: nope, it's still not working properly in-game with the newer script either, unfortunately - I still get killed when I have the perk and wear the ring...I don't even get to see the "You Are The Nerevarine" messagebox....
I changed the script reference from HasPerk (MaSNerevarine) to HasPerk (Nerevarine) as "MaSNererarine" is the ID name rather than the name (which is "Nerevarine"), but I still die immediately...
User avatar
Lisha Boo
 
Posts: 3378
Joined: Fri Aug 18, 2006 2:56 pm

Post » Thu Jun 21, 2012 11:57 am

You need to attach the property in the CK. go to the spell effect form, click on the script simbol and do the same on the now activable properties button. Click on auto fill all and then on OK. Now save.
User avatar
Leanne Molloy
 
Posts: 3342
Joined: Sat Sep 02, 2006 1:09 am

Post » Thu Jun 21, 2012 6:47 pm

That's great, thanks! I had to edit value to select the correct perk in properties before I could get it to auto-fill, but it's all working fine now - thanks again!
User avatar
Zoe Ratcliffe
 
Posts: 3370
Joined: Mon Feb 19, 2007 12:45 am


Return to V - Skyrim