Jump to content

Sign in to follow this  
ColonelSandersLite

CSL Weapon Switching

Recommended Posts

*** Updated V1.3 ***

This script allows you to easilly have a unit carry 2 primary weapons. For

example, it will allow you to equip a sniper with both an M24 and an MP5SD5.

It was originally made for the mission titled CO 1-2 Operation Shining Anvil to

enable the player sniper to carry an MP5 as well as the sniper rifle. I

thought that it would prove to be very useful for some people. As always,

feedback, bug reports, etc are welcome.

Features:

This script will work regardless of addons used.

Using this script will not give the players free rounds if they switch

weapons before a magazine is empty. They will retain the magazine with

the spent rounds.

Animation and sound played when the player switches weapons.

This script does not give the players extra ammo space, requiring them to

carefully balance their ammunition selections.

The player can pick up and drop weapons in either weapon slot at will.

Supports Join in progress, teamswitching, and all respawning modes.

Compatibility:

Tested Armed Assault v1.08 compatible. Older Versions not tested. It

should work on any later version.

Multiplayer:

100% MP compatible.

Issues:

There are 3 known issues that can not or will not be corrected due to arma

limitations.

1: The secondary weapon slot cannot be accessed inside the gear dialog on

mission start. This is completely unchangable. I attempted to make an

optional modified gear dialog for v1.1, but could not get arma to populate

it. If you figure out a way to fix this somehow, be sure and let me know.

2: If you use the scripts on a very unusually sized unit, the algorithm to

detect what posture the unit is in may fail. For example, a 50 foot giant

would always return standing, and a 2 foot midget would always return

prone. I consider this to be a minor issue.

3: It is possible to equip a large weapon (such a pk or m240) and an AT

weapon at the same time using the following process.

A: Switch to weapon slot you wish to arm with both heavy weapons.

B: Pick up a machinegun or any weapon weapon considered to be large.

C: Switch to the other weapon slot.

D: Pick up the AT or AA weapon.

E: Upon switching to the weapon slot with the large weapon, both

the heavy weapons will be available.

While this is a potential cheat, it is at least counterbalanced by the

fact that these weapons have large bulky ammo. Since this script does not

give the player extra ammo space, it will actually place a heavy handicap

on the player that attempts to do this. The only way to fix this problem

would be to require that all weapons be defined, which would make this

script much less flexible.

Download:

CSL Weapon Switching V1.3 Courtesy Of Armaholic.com

Hosting:

You can host this anywhere you want, but if you let me know via PM on the

BIS forums, I'll add a link in the download thread and let you know if I

patch it. I'd also prefer if you included a link back to the home page,

as this is where I'll be posting updates, answering questions etc.

Usage:

It is strongly reccomended you view the demo missions before attempting to

use this.

Full instructions are found in the readme.

Version History:

V1.3:

Fixed a save game related bug that slipped in probably in v1.1 but

remained undetected for reasons unknown. Thanks to undeceived for

reporting it.

Fixed a small bug that nobody had yet reported. Would have caused

problems when using the script on multiple units with teamswitching on.

V1.2:

Fixed a small mp bug involving running the script on a unit that doesn't

exist due to the unit being disabled either by the player or the mission

designer.

Parameters simplified slightly.

V1.1:

Units now play the correct reloading animation per their stance thanks to

Mandoble's function to detect it.

A couple of scripts are now built in to handle respawning, so you don't

have to do it yourself. One preserves the unit's current equipment on

death, and respawns him with it. The other, resets his equipment to

starting every time he respawns.

V1.0:

Release

License:

Unlimited rights (including editing and rereleasing) so long as it's non-

commercial and adheres to the BIS terms of use. Any derivative work

cannot be more restrictive than this with respect to what rights an end

user has.

Note that use of Mandoble's function must conform to his requirements, not

mine.

Credits:

Special Ed for prompting me to write this script in the first place and

helping with the MP testing.

Mandoble - Wrote the function to get the unit's posture.

Tack Of The 10th Mountain Division - Testing

Super - Six Of The 10th Mountain Division - Testing

Matt Rochelle - Bug Report, error when run on a disabled unit.

Undeceived - Bug Reprt, save game related.

Share this post


Link to post
Share on other sites

Just FYI, someone on the ofpec forums pointed out that there is now a method to get the soldiers posture by taking advantage of the intersect command. I'll do some testing on it, and should it prove reliable, I will be updating this script to solve known issue 2.

I will also experiment with an optional mod that will modify the gear menu to allow the player to manage both weapons in the gear selection screen. I doubt that it can actually be done. To be more precise, I could probably modify the gear UI itself to do it with little difficulty. The thing is that it'll be populated by arma game code that I couldn't touch or even see. It's worth a try I guess, but I wouldn't put my hopes into it.

Anyways, most likely, issue 2 will be solved and issues 1 and 3 will stand.

Share this post


Link to post
Share on other sites

V1.1 will be released as soon as it's tested in a true mp environment.

Changes:

Units now play the correct reloading animation per their stance thanks to Mandoble's script to detect it.

A couple of scripts built in to handle respawning, so the user doesn't have to do it himself. One preserves the unit's current equipment on death, and respawns him with it. The other, resets his equipment to starting every time he respawns. Retrospectively, that should have been in there to begin with.

Share this post


Link to post
Share on other sites

Very impressive work.

  [b said:
Quote[/b] ]Using this script will not give the players free rounds if they switch

weapons before a magazine is empty. They will retain the magazine with

the spent rounds.

I am particularly happy to see this implemented,I have an addon version if you ever wish to progress this , it dosent require any p3ds simply a config as it refferences the p3ds already inside arma.

send me a pm if in the future you want to go that way .

Share this post


Link to post
Share on other sites

I could put it together in addon format very easily. I really don't want to though, for the sake of mp. Addonless (if it's possible, it's not always, and that's OK)means one less thing to worry about for the end user playing a final product online. I appreciate the offer (really, I do) I just feel that it will overall hurt the usefulness of the scripts to do that.

Share this post


Link to post
Share on other sites

Yeah this is great stuff, me and a load of guys have been testing it on MP.. Its like the best thing ever! Period. Its just getting that script to work after the players have died, im 80% in getting it right lol. biggrin_o.gif

Share this post


Link to post
Share on other sites

Yeah, I know, getting it working with respawn is a pain, that's why I coded for it in v1.1.

Something went wrong with my copy of arma, so I spent a lot of time reinstalling it today, instead of testing it. If I'm not mistaken, after the fact, it seems that my profile got partially corrupted somehow. I'll see about getting it tested tomorrow sometime maybe. We'll just have to see what happens on that. People work and such, you know.

Share this post


Link to post
Share on other sites

Well if you need any help you know where to find me tounge2.gif

Im sure i once reinstalled arma and got my user currupt too, before they patches the game early on 1.02 or something. tounge2.gif

So im stuck with a user i cannot use/delete lol.

Share this post


Link to post
Share on other sites

Just for my own undertsanding, why doesnt this work? After the player is back alive and 12 seconds or so he gets his action back, but every 12/14 seconds he gets the action again and again even though he is now alive, so why isnt the check working?

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

; ****************************************************************

; Script file for Armed Assault

; Created by: TODO: Author Name

; ****************************************************************

#Check

~12

?!(alive Multi1) : goto "Multi1a"

?!(alive Multi2) : goto "Multi2a"

?!(alive Multi3) : goto "Multi3a"

~3

goto "check"

#Multi1a

_scriptHandle = [[Multi1, "SVD", "CSL_ReloadSound", "Multi1_CSLWeaponSwitchingSwap"]] execVM "CSL_WeaponSwitching\CSL_WeaponSwitching_V1.0_Main.sqf";

~0.3

goto "check"

#Multi2a

_scriptHandle = [[Multi2, "SVD", "CSL_ReloadSound", "Multi2_CSLWeaponSwitchingSwap"]] execVM "CSL_WeaponSwitching\CSL_WeaponSwitching_V1.0_Main.sqf";

~0.3

goto "check"

#Multi3a

_scriptHandle = [[Multi3, "SVD", "CSL_ReloadSound", "Multi3_CSLWeaponSwitchingSwap"]] execVM "CSL_WeaponSwitching\CSL_WeaponSwitching_V1.0_Main.sqf";

~0.3

goto "check"

Share this post


Link to post
Share on other sites
  (sickboy @ Sep. 10 2007,06:55) said:
Prone/Stand/Crouch check;

Cant you use http://community.bistudio.com/wiki/animationState for this? (Havent tested it though)

Yeah, that'll work, if you want to check against several hundred possible animation states wink_o.gif.

The solution implemented in v1.1 (mandiboles script to do it) checks if the unit exists between 2 points at 3 heights. It works very well, so long as the unit isn't sized abnormally. It wouldn't work on a 50 foot giant or a 2 foot midget, for example wink_o.gif.

Share this post


Link to post
Share on other sites
  (Matt Rochelle @ Sep. 10 2007,06:42) said:
Just for my own undertsanding, why doesnt this work? After the player is back alive and 12 seconds or so he gets his action back, but every 12/14 seconds he gets the action again and again even though he is now alive, so why isnt the check working?

I'm not sure what exactly you're trying to achieve there. However, since you say that he's getting the action again every 12 seconds, !(alive Multi1), or one of the others, is failing every time it goes through.

For your benifit, to peruse it, here is CSL_WeaponSwitching_V1.1_RespawnResetEquipment.sqf.

Note that it is, as yet, not properly *tested* to handle JIP and respawning correctly. As I said earlier, I had arma problems today, so didn't get around to it when it could have been tested. So yeah, I need to get a true mp test running, before I put that seal of approval on it wink_o.gif.

*note that this is an old version now and is only left here for the sake of completeness*

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

sleep 0.01;

// the unit *must* be named. I do not care *what* you name it, so long as it *does* have a name.

_unit = format["%1", _this select 0 select 0];

_secondaryWeapon = _this select 0 select 1;

_reloadSound = _this select 0 select 2;

_swapVariable = _this select 0 select 3;

_previouslyInitialised = false;

if (call compile format["!isNil ""CSL_WeaponSwitching_%1_Magazines""", _swapVariable, _unit]) then

{

//player sideChat "not null";

_previouslyInitialised = true;

};

if (not _previouslyInitialised) then

{

//player sideChat "was null";

_code = format["CSL_WeaponSwitching_%1_Magazines = magazines %1; publicVariable ""CSL_WeaponSwitching_%1_Magazines"";" , _unit];

call compile _code;

_code = format["CSL_WeaponSwitching_%1_Weapons = weapons %1; publicVariable ""CSL_WeaponSwitching_%1_Weapons"";" , _unit];

call compile _code;

};

_firstRun = true;

// assign the unit to a local variable so I don't have to recompile him as often.

// ( it saves processor cycles;) )

_tmpUnit = (call compile _unit);

while {true} do

{

if (!(_firstRun)) then

{

// clear his weapons and give him his old inventory back

removeAllWeapons _tmpUnit;

_tmpUnit addWeapon "FFARLauncher";

{

_tmpUnit addMagazine _x;

} forEach call compile format["CSL_WeaponSwitching_%1_Magazines", _unit];

{

(call compile _unit) addWeapon _x;

} forEach call compile format["CSL_WeaponSwitching_%1_Weapons", _unit];

_tmpUnit removeWeapon "FFARLauncher";

} else

{

_firstRun = false;

};

// if he's alive, execute the scripts, then wait until he's dead

if (alive _tmpUnit) then

{

_scriptHandle = [[_tmpUnit, _secondaryWeapon, _reloadSound, _swapVariable]] execVM "CSL_WeaponSwitching\CSL_WeaponSwitching_V1.1_Main.sqf";

//waitUntil {player sideChat "waiting to die"; !alive _tmpUnit};

waitUntil {!alive _tmpUnit};

};

call compile format["%1 = %2;", _swapVariable, _secondaryWeapon];

// wait until he's respawned

//waitUntil {player sideChat "waiting to live"; _tmpUnit = (call compile _unit); alive _tmpUnit};

waitUntil {_tmpUnit = (call compile _unit); alive _tmpUnit};

};

Basically, you call this inplace of main, and this script handles calling main as appropriate depending on the respawn state of the unit.

I already see a bug though, looking at it like this. That's great...

Share this post


Link to post
Share on other sites

It works in the MP editor, now time for test on a server. I will report back soon.

In your script i just had to change

CSL_WeaponSwitching_V1.1_Main.sqf";

to

CSL_WeaponSwitching_V1.0_Main.sqf";

Share this post


Link to post
Share on other sites

Well it works on the server but this error message repeats over and over.. and the RPT seems full of them, but it works :s  tounge2.gif

this one appears for a few moments i think

  [b said:
Quote[/b] ]Error in expression <CSL_WeaponSwitching_scalar bool array string 0xe0ffffef_Weapons>

Error position: <bool array string 0xe0ffffef_Weapons>

Error Missing ;

and this one appears contantly.

  [b said:
Quote[/b] ]Error in expression <scalar bool array string 0xe0ffffef>

 Error position: <bool array string 0xe0ffffef>

 Error Missing ;

Get that in the blackbox at the top of the screen and it doesnt go.

Share this post


Link to post
Share on other sites

That would mean that _unit isn't being initialised right. It's beta still, and I haven't even passed you full instructions. It may be my fault, and it may not. I'll be getting it fully running soon though. So, keep your socks on and keep a weather eye out.

Share this post


Link to post
Share on other sites

Chill dude crazy_o.giftounge2.gif Its what testing is all about, ill keep my pants on and wait a few days biggrin_o.gif

Share this post


Link to post
Share on other sites

If I came off harsh, you have my apologies. That was not my intent. Perhaps I should have added a smiley at the end?

Anyways, still not tested, but the script above has been edited with an updated version to fix a couple of things I noticed before I even got to it. I doubt it will help with your specific problem though.

Something to check, is *how* you're naming the unit.

If you're setting his name in the name field in the editor, you are doing that correctly. If you are doing something like this in his initfield, it won't work: UnitName = this

Share this post


Link to post
Share on other sites

Yeah im naming him in the editor name field.

Btw, with the other 1.1 scripts would they be any differnt than the 1.0 versions which im using in what may of coursed that bug, im just about to test the one you just updated though.

Edit:

Still getting this at start of game..

  [b said:
Quote[/b] ]

Error in expression <CSL_WeaponSwitching_scalar bool array string 0xe0ffffef_Magazines >

Error position: <bool array string 0xe0ffffef_Magazines >

Error Missing ;

Error in expression <CSL_WeaponSwitching_scalar bool array string 0xe0ffffef_Weapons >

Error position: <bool array string 0xe0ffffef_Weapons >

Error Missing ;

Error in expression <scalar bool array string 0xe0ffffef>

Error position: <bool array string 0xe0ffffef>

Error Missing ;

Error in expression <scalar bool array string 0xe0ffffef>

Error position: <bool array string 0xe0ffffef>

Error Missing ;

Error in expression <CSL_WeaponSwitching_scalar bool array string 0xe0ffffef_Magazines >

Error position: <bool array string 0xe0ffffef_Magazines >

Error Missing ;

Error in expression <CSL_WeaponSwitching_scalar bool array string 0xe0ffffef_Weapons >

Error position: <bool array string 0xe0ffffef_Weapons >

Error Missing ;

Error in expression <scalar bool array string 0xe0ffffef>

Error position: <bool array string 0xe0ffffef>

Error Missing ;

Error in expression <scalar bool array string 0xe0ffffef>

Error position: <bool array string 0xe0ffffef>

Error Missing ;

Error in expression <scalar bool array string 0xe0ffffef>

Error position: <bool array string 0xe0ffffef>

Error Missing ;

+ Infinit Of that Last message -----

Share this post


Link to post
Share on other sites

Matt Rochelle, clean out your inbox. It's full, so I can't send this PM.

V1.1 is tested and done. All that needs be done is confirmation on this issue.

Share this post


Link to post
Share on other sites
  (ColonelSandersLite @ Sep. 10 2007,03:06) said:
Yeah, I know, getting it working with respawn is a pain, that's why I coded for it in v1.1.

Something went wrong with my copy of arma, so I spent a lot of time reinstalling it today, instead of testing it.  If I'm not mistaken, after the fact, it seems that my profile got partially corrupted somehow.  I'll see about getting it tested tomorrow sometime maybe.  We'll just have to see what happens on that.  People work and such, you know.

I been having a corrupt profile problem with OFP. Keeps happening every now and again. Just make a copy of your profile so when one gets forked you just paste the copy into your userthing.

Share this post


Link to post
Share on other sites

Thx for the heads up, W0lle posted the last message in my inbox crazy_o.gifwow_o.gif Anyways its all cleared out.

smile_o.gif

Share this post


Link to post
Share on other sites

Newly discovered problem, albeit a minor one.

If you're running v1.0 or v1.1 of this script via init.sqf in mp, you should check that the unit exists before running the script on it. (this is what was causing Matt Rochelle's problem above)

An easy way to do this is to check if they're alive.

For example:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

if (alive Multi1) then {_scriptHandle = [[Multi1, "SVD", "CSL_ReloadSound", "Multi1_CSLWeaponSwitchingSwap"]] execVM "CSL_WeaponSwitching\CSL_WeaponSwitching_V1.1_RespawnResetEquipment.sqf";};

if (alive Multi2) then {_scriptHandle = [[Multi2, "SVD", "CSL_ReloadSound", "Multi2_CSLWeaponSwitchingSwap"]] execVM "CSL_WeaponSwitching\CSL_WeaponSwitching_V1.1_RespawnResetEquipment.sqf";};

if (alive Multi3) then {_scriptHandle = [[Multi3, "SVD", "CSL_ReloadSound", "Multi3_CSLWeaponSwitchingSwap"]] execVM "CSL_WeaponSwitching\CSL_WeaponSwitching_V1.1_RespawnResetEquipment.sqf";};

V1.2 will have this solved.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×