Sign in to follow this  
Followers 0
eraser1

Trader Weapon Attachment Dupe Workaround

9 posts in this topic

Posted (edited)

Do you want to spawn weapons with attachments, but are annoyed by the trader attachment "dupe"?

Well, you can paste this script in your init to work around it!

What this script does is that it checks to see if the player's weapons (both primary and handgun) spawn with attachments by default. If it does detect that they have those attachments by default, then it will

1) Find a replacement by checking the parent classes of the weapon (which usually contain the "stock" weapon version, at least for vanilla ArmA 3 weapons. I haven't tried any modded weapons yet)

2) If a suitable replacement is found, it will then save the configuration of the weapon (which attachments it has, what magazine and how many bullets are in the mag).

3) Remove the original weapon, and add the replacement.

4) Re-add the attachments that were on the original weapon, including magazines, with the correct amount of bullet. The script will replace GL ammo as well, again with the correct # of rounds (if using a 3GL).

5) In the event that the replacement weapon got loaded with extra magazines from the player's inventory, then those magazines will also be re-added to the inventory (again, with correct # of rounds, even with a GL).

 

The player shouldn't notice that anything has happened, and at most the script might disrupt an animation, and it might move a magazine or two around (I could ensure that the magazines are kept identical, but I think it's pretty minor and hardly worth the effort).

Other than that, I can't guarantee that it will work on any modded weapons, that's for you to test out.

 

INSTRUCTIONS:

Paste the script directly in the mission file after line 8, where it says "if (!hasInterface || isServer) exitWith {};" will automatically add it to the Exile thread system on a 30 second delay. The delay can be adjusted at the top.

Edit the "ExileServer_system_process_preInit.sqf" in the "exile_server\code\" folder: Comment out line 21:

//call ExileServer_system_process_noobFilter;

 

 

This script will work just as fine in any other mod, or even in vanilla (if you take out the Exile thread system part :P ) in case you have any use for that.

 

Leave any questions/concerns/issues below!

Edited by eraser1
3 people like this

Share this post


Link to post
Share on other sites

@eraser1 is this the init or initplayerlocal or initserver file? I presume its the playerlocal one?

cheers

Share this post


Link to post
Share on other sites
Advertisement

@red_ned You want this to run on clients, so initplayerlocal.sqf. AFTER the "if (!hasInterface || isServer) exitWith {};"

1 person likes this

Share this post


Link to post
Share on other sites
2 hours ago, eraser1 said:

@red_ned You want this to run on clients, so initplayerlocal.sqf. AFTER the "if (!hasInterface || isServer) exitWith {};"

cheers, just checking

Share this post


Link to post
Share on other sites

Updated instructions for latest version of Exile :D

1 person likes this

Share this post


Link to post
Share on other sites
43 minutes ago, eraser1 said:

Updated instructions for latest version of Exile :D

love you :rock:

1 person likes this

Share this post


Link to post
Share on other sites
On 6/26/2016 at 11:21 PM, red_ned said:

cheers, just checking

RN, how did you add it to initPlayerLocal, with an #include or an execVM?

Share this post


Link to post
Share on other sites
4 hours ago, kuplion said:

RN, how did you add it to initPlayerLocal, with an #include or an execVM?

here's the start of my file for you, just remove status bar and refuel

Spoiler

///////////////////////////////////////////////////////////////////////////////
// Static Objects
///////////////////////////////////////////////////////////////////////////////

// Taken away for now
//#include "initServer.sqf"

// init for the statusbar
[] execVM "addons\statusBar\statusbar.sqf";

if (!hasInterface || isServer) exitWith {};

// Refuel Rearm
[] execVM "addons\service_point\service_point.sqf";

// Dupe fix
[30,   // Delay, in seconds
{
private _fnc_isValid =
{
 private _linkedItems = configFile >> "CfgWeapons" >> _this >> "LinkedItems";

 private _isValid = true;
 {
  if !((getText (_linkedItems >> _x >> "item")) isEqualTo "") exitWith {_isValid = false};
 } forEach ["LinkedItemsOptic","LinkedItemsAcc","LinkedItemsMuzzle","LinkedItemsUnder"];

 _isValid
};
private _fnc_getLoadedMags =
{
 private _loadedMags = [];
 {
  if ((_x select 3) isEqualTo _this) then
  {
   _loadedMags pushBack [_x select 0,_x select 1];
  };
 } forEach (magazinesAmmoFull player);
 _loadedMags
};

private _primary = primaryWeapon player;
if (!(_primary isEqualTo "") && {!(_primary call _fnc_isValid)}) then
{
 private _replacement = "";

 {
  if ((configName _x) call _fnc_isValid) exitWith {_replacement = configName _x;};
 } forEach ((configFile >> "CfgWeapons" >> _primary) call BIS_fnc_returnParents);


 if (isText (configFile >> "CfgWeapons" >> _replacement >> "displayName")) then  // This bit ensures that the replacement weapon is an actual weapon, and not just a base class.
 {
  private _currentWeaponItems = primaryWeaponItems player;
  private _loadedMags_Original = 1 call _fnc_getLoadedMags;

  private _currentWeapon = currentWeapon player;

  player removeWeapon _primary;
  player addWeapon _replacement;

  private _loadedMags_Replacement = 1 call _fnc_getLoadedMags;

  if (_currentWeapon isEqualTo _primary) then
  {
   player selectWeapon _replacement;
  };

  {
   if !(_x isEqualTo "") then
   {
    player addPrimaryWeaponItem _x;
   };
  } forEach _currentWeaponItems;

  {
   player addWeaponItem [_replacement, _x];
  } forEach _loadedMags_Original;

  {player addMagazine _x} forEach _loadedMags_Replacement;
 };
};

private _handgun = handgunWeapon player;
if (!(_handgun isEqualTo "") && {!(_handgun call _fnc_isValid)}) then
{
 private _replacement = "";

 {
  if ((configName _x) call _fnc_isValid) exitWith {_replacement = configName _x;};
 } forEach ((configFile >> "CfgWeapons" >> _handgun) call BIS_fnc_returnParents);


 if (isText (configFile >> "CfgWeapons" >> _replacement >> "displayName")) then
 {
  private _currentWeaponItems = handgunItems player;
  private _loadedMags_Original = 2 call _fnc_getLoadedMags;

  private _currentWeapon = currentWeapon player;

  player removeWeapon _handgun;
  player addWeapon _replacement;

  private _loadedMags_Replacement = 2 call _fnc_getLoadedMags;

  if (_currentWeapon isEqualTo _handgun) then
  {
   player selectWeapon _replacement;
  };

  {
   if !(_x isEqualTo "") then
   {
    player addHandgunItem _x;
   };
  } forEach _currentWeaponItems;

  {
   player addWeaponItem [_replacement, _x];
  } forEach _loadedMags_Original;

  {player addMagazine _x} forEach _loadedMags_Replacement;
 };
};
},[],true] call ExileClient_system_thread_addTask;


///////////////////////////////////////////////////////////////////////////
// Hardware Trader
///////////////////////////////////////////////////////////////////////////

 

1 person likes this

Share this post


Link to post
Share on other sites
2 hours ago, red_ned said:

here's the start of my file for you, just remove status bar and refuel

  Hide contents

///////////////////////////////////////////////////////////////////////////////
// Static Objects
///////////////////////////////////////////////////////////////////////////////

// Taken away for now
//#include "initServer.sqf"

// init for the statusbar
[] execVM "addons\statusBar\statusbar.sqf";

if (!hasInterface || isServer) exitWith {};

// Refuel Rearm
[] execVM "addons\service_point\service_point.sqf";

// Dupe fix
[30,   // Delay, in seconds
{
private _fnc_isValid =
{
 private _linkedItems = configFile >> "CfgWeapons" >> _this >> "LinkedItems";

 private _isValid = true;
 {
  if !((getText (_linkedItems >> _x >> "item")) isEqualTo "") exitWith {_isValid = false};
 } forEach ["LinkedItemsOptic","LinkedItemsAcc","LinkedItemsMuzzle","LinkedItemsUnder"];

 _isValid
};
private _fnc_getLoadedMags =
{
 private _loadedMags = [];
 {
  if ((_x select 3) isEqualTo _this) then
  {
   _loadedMags pushBack [_x select 0,_x select 1];
  };
 } forEach (magazinesAmmoFull player);
 _loadedMags
};

private _primary = primaryWeapon player;
if (!(_primary isEqualTo "") && {!(_primary call _fnc_isValid)}) then
{
 private _replacement = "";

 {
  if ((configName _x) call _fnc_isValid) exitWith {_replacement = configName _x;};
 } forEach ((configFile >> "CfgWeapons" >> _primary) call BIS_fnc_returnParents);


 if (isText (configFile >> "CfgWeapons" >> _replacement >> "displayName")) then  // This bit ensures that the replacement weapon is an actual weapon, and not just a base class.
 {
  private _currentWeaponItems = primaryWeaponItems player;
  private _loadedMags_Original = 1 call _fnc_getLoadedMags;

  private _currentWeapon = currentWeapon player;

  player removeWeapon _primary;
  player addWeapon _replacement;

  private _loadedMags_Replacement = 1 call _fnc_getLoadedMags;

  if (_currentWeapon isEqualTo _primary) then
  {
   player selectWeapon _replacement;
  };

  {
   if !(_x isEqualTo "") then
   {
    player addPrimaryWeaponItem _x;
   };
  } forEach _currentWeaponItems;

  {
   player addWeaponItem [_replacement, _x];
  } forEach _loadedMags_Original;

  {player addMagazine _x} forEach _loadedMags_Replacement;
 };
};

private _handgun = handgunWeapon player;
if (!(_handgun isEqualTo "") && {!(_handgun call _fnc_isValid)}) then
{
 private _replacement = "";

 {
  if ((configName _x) call _fnc_isValid) exitWith {_replacement = configName _x;};
 } forEach ((configFile >> "CfgWeapons" >> _handgun) call BIS_fnc_returnParents);


 if (isText (configFile >> "CfgWeapons" >> _replacement >> "displayName")) then
 {
  private _currentWeaponItems = handgunItems player;
  private _loadedMags_Original = 2 call _fnc_getLoadedMags;

  private _currentWeapon = currentWeapon player;

  player removeWeapon _handgun;
  player addWeapon _replacement;

  private _loadedMags_Replacement = 2 call _fnc_getLoadedMags;

  if (_currentWeapon isEqualTo _handgun) then
  {
   player selectWeapon _replacement;
  };

  {
   if !(_x isEqualTo "") then
   {
    player addHandgunItem _x;
   };
  } forEach _currentWeaponItems;

  {
   player addWeaponItem [_replacement, _x];
  } forEach _loadedMags_Original;

  {player addMagazine _x} forEach _loadedMags_Replacement;
 };
};
},[],true] call ExileClient_system_thread_addTask;


///////////////////////////////////////////////////////////////////////////
// Hardware Trader
///////////////////////////////////////////////////////////////////////////

 

Ahhhh, you just added it in. I added it as a separate file and called it and it seems to be working. Thank you for getting back to me.

Share this post


Link to post
Share on other sites
Advertisement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.