Home   Help Search Login Register  

Author Topic: Weapon jamming system  (Read 2447 times)

0 Members and 1 Guest are viewing this topic.

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Weapon jamming system
« on: 06 Feb 2005, 13:23:34 »
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=20417
Hope 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 1

this 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 jam

INIT.sqs
Quote
_weaponjam = random 100
?(_weaponjam >= 90): player addEventHandler ["Fired", {_this exec "gunjammed.sqs"}]



Stage 2

If 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 jam


gunjammed.sqs
Quote
?! (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
Quote
Blockagedrill = Player addaction ["Clear Blockage","misc\blockagedrill.sqs"]


Stage 3
This 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
Quote
?! (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 death
Player removeaction Blockagedrill
player removeAllEventHandlers "Killed"
player removeAllEventHandlers "Fired"

;; As soon as unit is alive again
player addEventHandler ["killed", {_this exec "playerkilled.sqs"}]
_weaponjam = random 100
?(_weaponjam >= 90): player addEventHandler ["Fired", {_this exec "gunjammed.sqs"}]


***************************************************************

FOR REFERENCE
The 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 name
This 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


Quote
?(_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 NOTE
1) 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


« Last Edit: 06 Feb 2005, 13:33:55 by Terox »
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:Weapon jamming system
« Reply #1 on: 20 Jun 2005, 15:25:59 »
Improved system
works on ai as well as Players

the below example was for an fdf mission, hence the sides east and resistance are used, but that was purely for a radio message sound file that isnt listed below
There is no requirement for side query's
Again there is much room for improvement as this was quickly done and i havent bothered to use it since

A custom anim for the blockage drill would be good


INIT.SQS
Quote
;; *************************************************************************************
;;                    ________ WEAPON JAM SYSTEM System __________
;; *************************************************************************************
;;tx_everyunit = an array of every unit on the map, this can be automated using a trigger)
;; the following runs a script that randomly gives units a chance of a weapon jam when they fire their primary
 {[_x] exec "rnd_jam.sqs"} foreach tx_everyunit


RND_JAM.SQS
Quote
;; run on each unit to select whether that unit has a weapon jam potential
;; if the unit has a chance of a weapon jam, its is given a fired event handler
;; on each event "fired" a random number is generated, if this is greater than the jam chance, then the weapon will jam
;; additional random numbers are run to see whether a reload will be the requirement to clear the jam or a fill blown blockage drill needs to be carried out


#INIT
  _unit = _this select 0
  _jamchance = random 100
  ?(_jamchance >= tx_Wepjam):_unit addEventHandler ["Fired", {_this exec "gunjammed.sqs"}]
exit


GUNJAMMED.SQS
Quote
;; run of a fired eventhandler that is randomly given to any unit in the tx_everyunit array

#INIT
_unit = _this select 0
_weapon = _this select 1
? (_weapon == Primaryweapon _unit):goto "NEXT"
exit

#NEXT
_jam_chance = random 100
?(_jam_chance >= tx_Wepjam):goto "Jammed"
;;exit

#JAMMED
_count = 0
_magArray = magazines _unit
?(_unit == Player)&&(!alive _unit): goto "END"
{_unit removeMagazine _x} forEach _magArray
?(_unit == Player):hint format ["***** %1 *****\n\nYour  %2 has jammed\n\n Try Reloading",name player,_weapon]
?(side _unit == resistance):_unit groupRadio "fdf_magjam"
?(side _unit == east):_unit groupRadio "rus_magjam"
?(_unit == Player): _unit playmove "CombatReloadmagazine"
;; "CombatReloadmgun"

#LOOP
_count = _count + 0.2
?(_unit == Player)&&(!alive _unit): goto "END"
~0.2
?(_count < 3.0): goto "Loop"


_random = random 100
?(_random >tx_majblockage): goto "MajorJam"

_secweapon = secondaryweapon _unit
?(_secweapon != ""):_unit removeweapon _secweapon
{_unit addMagazine _x} forEach _magarray
?(_secweapon != ""):_unit addweapon _secweapon

?(_unit == Player):hint format ["***** %1 *****\n\n!!! BLOCKAGE CLEARED !!!\n\n #### Reload ###",name player]
;;_unit playmove "CombatReloadmagazine"
exit


#MAJORJAM
?(_unit == Player)&&(!alive _unit): goto "END"
?(_unit == Player):tx_Jam_mags = _magArray
~3
?(_unit == Player)&&(!alive _unit) goto "END"
?(_unit == Player):hint format ["***** %1 *****\n\nJammed Solid\n\n!!!!! FIND COVER !!!!\n\nCarry Out Blockage drills",name player]
?(_unit == Player):tx_Blockagedrill = _unit addaction ["Clear Blockage","blockagedrill.sqs"]
?(_unit != Player): goto "BlockageDrill"
exit

#BlockageDrill
?(side _unit == resistance):_unit groupRadio "fdf_wepjam"
?(side _unit == east):_unit groupRadio "rus_wepjam"
_unit playmove "CrouchToWeapon"
_unit playmove "CombatReloadMortarEnd"
_unit playmove "CombatToCrouch"
~7
_secweapon = secondaryweapon _unit
?(_secweapon != ""):_unit removeweapon _secweapon
{_unit addMagazine _x} forEach _magarray
?(_secweapon != ""):_unit addweapon _secweapon
exit

#END
_unit removeaction tx_Blockagedrill
exit

BLOCKAGEDRILL.SQS
Quote
?! (local Player): exit
?(side Player == resistance):Player groupRadio "fdf_wepjam"
?(side Player == east):Player groupRadio "rus_wepjam"
? (!alive Player): goto "END"
player playmove "CrouchToWeapon"
? (!alive Player): goto "END"
player playmove "CombatReloadMortarEnd"
? (!alive Player): goto "END"
player playmove "CombatToCrouch"
? (!alive Player): goto "END"
~7
? (!alive Player): goto "END"

_secweapon = secondaryweapon player
player removeweapon _secweapon
{player addMagazine _x} forEach tx_Jam_mags
_player addweapon _secweapon



hint format ["***** %1 *****\n\nYou managed to clear the jam\n\n #### Reload ###",name player]
#END
Player removeaction tx_Blockagedrill
_Player groupRadio "Wepready"
exit
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline 456820

  • Contributing Member
  • **
Re:Weapon jamming system
« Reply #2 on: 22 Jun 2005, 19:29:27 »
okay i few things are
1) it appears you have custom sounds including FDF ones wich should be included
2) There seems to be a few unnesserily lines like
? (!alive player) : goto "end"
thats repwated so many tims and when he dies he cant do the next action so theres no need of these actions
3) how about making it possible for several units for the whole west and east ?
4) how about adding probability's for different weapons thats what ive done on mine
5) how about more chances if you are firing full auot rather than single ? whats the point of the secondary weapon bit as secondary weapons tend to not jam as easy from primary weapons as they have different velocitys and fire a lot slower and work in different ways

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:Weapon jamming system
« Reply #3 on: 23 Jun 2005, 15:53:51 »
Again there is much room for improvement as this was quickly done and i havent bothered to use it since


okay i few things are
1) it appears you have custom sounds including FDF ones wich should be included

I simply posted the script, use whatever sounds you want



2) There seems to be a few unnesserily lines like
? (!alive player) : goto "end"
thats repwated so many tims and when he dies he cant do the next action so theres no need of these actions

True a dead player will not play these anims, however as each anim takes a few seconds to run, if the player dies during the anim, whats the point of running the script any further and what if the respawn delay is only 1 second and you let the script run its path, surely you can see that the player on respawning could then run some unwanted anims or have an array of magazines added that they dont want

3) how about making it possible for several units for the whole west and east ?
Quote
;; *************************************************************************************
;;                    ________ WEAPON JAM SYSTEM System __________
;; *************************************************************************************
;;tx_everyunit = an array of every unit on the map, this can be automated using a trigger)
;; the following runs a script that randomly gives units a chance of a weapon jam when they fire their primary
 {[_x] exec "rnd_jam.sqs"} foreach tx_everyunit
I thought thats what i had already done



4) how about adding probability's for different weapons thats what ive done on mine

5) how about more chances if you are firing full auot rather than single ? whats the point of the secondary weapon bit as secondary weapons tend to not jam as easy from primary weapons as they have different velocitys and fire a lot slower and work in different ways


I had no requirement to do that, something like this can be made as complicated or as easy as one wants


« Last Edit: 23 Jun 2005, 16:10:41 by Terox »
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline guziczek101

  • Members
  • *
Re: Weapon jamming system
« Reply #4 on: 09 Jan 2012, 15:38:00 »
Hi i have problem with this script I might be a dumb but i can't use for sheet this script. If someone could do a template to this I will be grateful
Thanks in advance and sorry the mods for digging up the archaic topic