How to add an item to inventory when in sneak only?

Post » Tue Jan 19, 2010 8:16 am

I have a potion that runs a script when it is activated in the "physical world" so it's not picked up when activated but I want to make it so I can pick it up(put in my inventory) when it's activated while in sneak mode. I've looked at some other mods but the method they use is basically spaghetti code and I know there has to be a more simple way. I'm thinking roughly the following:

If player.sneak == 1     player.addRefidOfActivatedInstance     elseif     potionRunScript(blah blah)endif


I just can't find out how to get the refid of the instance. Or if there's just an easier way to add the activated item to inventory then I would appreciate some help. Thanks, -d.
User avatar
Natalie Taylor
 
Posts: 3301
Joined: Mon Sep 11, 2006 7:54 pm

Post » Tue Jan 19, 2010 12:57 pm

begin onactivate if isactionref player == 1 ; prevents NPCs from triggering it, heard that can happen with some mods that add more 'active' NPCs    if player.issneaking == 1    activate player    endifendifend

User avatar
Katharine Newton
 
Posts: 3318
Joined: Tue Jun 13, 2006 12:33 pm

Post » Tue Jan 19, 2010 4:52 am

Sorry, should've been more specific but what I need to know is how to add an item to inventory in script. Is there a function that will add that particular refid (not base item) to my inventory?
User avatar
James Wilson
 
Posts: 3457
Joined: Mon Nov 12, 2007 12:51 pm

Post » Tue Jan 19, 2010 4:17 am

That will do it.

Just add an elseif to contain the code you want to have happen when not sneaking.

What will happen is that when the player activates it, if they aren't sneaking it will run the script section in the elseif. If they are sneaking, then the normal activation function will be called...in other words it will be picked up and placed in the players inventory.

You can even do it remotely, if you want. Just use "refid.activate player" and it will be picked up and put in the player's inventory.
User avatar
JD FROM HELL
 
Posts: 3473
Joined: Thu Aug 24, 2006 1:54 am


Return to IV - Oblivion