Whew! Lots here to reply to.
I'll take it as it came:
Well my intent was to make an addon as you described, but for use with Earl's magazines from the Marine Assault Pack. The script would be contained in the addon... The jammed magazine would be identical to the addon's standard magazines, but with differing bullet counts.
That's a pretty good idea that I hadn't even thought of. I was thinking that the original addon maker would have to config all the magazines, but I never thought about just inheriting from the original addon in a whole new addon. That's also nice because you can "hard code" all the magazine type/muzzle type names into the scripts inside the addon, so the mission maker doesn't have to worry about setting stuff up himself (more on that later).
I'm imaging the following:
Editor adds the following code to any unit using a weapon from Earl's Russian weapon pack:
[this,.03,0,.06] exec "\kmkC8XrussJamIt\initunit.sqs"
....
The fired EH would make sure the primary weapon was fired, then roll the dice based on the failure rates, and then swap out the mag with one contained in the addon with the correct bullet count (but same ammo type, sounds, config data as the regular mag) as you described.
Is this how you envisioned it? Seems pretty straightforward, I think.
Pretty much. However, the problem with that is when the player (or AI under his control) picks up a different weapon. So instead of passing the jam rates to the script on a per-unit basis, it seems that having a global variable of some sort that would have the jam-rates of each weapon would make more sense (or groupings of weapons, the specifics can be worked out for best performance). You could have a single parameter passed on a per-unit basis that would scale these jamming rates for that unit (to simulate his individual training level). So it would look more like this:
[this, <number from 0-1>] exec "jamscript.sqs"
Then there might be perhaps 3 global arrays:
low_jam_rate = ["m16","ak47","ak74"]
med_jam_rate = ["pk","m60"]
high_jam_rate = ["...."]
Then 3 more global numbers determining how often each of these catagories of weapons will jam in this specific mission. Any weapon not in one of these catagories would default to the lowest or something. Anyway, you get the idea, but the specifics could be changed. This was just how I was imagining putting it into the ECP.
I always consider string comparisons a last resort...especially without string case functions.
Actually, in the case of classnames, ofp ignores the case. Odd, undocumented, but helpful
. So "M16" is equal to "m16", so there shouldn't be any problem using string comparisons in a script like this.
Boy, you know what would make this much simpler? Instead of removing magazines, just remove the weapon instead.
Well, I never tried taking the weapon away for a long period of time. But when I removed it and put it back right away, the mag would stay loaded in the weapon.
Oh, nm, I see what you are saying.
The only issue is having the weapon disappear...how much of a show stopper is that?
If the choice is between having the weapon disappear for 3 seconds, and magically gaining bullets, I'd take the latter. I'm sure most others would say the same. Aside from the obvious visual weirdness, keep in mind that you move differently (slower) when you don't have a weapon.
To reiterate, trying to work it with the magazines is a nightmare when you think about addons. Or missions that use both standard/3rd party mags AND JAM2 magazines...you just can't tell what the player has loaded in the weapon at a given moment (can you?). And without an explicit string comparison against every possible magazine in the mission, you can't really know which magazines in the inventory are for a primary weapon.
Well, I suppose this script relies on the premise that for each weapon, there is only one magazine type. True, in some missions a player COULD have both HD and regular mags for the same weapon (for example), but in most missions that isn't the case.
Had you given any thought to the dual muzzle issue?
A little bit, but I'm not quite clear on how they work in terms of scripting or config. Perhaps the "mode" (burst, semi, etc) section of the EH can tell you if a GL was shot?
-------
So anyway, there are definately some *complications* in turning this into a reality. In the ECP, I was going to have to settle for gross-imperfection, because I have no control over either the mission or the addons used. However, if it were a script used by the mission maker, then he DOES have that control, and can configure certain global variables to match what is in his mission. If it is in an addon, then full control is there, because you know what classnames are in the addon.
So I think it could work out pretty well, especially for an addon. Perhaps we should work together and make this a reality? Both an imperfect script for editors to use w/o an addon, and an addon that uses the script to it's maximum potential?
Specifically, there is work on a new version of JAM (called MAAM). That's a great opportunity to work this script into a really good addon. Then hopefully other addonmakers will follow suit.