Jump to content
Sign in to follow this  
flymaker

Weapons replacement addon - help to convert script to addon

Recommended Posts

Hello,
 
I started a few days ago a script to change weapons from units. See here: https://forums.bistudio.com/topic/193112-unit-weapon-replacement-script-need-help
 
Now i want to make this an addon. Searching how execute the script to all units (spawned or pre placed on editor) i found the "init eventhandler". I dont know how work with eventhandles and config.cpp.
 
Anyone can help me in this project? I really dont know what im doing. =/
 

class CfgUnits //i dont know if that is the right way to call that
{
class myWeaponReplacement: unit
{
class EventHandlers
{
init = "_this execVM 'equip_change.sqf'";
};
};
};


 

// Replace CSAT Weapons Script

private ["_replacefor_Katiba", "_replacefor_KatibaGL", "_replacefor_KatibaC", "_replacefor_Zafir", "_replacefor_Rahim", "_replacefor_Lynx", "_replacefor_Sting", "_replacefor_Zubr", "_replacefor_Rook", "_replacefor_Ammo", "_replaceAmmoIndex", "_moreReplaceAmmo", "_replaceWeaponIndex", "_function", "_getItems", "_currentWeapon", "_magazinesArray", "_compatibleMags"
, "_countArrayIndex", "_index", "_magazineName", "_magazineAmount"];

// Put desire Weapon/Ammo Classname to replace
_replacefor_Katiba = "hlc_rifle_ak12";
_replacefor_KatibaGL = "hlc_rifle_ak12GL";
_replacefor_KatibaC = "hlc_rifle_aku12";
_replacefor_Zafir = "hlc_rifle_RPK12";
_replacefor_Rahim = "srifle_DMR_04_F";
_replacefor_Lynx = "hlc_rifle_awcovert_BL";
_replacefor_Sting = "hlc_rifle_aku12";

/*Only Primary Weapons for now
_replacefor_Zubr = [""];
_replacefor_Rook = [""];
*/

// Dont leave any empty
/* AmmoArray = [
"MagazineKatiba",
"MagazineKatibaTracer",
"MagazineZafir",
"MagazineZafirTracer",
"MagazineRahin",
"MagazineLynx",
"MagazineLynxSpecial",
"MagazineSting",
"GLAmmo 1",
"GLAmmo 2",
"GLSmoke 1",
"GLSmoke 2",
"GLSmoke 3",
"GLSmoke 4"
]*/

_replacefor_Ammo = [
"hlc_30Rnd_545x39_B_AK",
"hlc_30Rnd_545x39_t_ak",
"hlc_60Rnd_545x39_t_rpk",
"hlc_60Rnd_545x39_t_rpk",
"10Rnd_127x54_Mag",
"hlc_5rnd_300WM_mk248_AWM",
"hlc_5rnd_300WM_AP_AWM",
"hlc_30Rnd_545x39_B_AK",
"hlc_VOG25_AK",
"nul",
"hlc_GRD_White",
"hlc_GRD_Red",
"hlc_GRD_green",
"hlc_GRD_yellow"
];

/*		DO NOT EDIT BELLOW THIS LINE IF YOU DONT KNOW WHARE YOU DOING		*/

_replaceAmmoIndex = ["30Rnd_65x39_caseless_green","30Rnd_65x39_caseless_green_mag_Tracer","150Rnd_762x54_Box","150Rnd_762x54_Box_Tracer","10Rnd_762x51_Mag","5Rnd_127x108_Mag","5Rnd_127x108_APDS_Mag","30Rnd_9x21_Mag","1Rnd_HE_Grenade_shell","Blank","1Rnd_Smoke_Grenade_shell","1Rnd_SmokeRed_Grenade_shell","1Rnd_SmokeGreen_Grenade_shell","1Rnd_SmokeYellow_Grenade_shell"
];
_moreReplaceAmmo = ["10Rnd_93x64_DMR_05_Mag","10Rnd_762x51_Mag"];

_replaceWeaponIndex = ["arifle_Katiba_F","arifle_Katiba_GL_F","arifle_Katiba_C_F","LMG_Zafir_F","srifle_DMR_01_F","srifle_GM6_F","SMG_02_F"];

_function = execVM "Zen_ArrayGetNestedIndex.sqf";

waitUntil { scriptDone _function };

// Get Unit Current Weapon and remove
_getItems = primaryWeaponItems _this;
_currentWeapon = [primaryWeapon _this] call BIS_fnc_baseWeapon;
_this removeWeapon _currentWeapon;

_magazinesArray = magazines _this;
_magazinesArray = _magazinesArray call BIS_fnc_consolidateArray;

_compatibleMags = [];
{
	_mags = [];
	if ( _x != "this" ) then {
		_mags = getArray( configFile >> "CfgWeapons" >> _currentWeapon >> _x >> "magazines" ); 
	}else{
		_mags = getArray( configFile >> "CfgWeapons" >> _currentWeapon >> "magazines" ); 
	};
	_compatibleMags = _compatibleMags + _mags;
}forEach getArray( configFile >> "CfgWeapons" >> _currentWeapon >> "muzzles" );
{
	if ( _x in _compatibleMags ) then {
		_this removeMagazine _x;
	}
} forEach magazines _this;

{_this removeMagazines _x;} forEach _replaceAmmoIndex;
//{_this removeMagazines _x;} forEach _moreReplaceAmmo;

//Replace Katiba

If ( _currentWeapon == "arifle_Katiba_F" ) then {
	
	// CODE SEARCH MAGAZINE //
	_countArrayIndex = 0;
	{
	
	_index = [_magazinesArray, _x, 0] call Zen_ArrayGetNestedIndex;
	
	// FOUNDED - ADD AMMO  //
	if (_index >= 0) then {
	_magazineName = (_magazinesArray select _index) select 0;
	_magazineAmount = (_magazinesArray select _index) select 1;
	_this addMagazines [_replacefor_Ammo select _countArrayIndex ,_magazineAmount];	
	};

	_countArrayIndex = _countArrayIndex + 1;
	
	} forEach _replaceAmmoIndex;	
	
	_this addMagazines [_replacefor_Ammo select 0, 1];
	
	_this addweapon _replacefor_Katiba;
	{_this addPrimaryWeaponItem _x} forEach _getItems;
	_this selectWeapon ( primaryWeapon _this );
};
If ( _currentWeapon == "arifle_Katiba_GL_F" ) then {
	
	// CODE SEARCH MAGAZINE //
	_countArrayIndex = 0;
	{
	
	_index = [_magazinesArray, _x, 0] call Zen_ArrayGetNestedIndex;
	
	// FOUNDED - ADD AMMO  //
	if (_index >= 0) then {
	_magazineName = (_magazinesArray select _index) select 0;
	_magazineAmount = (_magazinesArray select _index) select 1;
	_this addMagazines [_replacefor_Ammo select _countArrayIndex ,_magazineAmount];	
	};

	_countArrayIndex = _countArrayIndex + 1;
	
	} forEach _replaceAmmoIndex;	
	
	_this addMagazines [_replacefor_Ammo select 0, 1];
	
	_this addweapon _replacefor_KatibaGL;
	{_this addPrimaryWeaponItem _x} forEach _getItems;
	_this selectWeapon ( primaryWeapon _this );
};
If ( _currentWeapon == "arifle_Katiba_C_F" ) then {
	
	// CODE SEARCH MAGAZINE //
	_countArrayIndex = 0;
	{
	
	_index = [_magazinesArray, _x, 0] call Zen_ArrayGetNestedIndex;
	
	// FOUNDED - ADD AMMO  //
	if (_index >= 0) then {
	_magazineName = (_magazinesArray select _index) select 0;
	_magazineAmount = (_magazinesArray select _index) select 1;
	_this addMagazines [_replacefor_Ammo select _countArrayIndex ,_magazineAmount];	
	};

	_countArrayIndex = _countArrayIndex + 1;
	
	} forEach _replaceAmmoIndex;	
	
	_this addMagazines [_replacefor_Ammo select 0, 1];
	
	_this addweapon _replacefor_KatibaC;
	{_this addPrimaryWeaponItem _x} forEach _getItems;
	_this selectWeapon ( primaryWeapon _this );
};
If ( _currentWeapon == "LMG_Zafir_F" ) then {
	
	// CODE SEARCH MAGAZINE //
	_countArrayIndex = 0;
	{
	_index = [_magazinesArray, _x, 0] call Zen_ArrayGetNestedIndex;
	
	// FOUNDED - ADD AMMO  //
	if (_index >= 0) then {
	_magazineName = (_magazinesArray select _index) select 0;
	_magazineAmount = (_magazinesArray select _index) select 1;
	_this addMagazines [_replacefor_Ammo select _countArrayIndex ,_magazineAmount];	
	};
	
	_countArrayIndex = _countArrayIndex + 1;
	
	} forEach _replaceAmmoIndex;	
	
	_this addMagazines [_replacefor_Ammo select 0, 1];
	
	_this addweapon _replacefor_Zafir;
	{_this addPrimaryWeaponItem _x} forEach _getItems;
	_this selectWeapon ( primaryWeapon _this );
	};
If ( _currentWeapon == "srifle_DMR_01_F" ) then {
	
	// CODE SEARCH MAGAZINE //
	_countArrayIndex = 0;
	{
	_index = [_magazinesArray, _x, 0] call Zen_ArrayGetNestedIndex;
	
	// FOUNDED - ADD AMMO  //
	if (_index >= 0) then {
	_magazineName = (_magazinesArray select _index) select 0;
	_magazineAmount = (_magazinesArray select _index) select 1;
	_this addMagazines [_replacefor_Ammo select _countArrayIndex ,_magazineAmount];	
	};
	
	_countArrayIndex = _countArrayIndex + 1;
	
	} forEach _replaceAmmoIndex;	
	
	_this addMagazines [_replacefor_Ammo select 0, 1];
	
	_this addweapon _replacefor_Rahim;
	{_this addPrimaryWeaponItem _x} forEach _getItems;
	_this selectWeapon ( primaryWeapon _this );
};
If ( _currentWeapon == "srifle_GM6_camo_F" ) then {
	
	// CODE SEARCH MAGAZINE //
	_countArrayIndex = 0;
	{
	_index = [_magazinesArray, _x, 0] call Zen_ArrayGetNestedIndex;
	
	// FOUNDED - ADD AMMO  //
	if (_index >= 0) then {
	_magazineName = (_magazinesArray select _index) select 0;
	_magazineAmount = (_magazinesArray select _index) select 1;
	_this addMagazines [_replacefor_Ammo select _countArrayIndex ,_magazineAmount];	
	};
	
	_countArrayIndex = _countArrayIndex + 1;
	
	} forEach _replaceAmmoIndex;	
	
	_this addMagazines [_replacefor_Ammo select 0, 1];
	
	_this addweapon _replacefor_Lynx;
	{_this addPrimaryWeaponItem _x} forEach _getItems;
	_this selectWeapon ( primaryWeapon _this );
};
If ( _currentWeapon == "SMG_02_F" ) then {
	
	// CODE SEARCH MAGAZINE //
	_countArrayIndex = 0;
	{
	_index = [_magazinesArray, _x, 0] call Zen_ArrayGetNestedIndex;
	
	// FOUNDED - ADD AMMO  //
	if (_index >= 0) then {
	_magazineName = (_magazinesArray select _index) select 0;
	_magazineAmount = (_magazinesArray select _index) select 1;
	_this addMagazines [_replacefor_Ammo select _countArrayIndex ,_magazineAmount];	
	};
	
	_countArrayIndex = _countArrayIndex + 1;
	
	} forEach _replaceAmmoIndex;	
	
	_this addMagazines [_replacefor_Ammo select 0, 1];
	
	_this addweapon _replacefor_Sting;
	{_this addPrimaryWeaponItem _x} forEach _getItems;
	_this selectWeapon ( primaryWeapon _this );
};

 

Share this post


Link to post
Share on other sites

I'm stuck =/ 

I made a config.cpp but this not executing correctly the script.

class CfgPatches
{
	class FLY_ChangeWeapons
	{
		units[] = {};
		weapons[] = {};
		requiredVersion = 1.0;
		requiredAddons[] = {"Extended_EventHandlers"};

	};
};

class Extended_PostInit_EventHandlers
{

		FLY_ChangeWeapons_Post_Init = "_handle = {[_x] execVM ""\FLY_ChangeWeapons\equip_change.sqf""} forEach allUnits";

};

Share this post


Link to post
Share on other sites

Why do you not just over-ride the units to use the weapons?

Because the addon will replace all weapons from all missions. BIS Default missions too

This is not possible over-ridding units 

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  

×