Ammo Box Help

i wanted to make an Box so that every time i click Use (E) On It then it gives me 20 Pistol Ammo

i Tried Here Just where it adds 5hp

but when i try it out it says

ammo Is An unknown command

Please Help ME. And DO NOT BAN ME AGAIN PLEASE!


function Ammo( ply )

barrel=ents.Create(“prop_physics”)
barrel:SetModel(“models/items/ammocrate_rockets.mdl”)
barrel:SetPos(ply:GetEyeTrace().HitPos)
barrel:Spawn()
function barrel:Use( activator, caller )

if ( activator:IsPlayer() ) then

	local health = activator:Health()
	activator:SetHealth( health + 5 )

end

end

concommand.Add(“Testammo”, Ammo)


well because the command is Testammo and not ammo?


function SpawnAmmoBarrel( ply )


barrel = ents.Create("prop_physics")
barrel:SetModel("models/items/ammocrate_rockets.mdl")
barrel:SetPos(ply:GetEyeTrace().HitPos)
barrel:Spawn()
function barrel:Use( ply )

	if ply:IsValid() and ply:Alive() then
	ply:GiveAmmo( 20, "pistol" )
	end

concommand.Add("AmmoBarrel", SpawnAmmoBarrel)

Not sure if you can even set functions on an entity like that, but give this a go.



function SpawnAmmoBarrel( ply )


barrel = ents.Create("prop_physics")
barrel:SetModel("models/items/ammocrate_rockets.mdl")
barrel:SetPos(ply:GetEyeTrace().HitPos)
barrel:Spawn()
function barrel:Use( ply )

	if ply:IsValid() and ply:Alive() then
	ply:GiveAmmo( 20, "pistol" )
	end
end
end
concommand.Add("AmmoBarrel", SpawnAmmoBarrel)


you didn’t end your functions

ENT.Use is a hook that only works for custom entities defined in lua/entities.

I did that on the spot, and it was midnight, Sorry ^_^’

The Ammo Crate Spawns But it wont give any ammo
:confused:

I noticed that also, i think it’s spawning too far below the ground? im not sure.

simple darkrp entity


AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")

function ENT:Initialize()
	self:SetModel("models/items/ammocrate_rockets.mdl")
	self:PhysicsInit(SOLID_VPHYSICS)
	self.Entity:SetUseType(  SIMPLE_USE )
	self:SetMoveType(MOVETYPE_VPHYSICS)
	self:SetSolid(SOLID_VPHYSICS)
end

function ENT:Use(activator, caller)
activator:GiveAmmo( 20, "SMG1" )
end


list of the ammo


AR2 - Ammunition of the AR2/Pulse Rifle
AlyxGun - (name in-game "5.7mm Ammo")
Pistol - Ammunition of the 9MM Pistol 
SMG1 - Ammunition of the SMG/MP7
357 - Ammunition of the .357 Magnum
XBowBolt - Ammunition of the Crossbow
Buckshot - Ammunition of the Shotgun
RPG_Round - Ammunition of the RPG/Rocket Launcher
SMG1_Grenade - Ammunition for the SMG/MP7 grenade launcher (secondary fire)
SniperRound
SniperPenetratedRound - (name in-game ".45 Ammo")
Grenade - Note you must be given the grenade weapon (e.g. pl:Give ("weapon_grenade")) before you can throw any grenades
Thumper - Ammunition cannot exceed 2 (name in-game "Explosive C4 Ammo")
Gravity - (name in-game "4.6MM Ammo")
Battery - (name in-game "9MM Ammo")
GaussEnergy 
CombineCannon - (name in-game ".50 Ammo")
AirboatGun - (name in-game "5.56MM Ammo")
StriderMinigun - (name in-game "7.62MM Ammo")
HelicopterGun
AR2AltFire - Ammunition of the AR2/Pulse Rifle 'combine ball' (secondary fire)
slam - See Grenade