Jump to content

Recommended Posts

Hello!

I'm trying to make a script that adds an intel item to the AI enemies loadout, randomly. It would be several different intel items in different AI's, both randomly. I did something like this, but it didn't work.

I am very grateful for any help. I'm a noob in scripting, unfortunately.

Thanks.
 

private ["_intelItems"];

_intelItems = ["Item_MobilePhone","Item_SmartPhone","Item_FlashDisk","Item_PropCamera_lxWS","Item_SecretDocuments","Item_FileTopSecret","Item_SecretFiles","Item_Files","Item_Laptop_Unfolded","Item_Laptop_closed","Item_ItemMap","Item_SmartPhone","Item_NetworkStructure","Item_Wallet_traitor"];


if (side _x == EAST) then  
	{
	
	_x select (random (count _x)) additem (_intelItems call BIS_fnc_selectRandom);
	
	}forEach allUnits;

 

Share this post


Link to post
Share on other sites

your script has syntax errors. this is how i would write it:

private _intelItems = ["Item_MobilePhone","Item_SmartPhone","Item_FlashDisk","Item_PropCamera_lxWS","Item_SecretDocuments","Item_FileTopSecret","Item_SecretFiles","Item_Files","Item_Laptop_Unfolded","Item_Laptop_closed","Item_ItemMap","Item_SmartPhone","Item_NetworkStructure","Item_Wallet_traitor"];
private _eastUnits = allUnits select {side _x == east};
for "_i" from 0 to (ceil random 5) do { // somehwere between 1 and 5 units will have intel
	private _randomUnit = _eastUnits deleteAt (floor random count _eastUnits); // Remove a random unit from the list of units
	_randomUnit addItem (selectRandom _intelItems); // Give a it a random item
};

 

  • Like 3

Share this post


Link to post
Share on other sites

Hi. Items which you want to add to inventory won´t have the same class name as they have in editor. In most cases it´s enough if you delete the prefix "Item_" but in some cases the item will have totally different name. I´ve fixed it for you 🙂. I´ve put together a function which should add the possibility for every unit to have some item generated. It´s a bit different aproach than @7erra has, but Arma is a game with a lot of ways to achieve things and every single one of us has its own style 😄. Take a look 🙂.
 

Spoiler

private _intelItems = ["MobilePhone","SmartPhone","FlashDisk","PropCamera_lxWS","DocumentsSecret","FileTopSecret","FilesSecret","Files","Laptop_Unfolded","Laptop_closed","ItemMap","SmartPhone","FileNetworkStructure","Wallet_ID"];
/*
This function will add random item to unit, if the unit has space in inventory for it.
How to use the function:
[
 unit,//<unit> to which item should be added
 [],//<array of strings> array of items that function should add (this array can´t be empty)
 0,//<scalar> number that will be randomized. (default:10)
 0//<scalar> number that should be always lower than number randomized. The lower the number is the higher is the chance that unit will have the item generated. If number is 0 every unit will have random item selected (default:0)
] spawn soldierXXXX_fnc_randomItem;
Example:[player,["FirstAidKit"],10,1] spawn soldierXXXX_fnc_randomItem;
*/
soldierXXXX_fnc_randomItem = {
                              scriptName "RandomItem";
                              params ["_unit","_itemsArray",["_RandomNumber",10],["_RandomNumberLow",0]];
                              private _addIntel = round random _RandomNumber;
                              if (_addIntel < _RandomNumberLow) exitWith {};
                              private _randomItem = selectRandom _itemsArray;
                              if (_unit canAdd _randomItem) then {
                                                                  _unit addItem _randomItem;
                                                                 };
                             };
{
 [_x,_intelItems,10,5] spawn soldierXXXX_fnc_randomItem;
} forEach units opfor;

 

 

Share this post


Link to post
Share on other sites
1 hour ago, soldierXXXX said:

Hi. Items which you want to add to inventory won´t have the same class name as they have in editor. In most cases it´s enough if you delete the prefix "Item_" but in some cases the item will have totally different name. I´ve fixed it for you 🙂. I´ve put together a function which should add the possibility for every unit to have some item generated. It´s a bit different aproach than @7erra has, but Arma is a game with a lot of ways to achieve things and every single one of us has its own style 😄. Take a look 🙂.
 

  Hide contents


private _intelItems = ["MobilePhone","SmartPhone","FlashDisk","PropCamera_lxWS","DocumentsSecret","FileTopSecret","FilesSecret","Files","Laptop_Unfolded","Laptop_closed","ItemMap","SmartPhone","FileNetworkStructure","Wallet_ID"];
/*
This function will add random item to unit, if the unit has space in inventory for it.
How to use the function:
[
 unit,//<unit> to which item should be added
 [],//<array of strings> array of items that function should add (this array can´t be empty)
 0,//<scalar> number that will be randomized. (default:10)
 0//<scalar> number that should be always lower than number randomized. The lower the number is the higher is the chance that unit will have the item generated. If number is 0 every unit will have random item selected (default:0)
] spawn soldierXXXX_fnc_randomItem;
Example:[player,["FirstAidKit"],10,1] spawn soldierXXXX_fnc_randomItem;
*/
soldierXXXX_fnc_randomItem = {
                              scriptName "RandomItem";
                              params ["_unit","_itemsArray",["_RandomNumber",10],["_RandomNumberLow",0]];
                              private _addIntel = round random _RandomNumber;
                              if (_addIntel < _RandomNumberLow) exitWith {};
                              private _randomItem = selectRandom _itemsArray;
                              if (_unit canAdd _randomItem) then {
                                                                  _unit addItem _randomItem;
                                                                 };
                             };
{
 [_x,_intelItems,10,5] spawn soldierXXXX_fnc_randomItem;
} forEach units opfor;

 

 

There is a possibility that none of the soldiers will get any intel items

Share this post


Link to post
Share on other sites
 [_x,_intelItems] spawn soldierXXXX_fnc_randomItem;

If you use the syntax this way then every unit which it is used for should get random item if they have spare space in their inventory 😉.

Share this post


Link to post
Share on other sites

Thanks a lot for the help, guys!
I could never do this alone, for sure.
Living and learning... that's my thruth in Arma. 

Thanks again!

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

×