Jump to content

Force an NPC to activate an object


StealthDick

Recommended Posts

as the title suggests, I made an NPC use the "Use Item At" package on an object with an OnActivate script and he just walks up to it.

 

The script goes:
Begin OnActivate npcREF

rewardxp 12 (placeholder variable just so i know if the npc activates it)
endif

end

Is there even a way I can force an NPC to activate something?

Link to comment
Share on other sites

What is the item? What should it look like when the NPC activates it? You can put a line somewhere like

ObjectRef.Activate NPCRef 1

I've had trouble getting stuff like this to work, even if it should.

 

Also, be aware that OnActivate blocks are glitched; they are not restricted to being called only when the calling reference (the object) is activated by the reference you specify.

Begin OnActivate npcREF 

will be called when anyone activates the object this script is attached to. Instead, you want:

Begin OnActivate
    If IsActionRef npcREF
        rewardxp 12 ;  (placeholder variable just so i know if the npc activates it)
    endif
end
Edited by EPDGaffney
Link to comment
Share on other sites

Hmmm I would have thought that "UseItem" is not the same as "Activate" Hence you couldn't activate something (Cause an "ONActivate" block to run) by an npc simply doing a "UseItem"

 

Even though , the npc did something like open a door , or get something out of a container.

It seems you would still have to have a call of "Activate" in a script , before "OnActivate would execute ???

Link to comment
Share on other sites

So i have this object that I attached an OnActivate script to
I want the NPC to walk up to it activate it.
Its just a static activator, but in the objects script when the NPC activates its supposed to disable making it look like he's picking it up.
does ObjectRef.Activate NPCRef force the npc to activate it?

Link to comment
Share on other sites

That's exactly what it does, but it won't play any animations unless they're in the OnActivate block in the script attached to the item. You can use this function:

https://geckwiki.com/index.php/PlayIdleEx

 

Also, I forgot that you're trying to run the OnActivate block when I wrote you that message. You actually need to set a flag to cause it to run that object's script instead of its default activation, meaning you actually want this:

ObjectRef.Activate NPCRef 1

By default, that flag is set to 0 (even if you don't specify by typing the 0), so if it's a door, the door will just open (or close), or if it's an item, they'll pick it up, even if the object or item in question has a script with an OnActivate block.

 

Instead, when you set this flag to 1, you make it run its OnActivate block instead of normal activation. So, a door with an OnActivate block will not open or close unless its OnActivate block contains code to make it do so (just Activate will do it, though you could use SetOpenState if you want to be more specific).

 

The point of all this is that if you can't get this to work right via the UseItemAt package or Find package, the answer to your question is that yes, you can technically 'force' an NPC to activate something. You can use a Travel package and a trigger box that forces this, or a GameMode block with GetDistance or whatever you like.

 

However, I would try to get it to work with UseItemAt or Find, as these are more standard and more likely to be simple and fluid and better for performance (well, only slightly better, most likely).

 

What flags are you setting in the package? Can you screenshot each tab?

Edited by EPDGaffney
Link to comment
Share on other sites

Great. Just make sure you test it a fair bit. Scripts placed there are unreliable in some situations. And if it's possible for the player to leave in the middle of this package, make sure it does what you want. And make sure you've accounted for the player possibly activating the activator, or any other weird stuff you can think of.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...