How to avoid default activation with OnActivate?

Post » Mon Nov 19, 2012 3:59 am

I have used a few hours to figure out how to use papyrus correctly but it seems very complicated and hard to use after all. I used to script a lot with Oblivion engine and when I'm trying to do things in Skyrim which are very simple to do in Oblivion they seemed to be broken with papyrus. For example I have now tried to simple OnActivate script on a specific bedroll to move player to certain marker instead of sleeping/serving the jail time. For some reason it seems that the default activation happens at first and so my script never occurs. If someone can help me to find a way to run this properly I'll be grateful. Here's my script in the spoiler:
Spoiler
Scriptname GoToJailShipscript extends ObjectReference

Actor Property PlayerREF Auto
ObjectReference Property JailShipMarker Auto

Event OnActivate(ObjectReference akActionRef)
If akActionRef == PlayerREF
akActionRef.MoveTo (JailShipMarker)

EndIf
EndEvent
User avatar
Beth Belcher
 
Posts: 3393
Joined: Tue Jun 13, 2006 1:39 pm

Post » Mon Nov 19, 2012 9:21 am

if you want to avoid activation between actor and objects, you can use BlockActivation() . Then you can still activate the object via Script call. (but I am not sure to understand what you mean by default activation?)
User avatar
Romy Welsch
 
Posts: 3329
Joined: Wed Apr 25, 2007 10:36 pm

Post » Mon Nov 19, 2012 11:34 am

if you want to avoid activation between actor and objects, you can use BlockActivation() . Then you can still activate the object via Script call. (but I am not sure to understand what you mean by default activation?)
I think you understand it just right - I mean the activation which happens normally when the object isn't connected to any scripts. Anyway the BlockActivation() is probably exactly what I need but unfortunately I'm unable to get it right it says "GoToJailShipscript.psc(6,8): no viable alternative at input '.'No output generated for GoToJailShipscript, compilation failed." When I tried it and I can't see what I did wrong
Spoiler
Scriptname GoToJailShipscript extends ObjectReference

ObjectReference Property JailBed1 Auto

Function BlockActivation(bool abBlocked = True) native
JailBed1.BlockActivation()
EndFunction

Actor Property PlayerREF Auto
ObjectReference Property JailShipMarker Auto

Event OnActivate(ObjectReference akActionRef)
If akActionRef == PlayerREF
akActionRef.MoveTo (JailShipMarker)

EndIf
EndEvent
User avatar
Joe Bonney
 
Posts: 3466
Joined: Tue Jul 17, 2007 12:00 pm

Post » Mon Nov 19, 2012 8:54 am

.(double post)
User avatar
Len swann
 
Posts: 3466
Joined: Mon Jun 18, 2007 5:02 pm

Post » Sun Nov 18, 2012 11:53 pm

Functions are not called directly, you must call them through event()
Here , the most reliable for this situation is probably the OnInit() event, that fires when the script/object is initialised

While assuming your script is attached to the JailBed1 object, this should looks like this:

Scriptname GoToJailShipscript extends ObjectReferenceActor Property PlayerREF AutoObjectReference Property JailShipMarker AutoEvent oninit()   BlockActivation()endeventEvent OnActivate(ObjectReference akActionRef)   If akActionRef == PlayerREF	  akActionRef.MoveTo (JailShipMarker)   EndIfEndEvent
User avatar
Kevin S
 
Posts: 3457
Joined: Sat Aug 11, 2007 12:50 pm

Post » Mon Nov 19, 2012 2:26 am

Functions are not called directly, you must call them through event()
Here , the most reliable for this situation is probably the OnInit() event, that fires when the script/object is initialised

While assuming your script is attached to the JailBed1 object, this should looks like this:

Scriptname GoToJailShipscript extends ObjectReferenceActor Property PlayerREF AutoObjectReference Property JailShipMarker AutoEvent oninit()   BlockActivation()endeventEvent OnActivate(ObjectReference akActionRef)   If akActionRef == PlayerREF	  akActionRef.MoveTo (JailShipMarker)   EndIfEndEvent
Even with that the original problem stays: normal activation happens and my script doesn't.
User avatar
Soraya Davy
 
Posts: 3377
Joined: Sat Aug 05, 2006 10:53 pm

Post » Mon Nov 19, 2012 1:39 am

Might you have loaded a save in which the script was already attached to you object? Because in that case the http://www.creationkit.com/OnInit event wouldn't have been called on it so its default activation wouldn't have become blocked.

Cipscis
User avatar
Claire Lynham
 
Posts: 3432
Joined: Mon Feb 12, 2007 9:42 am

Post » Mon Nov 19, 2012 7:38 am

Might you have loaded a save in which the script was already attached to you object? Because in that case the http://www.creationkit.com/OnInit event wouldn't have been called on it so its default activation wouldn't have become blocked.

Cipscis
I did so. Now I tried it with older save and the activation is blocked, but that blocks also the OnActivate script - so nothing happens with the bedroll now.
User avatar
Andrew
 
Posts: 3521
Joined: Tue May 08, 2007 1:44 am

Post » Mon Nov 19, 2012 12:00 am

Check, in an http://www.creationkit.com/OnActivate_(Papyrus) event, http://www.creationkit.com/IsActivationBlocked_-_ObjectReference. If so, code hinged on that will fire but the default activation will not.

ScriptName SomeContainerScript Extends ObjectReferenceEvent OnActivate(ObjectReference akActionRef)	If IsActivationBlocked()		Debug.Trace("Don't open, but run this code")	Else		Debug.Trace("Open normally and run this code")	EndIfEndEvent
User avatar
Andrew Tarango
 
Posts: 3454
Joined: Wed Oct 17, 2007 10:07 am

Post » Mon Nov 19, 2012 12:31 pm

Check, in an http://www.creationkit.com/OnActivate_(Papyrus) event, http://www.creationkit.com/IsActivationBlocked_-_ObjectReference. If so, code hinged on that will fire but the default activation will not.

ScriptName SomeContainerScript Extends ObjectReferenceEvent OnActivate(ObjectReference akActionRef)	If IsActivationBlocked()		Debug.Trace("Don't open, but run this code")	Else		Debug.Trace("Open normally and run this code")	EndIfEndEvent
Nope that doesn't run on it either. May this problem exist because the script is placed on a bedroll not on a container or item?
User avatar
BrEezy Baby
 
Posts: 3478
Joined: Sun Mar 11, 2007 4:22 am

Post » Mon Nov 19, 2012 1:58 am

Should work the same on a bedroll exchanging 'open' with 'sleep'. Did you try that after the activation blockage OnInit style?
Spoiler
ScriptName GoToJailShipScript Extends ObjectReferenceActor Property PlayerREF AutoObjectReference Property JailShipMarker AutoEvent OnInit()   BlockActivation()EndEventEvent OnActivate(ObjectReference akActionRef)	If akActionRef == PlayerREF		If IsActivationBlocked()			Debug.Notification("Don't sleep, but run this code")			akActionRef.MoveTo(JailShipMarker)		Else			Debug.Notification("Sleep normally and run this code")		EndIf	EndIfEndEvent
User avatar
Jessica Stokes
 
Posts: 3315
Joined: Fri Jul 28, 2006 11:01 am

Post » Mon Nov 19, 2012 3:06 am

Should work the same on a bedroll exchanging 'open' with 'sleep'. Did you try that after the activation blockage OnInit style?
Spoiler
ScriptName GoToJailShipScript Extends ObjectReference Actor Property PlayerREF Auto ObjectReference Property JailShipMarker Auto Event OnInit() BlockActivation() EndEvent Event OnActivate(ObjectReference akActionRef) If akActionRef == PlayerREF If IsActivationBlocked() Debug.Notification("Don't sleep, but run this code") akActionRef.MoveTo(JailShipMarker) Else Debug.Notification("Sleep normally and run this code") EndIf EndIf EndEvent
I copied this script and loaded older save before I first time tried it but still nothing happens. Activation is blocked in all ways also the OnActivate.
User avatar
Matthew Aaron Evans
 
Posts: 3361
Joined: Wed Jul 25, 2007 2:59 am

Post » Sun Nov 18, 2012 10:51 pm

the last script can't work
The thing is:
If you block the player activation on an object, you will not able to interact *with* the player normally (you cant sleep), *but* the event still fire in the script.

My first script should work, assuming you are using it on a clean save.
Otherwise you can put the blockactivation call into the onactivate event: the first time you are using it, it will not block, but after it will

Scriptname GoToJailShipscript extends ObjectReferenceActor Property PlayerREF AutoObjectReference Property JailShipMarker AutoEvent oninit()   BlockActivation()  debug.notification("bed Blocked")endeventEvent OnActivate(ObjectReference akActionRef)   debug.notification("bed activated")   BlockActivation() ; in case you are not on a clean save   If akActionRef == PlayerREF		  debug.messagebox("teleportation")		  akActionRef.MoveTo (JailShipMarker)   EndIfEndEvent
User avatar
Nicholas
 
Posts: 3454
Joined: Wed Jul 04, 2007 12:05 am

Post » Mon Nov 19, 2012 10:26 am

I do this with my dead creatures. How I did it is add 2 scripts. One with OnActivate Event for block activation, the other with what I want to happen OnActivate.

So you have 2 events. I can't remember off the top of my head if I did have 2 seperate scripts, or both events in the same script. Either way I've done this to stop the inventory menu showing.
User avatar
kitten maciver
 
Posts: 3472
Joined: Fri Jun 30, 2006 2:36 pm

Post » Mon Nov 19, 2012 6:59 am

the last script can't work
The thing is:
If you block the player activation on an object, you will not able to interact *with* the player normally (you cant sleep), *but* the event still fire in the script.

My first script should work, assuming you are using it on a clean save.
Otherwise you can put the blockactivation call into the onactivate event: the first time you are using it, it will not block, but after it will

Scriptname GoToJailShipscript extends ObjectReferenceActor Property PlayerREF AutoObjectReference Property JailShipMarker AutoEvent oninit()   BlockActivation()  debug.notification("bed Blocked")endeventEvent OnActivate(ObjectReference akActionRef)   debug.notification("bed activated")   BlockActivation() ; in case you are not on a clean save   If akActionRef == PlayerREF		  debug.messagebox("teleportation")		  akActionRef.MoveTo (JailShipMarker)   EndIfEndEvent
With that I got "Bed Blocked" message when loaded the save file and every time when I'm trying to activate the bed I get "Bed Activated" message but nothing else happens.
User avatar
Daniel Brown
 
Posts: 3463
Joined: Fri May 04, 2007 11:21 am

Post » Mon Nov 19, 2012 9:48 am

ok so what I guess, is that you didn't properly assign your properties in the CK.

Open the object in the CK, double click on the script, you have the property listed here, and you need to link each property to the relevant object in the world.
If your property name has the same than the object name (which is at least the case for playerRef), you can do this with the autofill button, otherwise, you will have to link them manually.
User avatar
Rebecca Clare Smith
 
Posts: 3508
Joined: Fri Aug 04, 2006 4:13 pm

Post » Mon Nov 19, 2012 1:20 am

Ok so how I have it to block the inventory menu showing on a dead animal (which should translate to other things, like sleeping) is this.

I have a block script attached to the object:

Scriptname HISBlockActivation1 extends ObjectReference  {This script causes the actor to block activation upon loading.}Event OnLoad()BlockActivation(true)EndEvent

I then also have another script attached to it as follows:

Scriptname HISQuest1GoatRemains extends ObjectReference  Quest Property HISGuildQuest1  Auto  Event OnActivate(ObjectReference akActionRef)	if (akActionRef == Game.GetPlayer()) && (HISGuildQuest1.GetStage() == 10)			   HISGuildQuest1.SetStage(20)      elseif (HISGuildQuest1.IsCompleted());Do nothing   else  endifendEvent

It does other stuff, but I've removed those lines as you don't need them.
User avatar
Ashley Clifft
 
Posts: 3468
Joined: Thu Jul 26, 2007 5:56 am

Post » Mon Nov 19, 2012 11:39 am

I checked all the properties and they are linked right, I tried a few variations with different scripts but nothing seems to work. I made another script for blocking and the one only for the result I want but that didn't work either. I even made my scripts to use debug.CenterOnCell command and that only freezed the game.
I'm starting to feel frustrated with this. How can it be that so simple thing which takes me five minutes to do with Oblivion engine takes days with Skyrims engine and even after that it didn't work at all?
User avatar
SexyPimpAss
 
Posts: 3416
Joined: Wed Nov 15, 2006 9:24 am

Post » Mon Nov 19, 2012 10:46 am

User error. This works:
Spoiler
ScriptName GoToJailShipscript Extends ObjectReference ; Attached to either a bedroll reference or base form and not a ReferenceAlias;Make sure the below are penciled in (filled)Actor Property PlayerREF AutoObjectReference Property JailShipMarker AutoEvent OnInit()	BlockActivation()EndEventEvent OnActivate(ObjectReference akActionRef)	If akActionRef == PlayerREF		If IsActivationBlocked()			PlayerREF.MoveTo(JailShipMarker)			Debug.Trace("Don't sleep, but run this code")		Else			Debug.Trace("Sleep normally and run this code")		EndIf	EndIfEndEvent;/Event OnGrab() ; Just for testing purposes	BlockActivation(!IsActivationBlocked())	Debug.Notification("Activation blocked: " + IsActivationBlocked())EndEvent/;
You should be able to copypasta, fill the properties, and have it all work w/o issue so long as you're not testing with a dirty save.
User avatar
Andrew
 
Posts: 3521
Joined: Tue May 08, 2007 1:44 am

Post » Mon Nov 19, 2012 2:59 am

User error. This works:
Spoiler
ScriptName GoToJailShipscript Extends ObjectReference ; Attached to either a bedroll reference or base form and not a ReferenceAlias;Make sure the below are penciled in (filled)Actor Property PlayerREF AutoObjectReference Property JailShipMarker AutoEvent OnInit()	BlockActivation()EndEventEvent OnActivate(ObjectReference akActionRef)	If akActionRef == PlayerREF		If IsActivationBlocked()			PlayerREF.MoveTo(JailShipMarker)			Debug.Trace("Don't sleep, but run this code")		Else			Debug.Trace("Sleep normally and run this code")		EndIf	EndIfEndEvent;/Event OnGrab() ; Just for testing purposes	BlockActivation(!IsActivationBlocked())	Debug.Notification("Activation blocked: " + IsActivationBlocked())EndEvent/;
You should be able to copypasta, fill the properties, and have it all work w/o issue so long as you're not testing with a dirty save.
I tried this with a clean save and it worked. But I also had old code which didn't work earlier on another place and now even it worked right.
So on one bedroll I have this
Spoiler
Scriptname GoToJailShipscript extends ObjectReference

Actor Property PlayerREF Auto
ObjectReference Property JailShipMarker Auto

Event OnInit()
BlockActivation()
EndEvent

Event OnActivate(ObjectReference akActionRef)
If akActionRef == PlayerREF
If IsActivationBlocked()
Debug.MessageBox("Don't sleep, but run this code")
akActionRef.MoveTo(JailShipMarker)
Else
Debug.MessageBox("Sleep normally and run this code")
akActionRef.MoveTo(JailShipMarker)
EndIf
EndIf
EndEvent
And on another I have two scripts
Spoiler
Scriptname LockJailBedscript extends ObjectReference
{This script causes the actor to block activation upon loading.}

Event OnLoad()

BlockActivation()

EndEvent
Spoiler
Scriptname GoToJailShipTyrvalscript extends ObjectReference

Actor Property PlayerREF Auto
ObjectReference Property JailShipTyrvalMarker Auto

Event OnActivate(ObjectReference akActionRef)
If akActionRef == PlayerREF
akActionRef.MoveTo(JailShipTyrvalMarker)
endif
endEvent
Both ways gave me now same result and are working correctly. I wonder what was the problem I had with these earlier when they didn't work.

Thank you everyone for the help you gave me. All comments made me to read and learn more about the papyrus engine and its possibilities.
User avatar
Josh Trembly
 
Posts: 3381
Joined: Fri Nov 02, 2007 9:25 am

Post » Mon Nov 19, 2012 5:31 am

Both ways gave me now same result and are working correctly. I wonder what was the problem I had with these earlier when they didn't work.
Not sure, but glad to hear things are falling into place :foodndrink:
User avatar
Dewayne Quattlebaum
 
Posts: 3529
Joined: Thu Aug 30, 2007 12:29 pm

Post » Mon Nov 19, 2012 1:31 am

Not sure, but glad to hear things are falling into place :foodndrink:

So it wasn't user (me) error then? Was a "Save has old scripts" problem, as both my way and your way work ;)

Glad you got it sorted OP.
User avatar
Rebecca Clare Smith
 
Posts: 3508
Joined: Fri Aug 04, 2006 4:13 pm


Return to V - Skyrim