Note to mods: Apologies for starting another thread on this topic, the other threads didnt seem to have real content, hopefully, users will modify the below system and implement improvements
i saw the following thread, havent read through it fully.
http://www.ofpec.com/yabbse/index.php?board=8;action=display;threadid=20417Hope this does the trick for ya
I created a rather simplistic weapon jamming system, here it is
set to work on players only
using eventhandler "fired"
Stage 1this sections runs a random generator for each player
If the random number generated on that players client is greater than 90, then there is a possibility that his weapon will jamINIT.sqs_weaponjam = random 100
?(_weaponjam >= 90): player addEventHandler ["Fired", {_this exec "gunjammed.sqs"}]
Stage 2If the player has the event handler attached to him, then everytime he fires his weapon the following is run
this sections runs a random generator for each player
If the random number generated on that players client is greater than 98, and the weapon fired is his primary then his primary weapon will jamgunjammed.sqs?! (local Player): exit
_jam_chance = random 100
?(_jam_chance >= 98):goto "Jammed"
exit
#JAMMED
_Player = _this select 0
_weapon = _this select 1
? (_weapon == Primaryweapon Player):goto "NEXT"
;;? (_weapon == Secondaryweapon Player):goto "NEXT"
exit
#NEXT
_weapArray = weapons player
_magArray = magazines player
? (tx_spawning): goto "END"
removeallweapons player
{player addWeapon _x} forEach _weapArray
;;; the following blue lines are muzzle fixes for multi muzzle mode weapons
?(_weapon == "M16GrenadeLauncher"): _weapon = "M16Muzzle"
?(_weapon == "UKF_SA80AG36"): _weapon = "UKF_SA80AG36Muzzle"
;;; Add additional multi muzzle weapon fixes here (see list below)
player selectweapon _weapon
hint format ["***** %1 *****\n\nYour %2 has jammed\n\n Try Reloading",name player,_weapon]
;;; tx_spawning is something i use specific to my missions to indicate if a unit is in respawn (no point in running the jam if he's been killed)
? (tx_spawning): goto "END"
~0.2
? (tx_spawning): goto "END"
hint format ["***** %1 *****\n\nYour %2 has jammed\n\n Try Reloading",name player,_weapon]
~0.2
? (tx_spawning): goto "END"
~ 1
? (tx_spawning): goto "END"
;;; the following section determines if the jam is more severe than a non ejected case and therefore if the unit has to carry out blockage drills
_random = random 100
?(_random >70): goto "MajorJam"
;;; if it isn't a major blockage, the magazines are given back to the unit and then he can carry out a reload action and carry on as normal
{player addMagazine _x} forEach _magArray
hint format ["***** %1 *****\n\n!!! BLOCKAGE CLEARED !!!\n\n #### Reload ###",name player]
exit
#MAJORJAM
? (tx_spawning): goto "END"
tx_Jam_mags = _magArray
~3
? (tx_spawning): goto "END"
hint format ["***** %1 *****\n\nJammed Solid\n\n!!!!! FIND COVER !!!!\n\nCarry Out Blockage drills",name player]
Blockagedrill = Player addaction ["Clear Blockage","misc\blockagedrill.sqs"]
exit
If the blockage is a major blockage, then further action is required by the unit to remove it.
This is done by adding an action to the unit (following line is run by the script at stage 2
Blockagedrill = Player addaction ["Clear Blockage","misc\blockagedrill.sqs"]
Stage 3This only occurs if there is a major blockage
Basically it forces the unit into a series of anims to make it look like the unit is clearing a major weapon blockage
(it allows the unit to find cover before carrying out the blockage drill, by using an action command in the units action menu)
Blockagedrill.sqs?! (local Player): exit
? (tx_spawning): goto "END"
player playmove "CrouchToWeapon"
? (tx_spawning): goto "END"
player playmove "CombatReloadMortarEnd"
? (tx_spawning): goto "END"
player playmove "CombatToCrouch"
? (tx_spawning): goto "END"
~7
? (tx_spawning): goto "END"
{player addMagazine _x} forEach tx_Jam_mags
hint format ["***** %1 *****\n\nYou managed to clear the jam\n\n #### Reload ###",name player]
#END
Player removeaction Blockagedrill
exit
Thats the weapon jamming system in its entirity.
If the mission has respawn, then you need to add the following elements
1) An addeventhandler "killed" to run a respawn script
lets call it
player addEventHandler ["killed", {_this exec "playerkilled.sqs"}]
2) and these lines need adding to your respawn system/respawn script
;; Immediately on deathPlayer removeaction Blockagedrill
player removeAllEventHandlers "Killed"
player removeAllEventHandlers "Fired"
;; As soon as unit is alive againplayer addEventHandler ["killed", {_this exec "playerkilled.sqs"}]
_weaponjam = random 100
?(_weaponjam >= 90): player addEventHandler ["Fired", {_this exec "gunjammed.sqs"}]
***************************************************************
FOR REFERENCEThe comref entry for fired eventhandlers is incorrect
here's what it actually returns
;;__________ Fired eventhandler returns________
_Player = _this select 0
_weapon = _this select 1
_muzzle = _this select 2
_mode = _this select 3
_ammo = _this select 4
I used use this line to prove it
hint format ["Player fired = %1\n\nWeapon = %2\n\nmuzzle = %3\n\nmode = %4\n\nammo %5",_Player,_weapon,_muzzle,_mode,_ammo]
NB>>> for some reason _ammo does not always return the magazine nameThis is why i remove and instantly replace the weapon, its a bugfix if you like
instead of just removing the magazines
If i was to remove the magazines, i would have to run a long list of magazine fixes, much in the same was as the l muzzle fixes
;;#####################################################################################################################
MUZZLE FIXES;;;;; weapons with additional muzzle types, eg grenade launchers, require the following lines added, when that weapon is used used
?(_weapon == "M16GrenadeLauncher"): _weapon = "M16Muzzle"
?(_weapon == "Ak74GrenadeLauncher"): _weapon = "AK74Muzzle"
?(_weapon == "Ak47GrenadeLauncher"): _weapon = "AK47Muzzle"
;;;;;;;;;; SUCHEY & EARL / WGL
?(_weapon == "C8XM16M203") : _weapon = "M16Muzzle"
?(_weapon == "C8XM16M203reflex") : _weapon = "M16Muzzle"
?(_weapon == "C8XM16M203acog") : _weapon = "M16Muzzle"
?(_weapon == "C8XM16M203cco") : _weapon = "M16Muzzle"
?(_weapon == "C8XM4M203") : _weapon = "M4Muzzle"
?(_weapon == "C8XM4M203cco") : _weapon = "M4Muzzle"
?(_weapon == "C8XM4M203reflex") : _weapon = "M4Muzzle"
?(_weapon == "C8XM4M203acog") : _weapon = "M4Muzzle"
?(_weapon == "C8XM4M203_SD") : _weapon = "M4Muzzle"
?(_weapon == "C8XM4M203reflex_SD") : _weapon = "M4Muzzle"
?(_weapon == "C8XM4M203acog_SD") : _weapon = "M4Muzzle"
?(_weapon == "C8XM4M203cco_SD") : _weapon = "M4Muzzle"
?(_weapon == "C8XAK74MGP25") : _weapon = "AK74MMuzzle"
?(_weapon == "C8XAK74MGP25cobra") : _weapon = "AK74MMuzzle"
?(_weapon == "C8XAK74MGP251p29") : _weapon = "AK74MMuzzle"
?(_weapon == "C8XAK74MGP25_sd") : _weapon = "AK74MMuzzle"
?(_weapon == "C8XAK74MGP25cobra_SD") : _weapon = "AK74MMuzzle"
?(_weapon == "C8XAK74MGP251p29_SD") : _weapon = "AK74MMuzzle"
?(_weapon == "C8XAKS74UBS1") : _weapon = "AKS74UMuzzle"
?(_weapon == "C8XAKS74UBS1cobra") : _weapon = "AKS74UMuzzle"
?(_weapon == "C8XJAMM16M203") : _weapon = "M16Muzzle"
?(_weapon == "C8XJAMM16M203reflex") : _weapon = "M16Muzzle"
?(_weapon == "C8XJAMM16M203acog") : _weapon = "M16Muzzle"
?(_weapon == "C8XJAMM16M203cco") : _weapon = "M16Muzzle"
?(_weapon == "C8XJAMM4M203") : _weapon = "M4Muzzle"
?(_weapon == "C8XJAMM4M203cco") : _weapon = "M4Muzzle"
?(_weapon == "C8XJAMM4M203reflex") : _weapon = "M4Muzzle"
?(_weapon == "C8XJAMM4M203acog") : _weapon = "M4Muzzle"
?(_weapon == "C8XJAMM4M203_SD") : _weapon = "M4Muzzle"
?(_weapon == "C8XJAMM4M203reflex_SD") : _weapon = "M4Muzzle"
?(_weapon == "C8XJAMM4M203acog_SD") : _weapon = "M4Muzzle"
?(_weapon == "C8XJAMM4M203cco_SD") : _weapon = "M4Muzzle"
?(_weapon == "C8XJAMAK74MGP25") : _weapon = "AK74MMuzzle"
?(_weapon == "C8XJAMAK74MGP25cobra") : _weapon = "AK74MMuzzle"
?(_weapon == "C8XJAMAK74MGP251p29") : _weapon = "AK74MMuzzle"
?(_weapon == "C8XJAMAK74MGP25_sd") : _weapon = "AK74MMuzzle"
?(_weapon == "C8XJAMAK74MGP25cobra_SD") : _weapon = "AK74MMuzzle"
?(_weapon == "C8XJAMAK74MGP251p29_SD") : _weapon = "AK74MMuzzle"
?(_weapon == "C8XJAMAKS74UBS1") : _weapon = "AKS74UMuzzle"
?(_weapon == "C8XJAMAKS74UBS1cobra") : _weapon = "AKS74UMuzzle"
;;;;;;;;;; BAS
?(_weapon == "BAS_M4MKMuzzle") : _weapon = "BAS_M4Muzzle"
?(_weapon == "BAS_M4RMKMuzzle") : _weapon = "BAS_M4RMuzzle"
?(_weapon == "BAS_M4ReflexM203Muzzle") : _weapon = "BAS_M4ReflexMuzzle"
?(_weapon == "BAS_M4ReflexSM203Muzzle"): _weapon = "BAS_M4ReflexSMuzzle"
;;;;;;;;;; JAM
?(_weapon == "JAM_M203Muzzle") : _weapon = "JAM_M16Muzzle"
?(_weapon == "JAM_GP25Muzzle") : _weapon = "JAM_AKMMuzzle"
?(_weapon == "JAM_GP30Muzzle") : _weapon = "JAM_AK74Muzzle"
;;;;;;;;;; LASER
?(_weapon == "LSR_jgpMuzzle") : _weapon = "LSR_jak103Muzzle"
?(_weapon == "LSR_jbsMuzzle") : _weapon = "LSR_jaksubMuzzle"
?(_weapon == "LSR_jgpMuzzle") : _weapon = "LSR_jak74mMuzzle"
;;;;;;;;;; SEB NAM
?(_weapon == "sebak47glmuzzle") : _weapon = "sebak47muzzle"
?(_weapon == "sebm16a1m203muzzle") : _weapon = "sebm16a1muzzle"
?(_weapon == "sebcar15glmuzzle") : _weapon = "sebcar15muzzle";;;;;;;;;;; SWI PE90
?(_weapon == "SWI_Pe90GLMuzzle") : _weapon = "SWI_Pe90Muzzle"
;;;;;;;;;; MISC
?(_weapon == "M203Muzzle") : _weapon = "M16Muzzle"
?(_weapon == "M203Muzzle") : _weapon = "M4Muzzle"
?(_weapon == "GP25Muzzle") : _weapon = "AK74MMuzzle"
?(_weapon == "BS1Muzzle") : _weapon = "AK74SUMuzzle"
[/color]
PLEASE NOTE1) There is much scope for improvement in this script
2) It is fairly efficient, as it uses eventhandlers
3) The random generator percentages are about right
4) It is possible to get a run of jams
5) Most jams are of the reload type (Not major)
6) It has been tried and tested on a mission, and the players didnt get fed up with jams
LIMITATIONS-Annoyances ..... System was originally developed for all weapons, handguns, secondary etc
later reduced to secondary & primary and then eventually to primary only
1) Because it removes all weapons, then all weapons need reloading before firing
..... maybe you could amend the system, so it removes
primaryweapon player..... that would remove a lot of annoyances too and greatly simplify the system
2) If NV Goggles were in use, the players has to refit them again
3) Each multi muzzlemode weapon needs an additional line added to the gunjammed.sqs
..... I added plenty of additional muzzlemode weapons to ease the use when creating for addon missions
..... Possible script improvement
_weapon = _weapon + "muzzle" (may remove the requirement for muzzle fixes, needs testing on non multi muzzle mode weapons)
4) System wasn't developed for AI units
..... Possible limitation, getting ai to reload their weapon after a jam
..... getting ai to find cover before carrying out a blockage drill
I stopped developing the system, because it works well enough for the mission it was intended for.
I may develop it further at some point, however, if you develop it further, please add the new system on ofpec for all to see.
A kindly note:
It would be nice of you if you mention in your mission's credits, that your jam system was developed using my basic system
Thanks & happy play