You need to create a WeaponHolder and place it on the ground. This is an invible object that just gives you a place to put ammo and weapons.
W1="weaponholder" createVehicle [x,z,y]
Note, as always, instead of x, z and y co-ordinates you can Getpos another object.
Then just addweapon cargo like you would an ammo crate.
W1 addWeaponCargo ["M16",1]