Spawning DarkRP weapons with a function

Hello, I am trying to make a module to DarkRP that spawns a weapon somewhere on the map. I can spawn the weapons, but they are not like the ones you buy in the f4menu, they get picked up as soon as you walk on them. This is the current code I am using:

local function dropWeapon(player,weapon)

     local pos = ply:GetEyeTraceNoCursor();

     entity = ents.Create("weapon_deagle2")
     entity:SetPos(ent:SetPos(pos.HitPos + pos.HitNormal * 32);)


What I need is to be able to spawn weapons like you would take a weapon out of the DarkRP pocket.

change “weapon_deagle2” to “spawned_weapon” and then add this line:
entity.weaponclass = “weapon_deagle2”

Also remember to set the model to deagle, otherwise it’ll appear as an error.

It works like a charm, thank you so much. Been trying to do this for several hours. Is there a similar to spawn entities such as money printers and food?

spawned_food seems to be the template entity for food.
You should check the entities folder in darkrp.