Jump to content

Recommended Posts

Hi,
Can someone help me?

 

I need the script so that when a player walks up to an ammo box it has 10 or each mag compatible with his weapons (Primary and secondary).

Share this post


Link to post
Share on other sites

something like this:
 

_magazines = getArray (configFile >> "CfgWeapons" >> currentWeapon player >> "magazines");

box addMagazineCargoGlobal [(_magazines select 0), 10];

But I would like to get all compatible mags.

 

I'm thinking an eventhandler

Share this post


Link to post
Share on other sites

SO!!! I'm getting closer,

 

this addEventHandler ["ContainerOpened", { 
 params ["_container", "_unit"];

_magazinesPri = getArray (configFile >> "CfgWeapons" >> primaryWeapon player >> "magazines"); 

_magazinesSec = getArray (configFile >> "CfgWeapons" >> handgunWeapon player >> "magazines"); 
 
box_M addMagazineCargoGlobal [(_magazinesPri select 0), 10];
box_M addMagazineCargoGlobal [(_magazinesSec select 0), 5];

 
}];


this addEventHandler ["ContainerClosed", { 
 params ["_container", "_unit"];

clearMagazineCargoGlobal box_M; 
}];

Now, how do I get more than one type of mags?

I'm thinking forEach

Share this post


Link to post
Share on other sites

This is close but not all done.

 

this addEventHandler ["ContainerOpened", { 
 params ["_container", "_unit"];

_magazinesPri = getArray (configFile >> "CfgWeapons" >> primaryWeapon player >> "magazines"); 

_magazinesSec = getArray (configFile >> "CfgWeapons" >> handgunWeapon player >> "magazines"); 

{ box_F addMagazineCargoGlobal [_x, 10]; } forEach _magazinesPri;
{ box_F addMagazineCargoGlobal [_x, 10]; } forEach _magazinesSec; 
}];


this addEventHandler ["ContainerClosed", { 
 params ["_container", "_unit"];

clearMagazineCargoGlobal box_F; 
}];

It's not finding all the magazines that the weapon can use.

How do i find that?
I guess it's my array that is not finding them all

Share this post


Link to post
Share on other sites

I think I got it 🙂 

this addEventHandler ["ContainerOpened", { 
 params ["_container", "_unit"];

_magazinesPri = primaryWeapon player call BIS_fnc_compatibleMagazines; 

_magazinesSec = handgunWeapon player call BIS_fnc_compatibleMagazines; 

{ box_A addMagazineCargoGlobal [_x, 10]; } forEach _magazinesPri;
{ box_A addMagazineCargoGlobal [_x, 10]; } forEach _magazinesSec; 
}];


this addEventHandler ["ContainerClosed", { 
 params ["_container", "_unit"];

clearMagazineCargoGlobal box_A; 
}];

So the last more tricky part.

 

How do I get this into a CFG file?

Class eventhandler?

  • Like 1

Share this post


Link to post
Share on other sites

Not tested, but if you code a crate in config, you could add the line:

 

postinit = "params ['_crate']; if (local _crate) then {_crate addEventHandler ['ContainerOpened', {params ['_crate','_unit']; _magazinesPri = primaryWeapon _unit call BIS_fnc_compatibleMagazines; _magazinesSec = handgunWeapon _unit call BIS_fnc_compatibleMagazines; {_crate addMagazineCargoGlobal [_x,10]} forEach _magazinesPri; {_crate addMagazineCargoGlobal [_x,10]} forEach _magazinesSec;}]; _crate addEventHandler ['ContainerClosed',{params ['_crate','_unit']; clearMagazineCargoGlobal _crate}]}";

 

Perhaps, work also with init = "...";  instead of postInit.

  • Like 1

Share this post


Link to post
Share on other sites

Seems to be working like a charm 😁!!

What would be the difference between postinit and init?

Also added the Launcher ammo:

 

		class EventHandlers
		{
		postinit = "params ['_crate']; if (local _crate) then {_crate addEventHandler ['ContainerOpened', {params ['_crate','_unit']; _magazinesPri = primaryWeapon _unit call BIS_fnc_compatibleMagazines; _magazinesHan = handgunWeapon _unit call BIS_fnc_compatibleMagazines;_magazinesSec = secondaryWeapon player call BIS_fnc_compatibleMagazines; {_crate addMagazineCargoGlobal [_x,10]} forEach _magazinesPri;{_crate addMagazineCargoGlobal [_x,10]} forEach _magazinesSec; {_crate addMagazineCargoGlobal [_x,10]} forEach _magazinesHan;}]; _crate addEventHandler ['ContainerClosed',{params ['_crate','_unit']; clearMagazineCargoGlobal _crate}]}";
		};

 

Share this post


Link to post
Share on other sites
15 hours ago, _-xXShArK_OGXx-_ said:

Seems to be working like a charm 😁!!

What would be the difference between postinit and init?

 

It's related to initialisation_order

 

init is the basic EH code applying to object at start. Not JIP on the contrary of preInit and postInit (see link above). Sometimes not recommended (for applying textures, as example).

 

postInit  calls the code upon mission start, after object is initialized. It's safe, and even recommended for some features like applying textures.

You can posInit some functions also, in cfgFunctions. Furthermore, the environment will be scheduled, if I'm right.

 

preInit   call the function upon mission start, before objects are initialized. So, doesn't apply to object. Unscheduled.

 

postInit and preInit are fine for self-running functions, i.e. you don't need to call them.

(See also preStart for some mods).

  • Like 1

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

×