Where's my error in this papyrus script for Trigger Event?

Post » Mon Nov 19, 2012 6:36 am

Hey guys, I am trying to make a script that, when something enters the trigger box, an integer "count" is incremented by 1... but only if that something is the player character.

Then, if the integer "count" is ==1 , then the player will experience their camera shaking and the screen blurring for a moment. Obviously, this is intended to happen once, so every time the trigger box is entered by another NPC, or entered a second time by the player, that the script for the shaking does not run.

Here is my code, but the compiler doesn't like it. Where have I gone wrong?

Sorry but I am not sure how to make thee message board indent, so I am using spaces to help with readability. Also, if anyone knows of anything that can help me make a good screen shake and rumbling with blurring, or possibly a voice (like a voice in your head), I'd love to learn about it, as thats next on my agenda.

===========================================================

Scriptname DWRumbleShakeTrig extends ObjectReference
{Makes the screen shake etc.}

int count
Actor Property PlayerRef Auto

Event OnTriggerEnter(ObjectReference akActionRef)

If akActionRef = PlayerRef
count = count + 1
EndIf

If count == 1
Debug.MessageBox("Triggers shaking and rumbling when active")
;here is where the actual code to cause shaking and rumbling will be placed
EndIf

endEvent
User avatar
Sarah Unwin
 
Posts: 3413
Joined: Tue Aug 01, 2006 10:31 pm

Post » Mon Nov 19, 2012 12:46 pm

This line needs '==' instead of '='

If akActionRef == PlayerRef
User avatar
BrEezy Baby
 
Posts: 3478
Joined: Sun Mar 11, 2007 4:22 am

Post » Mon Nov 19, 2012 2:01 pm

I have another really small script that doesn't appear to be working as intended. While my OP script isn't working at all, this one is working partially.

I want the player to not be able to loot or pickpocket a dead NPC that is labeled as "Unconscious".

For some reason, the script is making the inventory inactive, but only after the NPC's inventory is accessed the first time. After accessing the inventory once, and leaving, the script will execute properly, leaving the player with a message about the NPC being unconscious, rather than bringing up their inventory.

However, if the NPC is alive, and I attempt to pickpocket them, then the script seems to work properly from the start.

For readability sake, I wanted to post this in a second post, rather than editing the first...
==============================================

Scriptname Unconscious extends ObjectReference
{MakesNPCUnconscious}

ObjectReference Property NPC Auto

Event OnActivate(ObjectReference akActionRef)
NPC.BlockActivation()
Debug.MessageBox("She's breathing, but appears to be in a deep sleep")
endEvent
User avatar
Rachel Cafferty
 
Posts: 3442
Joined: Thu Jun 22, 2006 1:48 am

Post » Mon Nov 19, 2012 5:18 pm

This line needs '==' instead of '='

If akActionRef == PlayerRef

Wow, I feel silly. Thanks for catching that. But while the code compiles, the message doesn't trigger, so I did something wrong somewhere it the content as well. Or so I think.
User avatar
Ross Zombie
 
Posts: 3328
Joined: Wed Jul 11, 2007 5:40 pm

Post » Mon Nov 19, 2012 5:57 pm

Perhaps a temp variable of type Actor, then cast akActionRef so the types match in the 'If' statement. There might be a better way. I'm new at Papyrus scripting too ;)

Scriptname DWRumbleShakeTrig extends ObjectReference{Makes the screen shake etc.}int countActor TempRefActor Property PlayerRef AutoEvent OnTriggerEnter(ObjectReference akActionRef)TempRef = akActionRef As actorIf TempRef == PlayerRefcount = count + 1EndIfIf count == 1Debug.MessageBox("Triggers shaking and rumbling when active");here is where the actual code to cause shaking and rumbling will be placedEndIfendEvent 
User avatar
City Swagga
 
Posts: 3498
Joined: Sat May 12, 2007 1:04 am

Post » Mon Nov 19, 2012 9:01 am

Perhaps a temp variable of type Actor, then cast akActionRef so the types match in the 'If' statement. There might be a better way. I'm new at Papyrus scripting too ;)
That's actually almost exactly what the compiler does behind the scenes when you do a straight comparison of those values, except instead of casting akActionRef to an http://www.creationkit.com/Actor_Script, which can fail (harmlessly - it just returns http://www.creationkit.com/Literals_Reference#None_Literal), it will cast PlayerRef to an http://www.creationkit.com/ObjectReference_Script, which cannot fail.

The compiler will sneakily create a temporary ObjectReference variable that's local to the http://www.creationkit.com/OnTriggerEnter_-_ObjectReference event, and store the value of PlayerRef cast as an ObjectReference in that temporary variable in order to do the comparison.

Cipscis
User avatar
Caroline flitcroft
 
Posts: 3412
Joined: Sat Nov 25, 2006 7:05 am

Post » Mon Nov 19, 2012 1:10 pm

Perhaps a temp variable of type Actor, then cast akActionRef so the types match in the 'If' statement. There might be a better way. I'm new at Papyrus scripting too :wink:


I'm glad you posted that, thanks! I think the issues lies with how I set up the trigger box (as a reference). That code looks solid, but the message isn't appearing, so I must not be activating the trigger box so that the script has a chance to run.

I'll try to figure out what I messed up in the morning. Thanks again for the help and code edits!
User avatar
Latisha Fry
 
Posts: 3399
Joined: Sat Jun 24, 2006 6:42 am

Post » Mon Nov 19, 2012 12:15 pm

That's actually almost exactly what the compiler does behind the scenes when you do a straight comparison of those values, except instead of casting akActionRef to an http://www.creationkit.com/Actor_Script, which can fail (harmlessly - it just returns http://www.creationkit.com/Literals_Reference#None_Literal), it will cast PlayerRef to an http://www.creationkit.com/ObjectReference_Script, which cannot fail.

The compiler will sneakily create a temporary ObjectReference variable that's local to the http://www.creationkit.com/OnTriggerEnter_-_ObjectReference event, and store the value of PlayerRef cast as an ObjectReference in that temporary variable in order to do the comparison.



Cipscis

So it's best to stick with what I originally had?

Also, I added a line below the note about where the code for shaking is to go, and it reads ----- count = count +1

I did that to make sure that no NPC can walk into the trigger after count is equal to 1, but before the player enters again and sets it to 2. Just trying to cover my logic holes in the code. Not sure if I was right to do that, but it will at least guarantee the function is invalid after one go.
User avatar
Eddie Howe
 
Posts: 3448
Joined: Sat Jun 30, 2007 6:06 am

Post » Mon Nov 19, 2012 8:18 pm

I worked on something sort of like that, wanted part of my cave to shake when the player reached a set point, found that i could go into the "warehousetrap" cell grab the two "L" markers from the rockcavein trap and rig those to a triggerboxself.
All the coding is there, just had to sort the properties, and since it is a trap, it only fires once (until next reset, but that can be unchecked) you can then alter the properties to only alow player trigger, and not followers again done in the properties.

Simple workaround that might be worth looking into :)
User avatar
Syaza Ramali
 
Posts: 3466
Joined: Wed Jan 24, 2007 10:46 am

Post » Mon Nov 19, 2012 8:23 am

Thanks, I tried that and got a good code from that, Treeki. Unfortunately, the trigger still wont work. I used a trigger box, and chose the triggerbox preset one. Nothing happens when I walked into the trigger box!

Does anyone know of a common pitfall with making trigger boxes, because this one just doesnt seem to recognize that i've given it a purpose.
User avatar
rolanda h
 
Posts: 3314
Joined: Tue Mar 27, 2007 9:09 pm

Post » Mon Nov 19, 2012 12:17 pm

Apparently there's a bug if the activator is at 0 degrees on the Z plane. It won't activate/trigger

http://www.gamesas.com/topic/1414383-activator-y-u-no-activate/
User avatar
mimi_lys
 
Posts: 3514
Joined: Mon Apr 09, 2007 11:17 am

Post » Mon Nov 19, 2012 9:11 pm

Ugh. I was hoping that was the problem. It still refuses to work. Although I changed the z plane value to a non zero to prevent the issues you mentioned in the future.


Grrr. The trigger box is set just like other previously made skyrim trigger boxes that I see in various levels. The code seems to be correct... but nothing happens at all...

Edit: I've got it working. The playerRef code was keeping it from working correctly.
User avatar
Hayley O'Gara
 
Posts: 3465
Joined: Wed Nov 22, 2006 2:53 am


Return to V - Skyrim