Steal an Item from another character

Hi there…

I am trying to work out how to have an AI character hold a Key item and the player sneak up and steal the key of it.

So, on begin play I would like the NPC to have a key, I creep up to it, throw a linetrace and steal the key. This should only happen once.

Currently, I have a function called Steal
image

in the function there is a short linetrace and a (Steal) interface set up.
When the trace hits the NPC, I have a do once > spawn actor from class (Key).

But if I keep pressing the T key for “Steal” it keeps spawning more keys.

Can anyone help me?
Thank you for any help.

Hey @mawilbolou,
Do you have any Logic for when it shouldn’t be allowed to steal a key? Like once the key is gone, it removes itself from the NPC? I can only see the logic for something that spawns a key if the NPC implements the Steal Item Interface, but nothing for checking if a key has been spawned already.
I hope this can help!
-Zen

Hi there, thanks for the reply Zen.
I dont have anything more than this. I cant work out the best way to do it.
Im sure that spawn actor from class isnt the best way to do it.

Any suggestions as to how you would structure it?

Not a real solution, more as a help as to what you have actually built, as far as i can see :slight_smile: Right now, you are not STEALING those items from your NPCs, right now, you CREATE those items out of thin air the moment your event can be triggered.

That “Do Once” node just makes sure, that it spawns only one item for each time you press that key (and not multiple per key pressing), but it does not prevent repeated key pressing and therefore event triggering and summoning new items.

Right now, you do not check, what items the NPC carries in his inventory (or if he even carries anything, that could be stolen), but that could be done with casting to that NPC you just successfully line traced.
Then you would need to check his inventory, if he carries that item (or any item, if steal just grabs a random item from the inventory), and delete it from the NPCs inventory before or after you you spawned it.

Not sure, how such an inventory would be realized, but it probably would be good to have all items a variable, that tells your system, that this item can be stolen, or cannot be stolen from that char.

In my tiny tests, i have some NPCs, that collect items, which lie around in the room, and the moment they pick it up, i of course cannot pick up those items anymore (usually would happen with an overlap event).
The moment those NPCs pick up those items and carry them, they cast to those items and switch a bool variable in that very item, that it “is stolen” or “is carried”. So for me to be able to get that item, i first have to kill that NPC, because the NPC death/kill event also resets this variable in all carried items to false, and i then can collect this item again.

1 Like

Thank you I will take that as a solution.
And I will look more in to it…

I did however manage to fix what I had.

Firstly, a friend told me that “a do once nodes don’t work inside a function”.

So I made a custom event instead of a function and it worked fine.

I also added a static mesh to the NPC of a key, and when my linetrace hit the NPC the static mesh got hidden.