Jump to content
Sign in to follow this  
Militant1006

weapon replacement script

Recommended Posts

Hey guys I'm trying to work on something that I thought was pretty simple but seems more complex than I thought, I am trying to get a script working in the init.sqf that detects if a soldier has a SCAR_H_CQC_CCO, and then replaces it but it seems quite a bit challenging right now, so far I have tried

if _unit hasWeapon "SCAR_H_CQC_CCO" then _unit removeWeapon "SCAR_H_CQC_CCO";

As you can see that would only remove the weapon but I can't even get that working, any thoughts?

EDIT: I guess I should mention that this was to replace the Delta force SCAR-H's with ACE HK416's and M4A1's eventually, but to do that I would also need to replace the magazines with the right amount.

And I was hoping I could do this in script form but I might have to de-Pbo and modify the config for them, and I was thinking I should take it out of the init.sqf and make a dedicated file for it eg. "scarHreplacement.sqf" but at the moment I have no idea.

Edited by Militantsausage

Share this post


Link to post
Share on other sites

Just remove all weapons and give them back exactly what you want them to have.

Share this post


Link to post
Share on other sites

I know what your thinking there but I was trying to be a bit more ambitious, I was trying to make basically a weapon replacement script that detects what the person is holding and then corrects it.

Share this post


Link to post
Share on other sites

A simple check of primaryWeapon unit then compare to a switch statement with all the guns you want to replace with should work. Really though it seems like a lot of extra effort since you shouldn't not know what weapons your units are starting with. :)

Share this post


Link to post
Share on other sites
.....I was trying to make basically a weapon replacement script that detects what the person is holding and then corrects it.

Here brother from across the pond.....try this :-

Put this in the Init line of the soldier you want have his weapons replaced....for this example he must have the "M16A4".

nul = [this] execVM "replace_weaps.sqf";

Here is the little script :-

"replace_weaps.sqf";

private ["_unit"];

_unit = _this select 0;

if (_unit hasWeapon [color="Red"]"M16A4"[/color]) then {

// Remove the stock items from the man
RemoveAllWeapons _unit;

// Add the primary weapon magazines to the man
_unit addmagazine "200Rnd_556x45_M249";
_unit addmagazine "200Rnd_556x45_M249";
_unit addmagazine "200Rnd_556x45_M249";
_unit addmagazine "200Rnd_556x45_M249";

//Add the mags for the primary weapon
_unit addweapon [color="Red"]"M249"[/color];

//Add the secondary weapon magazines to the man
_unit addmagazine "7Rnd_45ACP_1911";
_unit addmagazine "7Rnd_45ACP_1911";
_unit addmagazine "7Rnd_45ACP_1911";
_unit addmagazine "7Rnd_45ACP_1911";
_unit addmagazine "7Rnd_45ACP_1911";
_unit addmagazine "7Rnd_45ACP_1911";

//Add the mags for the secondary weapon
_unit addweapon "Colt1911";

//Add all this other good stuff
_unit addmagazine "HandGrenade";
_unit addmagazine "HandGrenade";

_unit addweapon "Binocular";

_unit addweapon "NVGoggles";

//Make the dude select the primary weapon
_unit selectweapon "M249";

};

Demo here.

The "M16A4" is replaced with the "M249". Everything is removed from the man and a whole new kit is assigned!

Good luck!

EDIT : Made a slight change to the script...took out the extra "_unit = _this select 0"! All good now!

Edited by twirly
Clarity

Share this post


Link to post
Share on other sites

Thank you very much for your effort, and well success, just thinking is there a way to replace certain units guns without having to put something in the init? eg. Have a script that detects any delta force operators and replaces their Mk. 17's with a HK416 or an

M4A1? Or does this already work?

I was thinking put "execVM "Delta_load.sqf";" (Thats what I called it ;) ) into the init.sqf, and then it should automatically detect whether a unit has a SCAR-H or not, then it will replace.

One thing i'm not sure about is if the _unit array covers all units in the game or just units that have the execVM in their init box.

---------- Post added at 12:37 PM ---------- Previous post was at 11:42 AM ----------

Ok this is going to be a big post.

I tried the script, I got the way you suggested working which does in the long run decrease the work load of loadouts, but I tried to initialize it in the init.sqf with both "execVM "Delta_load.sqf" and "nul = [this] execVM "Delta_load.sqf" but I couldn't get it to work, do you know how to get the script to detect if the gun is being used or not?.

First of all you forgot to close it with a "}", (I figured that out through squint) and after using squint it was coming up with no errors at all.

This is what I have so far

// The automatic Mk.17 replacement script

private ["_unit"];

_unit = _this select 0;

if (_unit hasWeapon "SCAR_H_CQC_CCO") then {

// Remove the stock items from the man

RemoveAllWeapons _unit;

// Add the primary weapon magazines to the man

_unit addmagazine "ACE_30rnd_556x45_SB_STANAG";

_unit addmagazine "ACE_30rnd_556x45_SB_STANAG";

_unit addmagazine "ACE_30rnd_556x45_SB_STANAG";

_unit addmagazine "ACE_30rnd_556x45_SB_STANAG";

_unit addmagazine "ACE_30rnd_556x45_SB_STANAG";

_unit addmagazine "ACE_30rnd_556x45_SB_STANAG";

_unit addmagazine "ACE_30rnd_556x45_SB_STANAG";

_unit addmagazine "ACE_30rnd_556x45_SB_STANAG";

//Add the mags for the primary weapon

_unit addweapon "ACE_HK416_D14_COMPM3";

//Add the secondary weapon magazines to the man

//Add the mags for the secondary weapon

//Add all this other good stuff

_unit addmagazine "HandGrenade";

_unit addmagazine "HandGrenade";

_unit addmagazine "smokeShell";

_unit addmagazine "ACE_Battery_Rangefinder";

_unit addweapon "Binocular_Vector";

_unit addweapon "NVGoggles";

//Make the dude select the primary weapon

_unit selectweapon "ACE_HK416_D14_COMPM3";};

EDIT: kylania I will try your idea aswell should it look like this

(_unit primaryWeapon "SCAR_H_CQC_CCO") : _unit addWeapon "M110_NVG_EP1";

The problem with that though is you can only use weapons with the same mags.

I'm also starting to think this could be easier by making a Pbo version replacement, but then I will have to find where the config for Delta force is in the game files (I have no idea). By the way I hope I have explained properly that the reason i'm trying to do this is basically so I can copy/paste it into any of my mission and prevent using another addon, the point of the script is so you do not have to define which soldiers do get their weapons replaced but the script does. It is ment to function in a similar way to a replacement addon.

Edited by Militantsausage

Share this post


Link to post
Share on other sites
.........Have a script that detects any delta force operators and replaces their Mk. 17's with a HK416 or an

M4A1?

That is exactly what I use! ....and here it is. It's really two scripts :-

First script....

private ["_unit"];

_unit= _this select 0;

if (typeOf _unit == "USMC_SoldierS_SniperH") then {nul=[_unit] execVM "chweaps\sd_mk12sd.sqf"};
if (typeOf _unit == "USMC_Soldier_Pilot") then {nul=[_unit] execVM "chweaps\wsnip107.sqf"};
if (typeOf _unit == "USMC_Soldier_M16A2") then {nul=[_unit] execVM chweaps\sd_L115A3.sqf"};

For this example the second script is in a folder called "chweaps\" in your mission folder....and is a different script for each different loadout. So can be many scripts for the weapons...hence the seperate folder to keep things tidy.

Example second script.....

private ["_unit"];

// Get the unit
_unit = _this Select 0;

// Remove the stock items from the unit
RemoveAllWeapons _unit;


// Add the mags to the unit

_unit addmagazine "10Rnd_127x99_m107";
_unit addmagazine "10Rnd_127x99_m107";
_unit addmagazine "10Rnd_127x99_m107";

.....blah blah blah

I'm sure you'll figure it out. The first script still has to be executed on the unit somehow though!. It can be executed on each unit of a whole squad with a loop.

Don't forget the fix for multiple muzzles.

Thanks Carl. Hmmmm...I'm going to have to look into this....Doing that now!

EDITED/ADDED:-

In this little demo I'm swapping my current weapon for one with a grenade launcher.....seems to work fine without any fix!

There is a three second sleep so you can see the change over.

@Carl......Am I just totally missing something here?

Edited by twirly
Clarity & added a link.

Share this post


Link to post
Share on other sites

Not sure. Maybe it was fixed? Or maybe the circumstances doesn't match? I tend to add it for everything of this nature, probably a habit :p

It goes like this:

_primw = primaryWeapon _p;
if (_primw != "") then {
_p selectWeapon _primw;
_muzzles = getArray(configFile>>"cfgWeapons" >> _primw >> "muzzles");
_p selectWeapon (_muzzles select 0);
};

Iirc the point of it was that sometimes you would not have a mode selected. So the fire button wouldn't work unless you pressed f at least once.

Share this post


Link to post
Share on other sites
Not sure. Maybe it was fixed? Or maybe the circumstances doesn't match? I tend to add it for everything of this nature, probably a habit :p

It goes like this:

_primw = primaryWeapon _p;
if (_primw != "") then {
_p selectWeapon _primw;
_muzzles = getArray(configFile>>"cfgWeapons" >> _primw >> "muzzles");
_p selectWeapon (_muzzles select 0);
};

Iirc the point of it was that sometimes you would not have a mode selected. So the fire button wouldn't work unless you pressed f at least once.

Ahh..OK...I see. I think I remember something to do with that at some point in the past....but it does seem to work now.

I tend to add it for everything of this nature, probably a habit

LOL! Same here....workaround habits develop and stick!

Thanks for replying...and thanks for the code snippet.

Share this post


Link to post
Share on other sites

Uhh I haven't touched it for a while, to be honest I was quite hopeless at that, more of a mission maker (hence why I wanted a script rather than config)

I could try and make extra loadouts with units though, if I get the spare time, but at the moment my main PC is broken, the one I am on atm doesn't have any stuff from arma.

At the moment, for clan stuff, I am looking at:

- 1-2 missions per week

- doing weapon loadouts for each member (around 20-30 of them) as a part of a script we are using (made by bon ;) )

- Compiling some helpful stuff for first time mission makers in the clan (None of it is really "mine" so I don't know if I would release it publicly)

- Actual game commitments, Leading a fireteam and helping train while shooting at the enemy

- Real life stuff, such as a job, lol.

I would love to get it done though, don't count on it but I could get some good experience out of it

Share this post


Link to post
Share on other sites

I was trying to get these to work, however, not even one of the example missions worked.

I need to replace weapons for about 200 Units on this map, and doing it all via init line is kind of tedious. I am pretty bad at scripting, can anybody help me out here?

I have tried all the script versions and the example missions posted in this thread, to no avail. :<

Any kind of help is really appreciated, thanks in advance!

Cheerio

Insta

Edit: I have to add that I run the mission with ACE2 to make use of all the good features it has, maybe there´s a conflict there? If yes, is there a workaround to make something like this work with ACE?

Edit of the Edit: I have got Twirly´s version working now, except (as stated by him) it only changes the weapon of any unit that has the thing in its init line. Is there any way to execute this globally for all Units of a faction of a given type, with the script there?

Edited by InstaGoat

Share this post


Link to post
Share on other sites
..... I have got Twirly´s version working now, except (as stated by him) it only changes the weapon of any unit that has the thing in its init line. Is there any way to execute this globally for all Units of a faction of a given type, with the script there?

You can try something like this loop here. As it is here it should be easy enough to follow...

_allunits = allunits;

for "_i" from 0 to (count _allunits)-1 do {
_unit = _allunits select _i;
if (side _unit = [b]EAST[/b]) then {
	nul = [_unit] execVM "replace_weaps.sqf";
};
sleep 0.01;
};

....or to to change weapons for different soldier types (classes).... maybe something like this and have a different script for each class....

_allunits = allunits;

for "_i" from 0 to (count _allunits)-1 do {
_unit = _allunits select _i;
if (side _unit = [b]WEST[/b]) then {
           if (typeOf _unit == "USMC_SoldierS_SniperH") then {nul=[_unit] execVM "chweaps\sd_mk12sd.sqf"};
           if (typeOf _unit == "USMC_Soldier_Pilot") then {nul=[_unit] execVM "chweaps\wsnip107.sqf"};
           if (typeOf _unit == "USMC_Soldier_M16A2") then {nul=[_unit] execVM chweaps\sd_L115A3.sqf"};
};
sleep 0.01;
};

EDIT: You can also use switch to do away with all the separate if checks for typeOf _unit.

Edited by twirly
Added stuff

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  

×