Godot 3(not 4)pick up and use items

Godot Version

Godot 3 .2.3 stable

Question

(A) you are walking across a platform you find a gun on the ground you pick it attach it to the player then using a key like (S for example) it shots bullet.

(b) you find a knife you then use a key like (T for an example) to throw it.. (and based on what it hits you either kill and enemy or brake windows etc..)

(C) you find an apple you put it into your inventory then later you give it to an NPC eat or sell it)

So what is your question / problem?

I recommend checking Posting guidelines in #Help channel

[A]

[1] how do you pick up the gun [2] how do you attach it to player (3) how to make shot

[B]

[1] how do you pick up knife [2] how do you throw it [3} how do you tell what if if hits enemy then kill enemy or if it hits window how do brake window

[C]

how do you pick up apple how do you put into inventory how do take it out of inventory and hand it to NPC

All of these are very subjective, and require even more subjective systems to even start a solution. Do you have an inventory and equipment system? An interactable system can be made outside of these systems and emit a common signal to work with your systems.

Interactables typically are by proximity, especially in 2D, so a good start could be to use an Area2D to detect when the player enters and exits the interactable area. If the player is inside the zone and pressed the correct button, you can emit the signal

# interactable area.gd
extends Area2D
class_name Interactable

var target_player: Player

signal interacted(by: Player)

func _on_area_entered(body: Node2D) -> void:
    if body is Player:
        target_player = body


func _on_area_exited(body: Node2D) -> void:
    if body == target_player:
        target_player = null


func _unhandled_input(event: InputEvent) -> void:
    if target_player != null: # someone is in the zone
        if event.is_action_pressed("interact"): # and they pressed 'interact'
            interacted.emit(target_player) # emit!

From this you can connect the interacted signal to your other systems.

Honest question , why are you still on Godot 3? Things have moved on somewhat.

Thanks for pointing to an Area2D proximity check and a shared interacted signal. For Godot 3.2.3, is that still the usual first step before wiring a separate inventory, or does pickup need to live inside the inventory system from the start?