It would be pretty simple to do this, only problem would be the gun wouldn't turn as you drove along:
[truck/halftrack]
addtemplate at_gun_spawner
create objectspawn at_gun_spawner
team 0 pak40_mobile
holdonvehicle 1
Done. Then when someone jumps into the at gun and presses forward it drops off the truck/halftrack. Can't re-attach, but that would be impossible to do anyway.
There are other problems, like the gun will spawn back onto the truck once the gun dies. IIRC if you make the respawn timer very long the next time the truck spawns it won't have the gun on it, but that I'm not sure of.