Jump to content
MechSlayer

Add all objects from arrays into a crate

Recommended Posts

Hey, I'm trying to add all the wapons that I have into  4 arrays to a crate. I have this code: 

{
		if !(_x isEqualTo []) then
		{
		_Caja addWeaponCargoGlobal [_x,1];
		_Caja addBackpackCargoGlobal [_x,1];
		_Caja addItemCargoGlobal [_x,1];
		_Caja addMagazineCargoGlobal [_x,1];
		};
	} forEach _array1;

	{
		if !(_x isEqualTo []) then
		{
		_Caja addWeaponCargoGlobal [_x,1];
		_Caja addBackpackCargoGlobal [_x,1];
		_Caja addItemCargoGlobal [_x,1];
		_Caja addMagazineCargoGlobal [_x,1];
		};
	} forEach _array2;

	{
		if !(_x isEqualTo []) then
		{
		_Caja addWeaponCargoGlobal [_x,1];
		_Caja addBackpackCargoGlobal [_x,1];
		_Caja addItemCargoGlobal [_x,1];
		_Caja addMagazineCargoGlobal [_x,1];
		};
	} forEach _array3;

	{
		if !(_x isEqualTo []) then
		{
		_Caja addWeaponCargoGlobal [_x,1];
		_Caja addBackpackCargoGlobal [_x,1];
		_Caja addItemCargoGlobal [_x,1];
		_Caja addMagazineCargoGlobal [_x,1];
		};
	} forEach _array4;

And this is the array:

[["H_TurbanO_blk","G_Aviator","U_C_Poloshirt_stripped"],[],["OPTRE_BR55HB"],[]]

 

The problem is that it adds some blank objects and duplicate others. Is there another way?

Share this post


Link to post
Share on other sites
20 minutes ago, MechSlayer said:

Hey, I'm trying to add all the wapons that I have into  4 arrays to a crate. I have this code: 


{
		if !(_x isEqualTo []) then
		{
		_Caja addWeaponCargoGlobal [_x,1];
		_Caja addBackpackCargoGlobal [_x,1];
		_Caja addItemCargoGlobal [_x,1];
		_Caja addMagazineCargoGlobal [_x,1];
		};
	} forEach _array1;

	{
		if !(_x isEqualTo []) then
		{
		_Caja addWeaponCargoGlobal [_x,1];
		_Caja addBackpackCargoGlobal [_x,1];
		_Caja addItemCargoGlobal [_x,1];
		_Caja addMagazineCargoGlobal [_x,1];
		};
	} forEach _array2;

	{
		if !(_x isEqualTo []) then
		{
		_Caja addWeaponCargoGlobal [_x,1];
		_Caja addBackpackCargoGlobal [_x,1];
		_Caja addItemCargoGlobal [_x,1];
		_Caja addMagazineCargoGlobal [_x,1];
		};
	} forEach _array3;

	{
		if !(_x isEqualTo []) then
		{
		_Caja addWeaponCargoGlobal [_x,1];
		_Caja addBackpackCargoGlobal [_x,1];
		_Caja addItemCargoGlobal [_x,1];
		_Caja addMagazineCargoGlobal [_x,1];
		};
	} forEach _array4;

And this is the array:


[["H_TurbanO_blk","G_Aviator","U_C_Poloshirt_stripped"],[],["OPTRE_BR55HB"],[]]

 

The problem is that it adds some blank objects and duplicate others. Is there another way?

Don't add items and weapons this way, you use addItemCargo, addWeaponCargo, addMagazineCargo and addBackpackCargo for all items inside the arrays, this is bound to cause issues.

Make arrays only containing backpack classnames, use this array with addBackpackCargo, same for items, weapons, magazines, etc.

Won't work otherwise.

 

Cheers

  • Thanks 1

Share this post


Link to post
Share on other sites

Ok, i made it read all arrays separate but i got another problem. The forEach won't work

	_Caja = nearestObjects [player, ["B_supplyCrate_F"], 7];
	_Caja = _Caja select 0;
	[player,_Caja] remoteExecCall ["ExternalS_fnc_iniCajaCargar", 2];
	
	sleep 1;
	_Objetos = player getVariable "ObjetosCaja";
    	hint "test";
        //STOPS HERE
	{
		_Caja addItemCargoGlobal [_x,1];
	} forEach _Objetos;
    	hint "test2";
	["Sistema", "Objetos cargados", false] spawn HRP_fnc_Notifications;
	

	_Armas = player getVariable "ArmasCaja";
	{	
		_Caja addWeaponCargoGlobal [_x,1];
	} forEach _Armas;
	["Sistema", "Armas cargadas", false] spawn HRP_fnc_Notifications;
	

	_Mochilas = player getVariable "MochilasCaja";

	{
		_Caja addBackpackCargoGlobal [_x,1];
	} forEach _Mochilas;
	["Sistema", "Mochilas cargadas", false] spawn HRP_fnc_Notifications;
	

	_Cargadores = player getVariable "CargadoresCaja";

	{
		_Caja addMagazineCargoGlobal [_x,1];
	} forEach _Cargadores;
	["Sistema", "Cargadores cargados", false] spawn HRP_fnc_Notifications;

The script stops working on //STOP HERE (I get the first hint but not the second) the script that retrieve the data works fine too ([player,_Caja] remoteExecCall ["ExternalS_fnc_iniCajaCargar", 2];) here's the code for that

params ["_Jugador","_Caja"];

_UID = getPlayerUID _Jugador;

_BD = ["new", "CargoCasas"] call OO_INIDBI;
_Objetos = ["read", [_UID,"Objetos"]] call _BD;
_Armas = ["read", [_UID,"Armas"]] call _BD;
_Cargadores = ["read", [_UID,"Cargadores"]] call _BD;
_Mochilas = ["read", [_UID,"Mochilas"]] call _BD;
_Jugador setVariable ["ObjetosCaja", _Objetos, true];
_Jugador setVariable ["ArmasCaja", _Armas, true];
_Jugador setVariable ["CargadoresCaja", _Cargadores, true];
_Jugador setVariable ["MochilasCaja", _Mochilas, true];

Got any idea what could it be?

Share this post


Link to post
Share on other sites

did u look for an error in .rpt file? If yes then post it.

also show us the content of _Objetos

  • Thanks 1

Share this post


Link to post
Share on other sites

No .rpt errors, the function loads fine, here are the arrays:

[76561198133987227]
Nombre=""Mech""
Objetos="["OPTRE_Ins_ER_uniform_GAgreen","OPTRE_INS_UNSC_vest2","G_Aviator","sl_phone_1","ItemMap"]"
Mochilas="["sl_client_c_carryall_2"]"
Armas="["hlc_rifle_Bushmaster300","launch_O_Vorona_green_F","OPTRE_M6C"]"
Cargadores="["OPTRE_12Rnd_127x40_Mag","29rnd_300BLK_STANAG","29rnd_300BLK_STANAG","OPTRE_12Rnd_127x40_Mag","OPTRE_12Rnd_127x40_Mag"]"

_Objetos it's Objetos,  ExternalS_fnc_iniCajaCargar reads it then saves it in "ObjetosCaja" with setVariable

Share this post


Link to post
Share on other sites

what r these extra quotation marks?

 

"["OPTRE_Ins_ER_uniform_GAgreen","OPTRE_INS_UNSC_vest2","G_Aviator","sl_phone_1","ItemMap"]"

  • Thanks 1

Share this post


Link to post
Share on other sites

They're automatically added by iniDBI2 (Ignored when reading data)

Share this post


Link to post
Share on other sites

I wanted to see the contents of _Objetos array not any prior thing. add this before your test hint and show the .rpt output of it:

diag_log _Objetos;

 

  • Thanks 1

Share this post


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

The script stops working on //STOP HERE

You remote execute a function on the server to load data from the database, but your original function continues to run using player vars which have yet to be transferred from the server!. Why even transfer vars? If your just adding cargo to a container just do it globally at the server when you retrieve the data?

 

TAG_fnc_addContainerCargo = {
	if !( isServer ) exitWith { "TAG_fnc_addContainerCargo can only be called on the server" call BIS_fnc_error };
	if !( params[
		[ "_player", objNull, [ objNull ] ], 
		[ "_container", objNull, [ objNull ] ]
	] ) exitWith { "Invalid argument in call to TAG_fnc_addContainerCargo" call BIS_fnc_error };
	
	_uid = getPlayerUID _player;

	_BD = ["new", "CargoCasas"] call OO_INIDBI;
	_Objetos = ["read", [_uid,"Objetos"]] call _BD;
	_Armas = ["read", [_uid,"Armas"]] call _BD;
	_Cargadores = ["read", [_uid,"Cargadores"]] call _BD;
	_Mochilas = ["read", [_uid,"Mochilas"]] call _BD;
	
	//Do you really need to transfer all this data??
	_player setVariable ["ObjetosCaja", _Objetos /*, true*/];
	_player setVariable ["ArmasCaja", _Armas /*, true*/];
	_player setVariable ["CargadoresCaja", _Cargadores /*, true*/];
	_player setVariable ["MochilasCaja", _Mochilas /*, true*/];
	
	//Add all items to container globally
	{
		if ( !isNil "_x" && { _x isEqualType [] } ) then {
			{
				_x params[ "_item", "_count" ];
				
				if !( _item isEqualTo "" ) then {
					_item call BIS_fnc_itemType params[ "_type", "_subType" ];
					switch ( toUpper _type ) : {
						case "MINE" : {
							_container addMagazineCargoGlobal _x;
						};
						case "EQUIPMENT" : {
							if ( _subType == "backpack" ) then {
								_container addBackpackCargoGlobal _x;
							}else{
								_container addItemCargoGlobal _x;
							};
						};
						default {
							_container addItemCargoGlobal _x;
						};
					};
				};
			}forEach ( _x call BIS_fnc_consolidateArray );
		};

	}forEach [ _Objetos, _Armas, _Cargadores, _Mochilas ];
	
	["Sistema", "Cargadores cargados", false] remoteExec [ "HRP_fnc_Notifications", _player ];

};
_Caja = nearestObjects [player, ["B_supplyCrate_F"], 7];
if !( isNil { _Caja select 0 } ) then {
	[player,_Caja select 0] remoteExecCall ["TAG_fnc_addContainerCargo", 2];
};

not tested, may contain mistakes.

  • Thanks 1

Share this post


Link to post
Share on other sites

The function it's serverside, but it's called locally. Anyway I found the main mistake, I typed "copmlie" instead of "compile" on the functions compiler (Strange that only this was affected). Thanks all for the help.

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

×