Hey there GaReb!
The simple solution is to clearWeapon/MagazineCargo initially, and then in the OnTrue event addWeapon/Magazinecargo as you want.
Well, there's a slight problem with using an ammo-crate here. Say for instance you want the ammocrate's contents to only be accessible to someone who enters the correct code. The problem here is that there's no way to count the amount of ammo inside a crate, meaning if that someone opens the crate, changes weapons around, and then closes it again, there's no way to tell how much has been changed. Furthermore, there's no way to prevent people from accessing the empty ammo crate and depositing guns n' ammo there, that might in turn be deleted when the ammo crate is "locked" again.
If this isn't a problem, and you don't mind the ammobox being refilled every time it's "opened" (and everything extra put into it deleted) then something like this should work. If you don't want the ammobox emptied, just remove everything after Player action ["gear"...] and instead use a removeAction to prevent the player from continually filling the box:
OnTrueAmmoBox1 =
{
// Start of script. Sleeps one second to let the player know he's succeeded, then closes the codepad dialog.
sleep 1;
closeDialog 0;
// Adds the ammo and weapons : put whatever you want here.
AmmoBox1 addweaponcargo ["M4", 2];
AmmoBox1 addmagazinecargo ["PipeBomb", 10];
// Extra stuff. Using the gear action makes the player automatically try to access the box - might not work if the player is too far away.
Player action ["gear", AmmoBox1];
sleep 1;
// Uncomment the following line if you just want a one-shot unlock, and delete the clearMagazine/weapon cargo entries!
// AmmoBox1 removeAction 0;
// Waits until the gear dialog is closed
waitUntil {(isNull (findDisplay 106))};
// Clears the magazine and ammo cargo again
clearMagazineCargo AmmoBox1;
clearWeaponCargo AmmoBox1;
//End of script
};
Name of the Ammo box is AmmoBox1 of course. The action would look something like:
AmmoBox1 addAction ["Unlock Box", "CodePad.sqf", [[1, 2, 3], OnTrueAmmoBox1, {ctrlSetText [999,"Wrong code!"]; sleep 1; ctrlSetText [999, ""];}]];
Hope that helps, and isn't too complicated!
Wolfrug out.