Jump to content
paramedic

Put Items into the nearest vehicle

Recommended Posts

Okay all I want is for a crate to have an action that allows me to put items into it on a mp server. So far I got some stuff activated via addaction from the crate but it doesn't work and I couldn't find anything about it. I'm not that good of a scripter obviously..

 

 

Quote

_packesel = nearestObjects [crate_1, ["Truck","Car","Tank"], 15];


_packesel addWeaponCargoGlobal ["rhs_weap_M136_hedp", 4];
_packesel addMagazineCargoGlobal ["rhs_mag_smaw_HEAA", 2];
_packesel addMagazineCargoGlobal ["rhs_mag_smaw_HEDP", 4];
_packesel addWeaponCargoGlobal ["rhs_weap_fim92", 1];
_packesel addWeaponCargoGlobal ["lerca_1200_tan", 1];
_packesel addMagazineCargoGlobal ["rhs_fim92_mag", 4];
_packesel addItemCargoGlobal ["ACE_M26_Clacker", 1];
_packesel addMagazineCargoGlobal ["DemoCharge_Remote_Mag", 4];
_packesel addMagazineCargoGlobal ["ClaymoreDirectionalMine_Remote_Mag", 2];
_packesel addMagazineCargoGlobal ["rhs_mag_m67", 8];
_packesel addMagazineCargoGlobal ["rhs_mag_an_m8hc", 8];

_packesel addItemCargoGlobal ["FirstAidKit", 8];

_packesel addMagazineCargoGlobal ["rhs_mag_30Rnd_556x45_Mk318_Stanag", 20];
_packesel addMagazineCargoGlobal ["rhsusf_100Rnd_556x45_soft_pouch", 4];

_packesel addItemCargoGlobal ["ToolKit", 1];

_packesel addBackpackCargoGlobal ["B_Kitbag_cbr", 2];
_packesel addBackpackCargoGlobal ["B_Carryall_cbr", 1];

_packesel addWeaponCargoGlobal ["rhs_weap_M320", 1];
_packesel addMagazineCargoGlobal ["ACE_HuntIR_M203", 4];
_packesel addMagazineCargoGlobal ["rhs_mag_M441_HE", 8];
_packesel addMagazineCargoGlobal ["rhs_mag_m714_White", 8];
_packesel addMagazineCargoGlobal ["rhs_mag_M585_white", 8];
_packesel addMagazineCargoGlobal ["rhs_mag_m18_green", 1];
_packesel addMagazineCargoGlobal ["rhs_mag_m18_red", 1];
_packesel addMagazineCargoGlobal ["rhs_mag_m662_red", 1];
_packesel addMagazineCargoGlobal ["rhs_mag_m713_Red", 1];
_packesel addMagazineCargoGlobal ["rhs_mag_m715_Green", 1];
_packesel addMagazineCargoGlobal ["rhs_mag_m661_green", 1];
_packesel addMagazineCargoGlobal ["rhs_mag_M433_HEDP", 2];
_packesel addMagazineCargoGlobal ["rhs_mag_M397_HET", 2];


_packesel addItemCargoGlobal ["ACE_EarPlugs", 8];
_packesel addItemCargoGlobal ["ACE_EntrenchingTool", 2];
_packesel addItemCargoGlobal ["rhsusf_opscore_aor1_pelt", 2];
_packesel addItemCargoGlobal ["ACE_IR_Strobe_Item", 8];
_packesel addItemCargoGlobal ["ACE_wirecutter", 1];
_packesel addItemCargoGlobal ["ACE_DefusalKit", 1];
_packesel addItemCargoGlobal ["ACE_SpraypaintGreen", 4];

_packesel addWeaponCargoGlobal ["rhs_weap_XM2010_sa", 1];
_packesel addMagazineCargoGlobal ["rhsusf_5Rnd_300winmag_xm2010", 8];
_packesel addBackpackCargoGlobal ["ace_gunbag_Tan", 1];
_packesel addItemCargoGlobal ["rhsusf_acc_M2010S_sa", 1];
_packesel addItemCargoGlobal ["rhsusf_acc_anpeq16a", 8];
_packesel addItemCargoGlobal ["rhsusf_acc_M8541", 1];
_packesel addItemCargoGlobal ["rhsusf_acc_harris_bipod", 1];

 

 

I'm sure I'm just missing something really big here and my question is actually incredible stupid but I would be thankful for any help.

Share this post


Link to post
Share on other sites

What is not working exactly? Make sure -showoScriptErrors is enabled, as I would bet that your issue would pop up there. And how are you executing the addAction?

 

My understanding is that you have an ammo crate with an addAction scripted onto it, and the above code block is what is executed. The code is intended to add that list of items to the nearest vehicle within 15m. 

 

Regarding the error, read through the biki entry for nearestObjects. Pay close attention to the return value, and understand that you are executing commands that require an object as an argument, and you are giving them an array. Because nearestObjects returns an array, you need to select the first (closest) element in that array and set your local variable equal to that. 

 

If that makes sense, take a look at the difference between nearestObjects and nearEntities and then read up further on nearEntities. Although not a particularly big deal here, it is a good habit to get into when the circumstances fit. 

  • Like 2

Share this post


Link to post
Share on other sites

The issue is that nearestObjects returns array, not a single object. Try:

_packesel = (nearestObjects [crate_1, ["Truck","Car","Tank"], 15]) select 0;

 

  • Like 1

Share this post


Link to post
Share on other sites

And it works, thank you. I knew I forgot something way to obvious.

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

×