Using a key item to use an activator

Post » Sun Nov 18, 2012 11:23 am

I have this custom activator in my mod that does a bunch of things when activated, opens a door, turns on lights, plays effects and sounds etc. Everything works like a charm, but I'd like to make it so that it can only be activated when the player has a certain item. I don't want it to be involved in any quest at this point. The best thing would be using some vanilla scripts, but I can't find anything that fits the situation, even though this feels like the simplest thing ever to implement.
User avatar
Dean Ashcroft
 
Posts: 3566
Joined: Wed Jul 25, 2007 1:20 am

Post » Sun Nov 18, 2012 11:10 am

Make the required item a property in your script. Here is an example script (coding from memory so may not be exact). You need the if lines :smile:

Script name Script1 extends object referenceItemName property autoPlayer property(other properties you need)Event OnActivateIf Player.GetItemCount(ItemName) == 1;we're saying if the player has 1 of this item   ;do something here like enable objects etc	  Elseif		  ;do nothingEndifEndEvent

EDIT

Fixed
User avatar
Peter P Canning
 
Posts: 3531
Joined: Tue May 22, 2007 2:44 am

Post » Sun Nov 18, 2012 8:21 pm

Yeah, GetItemCount was the most logical thing I found, but I'm not sure how I should be using it. I probably have a wrong approach to begin with: The activator itself has no scripts attached, but it simply acts as a parent to the things it activates. Those individual objects have scripts of their own. So, is it possible to just attach a new script to the activator that kind of "disables it" if the player doesn't have the item, or do I have to modify how the other objects are activated as well?
User avatar
Emily Rose
 
Posts: 3482
Joined: Sat Feb 17, 2007 5:56 pm

Post » Sun Nov 18, 2012 12:20 pm

Yeah, GetItemCount was the most logical thing I found, but I'm not sure how I should be using it. I probably have a wrong approach to begin with: The activator itself has no scripts attached, but it simply acts as a parent to the things it activates. Those individual objects have scripts of their own. So, is it possible to just attach a new script to the activator that kind of "disables it" if the player doesn't have the item, or do I have to modify how the other objects are activated as well?

How does the activator activate the objects?

I'm thinking maybe just have the if count == 0 do nothing part of the script, and that's it. So any time the player activates it without the object, nothing should happen.
User avatar
mike
 
Posts: 3432
Joined: Fri Jul 27, 2007 6:51 pm

Post » Sun Nov 18, 2012 6:39 pm

How does the activator activate the objects?
The activator is simply set as an activate parent to the other objects, so when it's activated the other objects are as well. (It's now activated by simply pressing E, and this is actually what I'd like to change.) Obviously, doors and similar objects work automatically like this. For other objects I'm using OnActivate scripts.

I'm thinking maybe just have the if count == 0 do nothing part of the script, and that's it. So any time the player activates it without the object, nothing should happen.

The thing is, there's no "the script".
User avatar
Mariaa EM.
 
Posts: 3347
Joined: Fri Aug 10, 2007 3:28 am

Post » Sun Nov 18, 2012 1:46 pm


The activator is simply set as an activate parent to the other objects, so when it's activated the other objects are as well. (It's now activated by simply pressing E, and this is actually what I'd like to change.) Obviously, doors and similar objects work automatically like this. For other objects I'm using OnActivate scripts.



The thing is, there's no "the script".

Well stick a script on there. If it behaves like an activator, then an OnActivate script like I posted above will work. Ive done it lots of times mate for various things in my mod.

But just use the if count == 0 do nothing fragment. That way if you have the item it'll just work. If not, it won't.
User avatar
Tyrone Haywood
 
Posts: 3472
Joined: Sun Apr 29, 2007 7:10 am

Post » Sun Nov 18, 2012 4:27 pm

It's really that simple? It's so easy I didn't even bother trying it. Thanks for the help man, I'll give it a shot when I get home!
User avatar
Charlotte Lloyd-Jones
 
Posts: 3345
Joined: Fri Jun 30, 2006 4:53 pm

Post » Sun Nov 18, 2012 3:37 pm

if the activator is a parent activation object, it will activate its children regardless of the OnActivate block on its script, so adding a script to the parent activator actually does nothing. in plain english this is what happens if you add a condition script to the parent activator:

"if the object is activated, run the OnActivate block in ADDITION to already activating its children" (so in this case, a "do nothing" condition actually does nothing different than not having a script at all)

you need to either remove the parent activation (and force-activate via condition in a script attached to the parent using all of its children as objrefs - not recommended if there are many children), or add a getitem condition check in every script of the child objects (annoying and slower with more property clutter,, but overall less persistence tax).
User avatar
Maddy Paul
 
Posts: 3430
Joined: Wed Feb 14, 2007 4:20 pm

Post » Sun Nov 18, 2012 3:32 pm

:facepalm:

Well there's something new I've learned about parent activation. Perhaps I was thinking of parent enabling. Hmm, yes that's the one. Lots of enable objects with my script through enable parent. Sorry dude.
User avatar
JLG
 
Posts: 3364
Joined: Fri Oct 19, 2007 7:42 pm

Post » Sun Nov 18, 2012 10:51 am

if the activator is a parent activation object, it will activate its children regardless of the OnActivate block on its script, so adding a script to the parent activator actually does nothing.

Ok, this how I imagined it would work in the first place.

What if I make another hidden activator to act as a parent to the children. It could be then activated via script attached to the original parent (which is no longer a parent to anything)? Does this make any sense?
User avatar
Emma Parkinson
 
Posts: 3401
Joined: Wed Jul 26, 2006 5:53 pm

Post » Sun Nov 18, 2012 3:33 pm

that would work as well. you can have your actual parent be an invisible non-collision object (but it still needs to be considered a player-activatable object). then have your interactive activator object use the condition script that passes the Activate() onto the hidden activator (declared as an objref property in the script). you also dont need to use disable/enable

just remember that HiddenParentActivator.Activate(PlayerRef) will not actually activate the hidden object unless the object can accept player activation. you can achieve this by using a non-collision marker object (like one of the dummy objects), but still giving it an arbitrary visible in-game name (but since the object has no collision you wont be able to mouse over it, but it still is considered player-activatable).


if you dont want to mess around with invisible objects for your parent activate and just keep it as is with its 3d mesh, just move the activator off-screen somewhere it cannot be seen by the player (push it far out into the void space of your cell). calling Activate() via script remotely will still work perfectly fine from the visible activator object.
User avatar
Heather M
 
Posts: 3487
Joined: Mon Aug 27, 2007 5:40 am

Post » Sun Nov 18, 2012 9:46 pm

Finally nailed it using the extra activator. Works perfectly, thanks for the help!
User avatar
Karl harris
 
Posts: 3423
Joined: Thu May 17, 2007 3:17 pm


Return to V - Skyrim