Jump to content
mrgwilliam

Issues with a loadout script - error

Recommended Posts

Hey guys, I have been trying to solve this issue for the past couple of hours but have hit a brick wall. I keep getting the following error "Error Generic Error in Expression" when trying to call my functions:

 

My functions are the following:

 

My compile.sqf file which runs in the initialization file. via a call compile preprocessFile "framework\fnc\compile.sqf";

player_getPlayerLoadout = compile preprocessFile 'player\getPlayerLoadout.sqf';
player_restorePlayerLoadout = compile preprocessFile 'player\restorePlayerLoadout.sqf';

getPlayerLoadout.sqf -  player_getPlayerLoadout

/*
	File: getPlayerLoadout.sqf

	Description:
	Used to obtain all current weapons, items, and magazines and return them to an array

	Parameter(s):
  _this:	OBJECT	- Player Object that needs to be examined

	Returns:
	_this: Array -
          0 - Player Information [0 - Name, 1 - UUID]
          1 - Primary weapon
          2 - Secondary weapon
          3 - Handgun weapon
          4 - Primary Attachments [0 - silencer, 1 - laser, 2 - optics, 3 - bipod]
          5 - Secondary Attachments [0 - silencer, 1 - laser, 2 - optics, 3 - bipod]
          6 - Handgun Attachments [0 - silencer, 1 - laser, 2 - optics, 3 - bipod]
          7 - Headgear
          8 - Goggles
          9 - Uniform
          10 - Vest
          11 - Backpack
          12 - Magazines [[0 - classname, 1 - ammo count], ... ]
          13 - Items
          14 - Assigned Items
          15 - Misc
          16 - Primary Weapon Current Magazines [0 - magazine type, 1 - ammo count]
          17 - Secondary Weapon Current Magazine [0 - magazine type, 1 - ammo count]
          18 - Handgun Weapon Current Magzine [0 - magazine type, 1 - ammo count]
*/

// Establish Player Information
_player = _this select 0;
_playerName = name _player;
_playerUUID = getPlayerUID _player;

// Call all relevant information functions for loadout
//Weapons
_weapons = weapons _player;
_primaryWeapon = primaryWeapon _player;
_primaryAttachments = primaryWeaponItems _player;
_handgunWeapon = handgunWeapon _player;
_handgunAttachments =  handgunItems _player;
_secondaryWeapon = secondaryWeapon _player;
_secondaryAttachments = secondaryWeaponItems _player;

// Uniform
_headgear = headgear _player;
_goggles = goggles _player;
_uniform = uniform _player;
_vest = vest _player;
_backpack = backpack _player;


//Held Magazine
_magazines = magazinesAmmo _player;
_primaryMagazineType = primaryWeaponMagazine _player;
_primaryMagazineAmmo = _player ammo _primaryWeapon;
_secondaryMagazineType = secondaryWeaponMagazine _player;
_secondaryMagazineAmmo = _player ammo _secondaryWeapon;
_handgunMagazineType = handgunMagazine _player;
_handgunMagazineAmmo = _player ammo _handgunWeapon;

//Items
_assignedItems = assignedItems _player;
_items = items _player;

//House Keeping
_misc = _weapons - [_primaryWeapon,_secondaryWeapon,_handgunWeapon];
_primaryMag = _primaryMagazineType+[_primaryMagazineAmmo];
_secondaryMag = _secondaryMagazineType+[_secondaryMagazineAmmo];
_handgunMag = _handgunMagazineType+[_handgunMagazineAmmo];

// Return Loadout
_playerLoadout = [[_playerName,_playerUUID],
				_primaryWeapon,
				_secondaryWeapon,
				_handgunWeapon,
				_primaryAttachments,
				_secondaryAttachments,
				_handgunAttachments,
				_headgear,
				_goggles,
				_uniform,
				_vest,
				_backpack,
				_magazines,
				_items,
				_assignedItems,
				_misc,
				_primaryMag,
				_secondaryMag,
				_handgunMag
];

and the last one the restorePlayerLoadout.sqf - player_restorePlayerLoadout

/*
	File: restorePlayerLoadout.sqf

	Description:
	Used to restore players Loadout based on input array

	Parameter(s):
  _this:
      0 - Player
      1 - Array -
          0 - Player Information [0 - Name, 1 - UUID]
          1 - Primary weapon
          2 - Secondary weapon
          3 - Handgun weapon
          4 - Primary Attachments [0 - silencer, 1 - laser, 2 - optics, 3 - bipod]
          5 - Secondary Attachments [0 - silencer, 1 - laser, 2 - optics, 3 - bipod]
          6 - Handgun Attachments [0 - silencer, 1 - laser, 2 - optics, 3 - bipod]
          7 - Headgear
          8 - Goggles
          9 - Uniform
          10 - Vest
          11 - Backpack
          12 - Magazines [[0 - classname, 1 - ammo count], ... ]
          13 - Items
          14 - Assigned Items
          15 - Misc
          16 - Primary Weapon Current Magazines [0 - magazine type, 1 - ammo count]
          17 - Secondary Weapon Current Magazine [0 - magazine type, 1 - ammo count]
          18 - Handgun Weapon Current Magzine [0 - magazine type, 1 - ammo count]

	Returns: Nothing
*/

_player = _this select 0;
_playerLoadout = _this select 1;

// Remove everything from Player
removeAllWeapons _player;
removeAllItems _player;
removeAllContainers _player;
removeAllAssignedItems _player;
removeHeadgear _player;

// Based on Array -> rearm the player
// Uniform
_player addHeadgear (_playerLoadout select 7);
_player addGoggles (_playerLoadout select 8);
_player forceAddUniform (_playerLoadout select 9);
_player addVest (_playerLoadout select 10);
_player addBackpack (_playerLoadout select 11);

// Primary Weapon
if ((_playerLoadout select 16 select 1) != 0) then {
_player addMagazine [_playerLoadout select 16 select 0,_playerLoadout select 16 select 1];
_player addWeapon (_playerLoadout select 1);
{_player addPrimaryWeaponItem (_x);} forEach (_playerLoadout select 4);
};

// Secondary
if ((_playerLoadout select 17 select 1) != 0) then {
  _player addMagazine [_playerLoadout select 17 select 0,_playerLoadout select 17 select 1];
  _player addWeapon (_playerLoadout select 2);
  {_player addSecondaryWeaponItem _x;} forEach (_playerLoadout select 5);
};

// Handgun
if ((_playerLoadout select 18 select 1) != 0) then {
_player addMagazine [_playerLoadout select 18 select 0,_playerLoadout select 18 select 1];
_player addWeapon (_playerLoadout select 3);
{_player addHandgunItem _x;} forEach (_playerLoadout select 6);
};

//Add Magazines
{_player addMagazine [(_x select 0), (_x select 1)];} forEach (_playerLoadout select 12);
//Add Items
{_player addItem _x;} forEach (_playerLoadout select 13);
{_player addItem _x;} forEach (_playerLoadout select 14);
{_player assignItem _x;} forEach (_playerLoadout select 14);
{_player addWeapon _x;} forEach (_playerLoadout select 15);

I am trying to verify that I can call these functions but have been very unsuccessful. The files work as intended if I call them via execVM from my debug console however, to successfully test it I make the return variable a global variable and use that as the input to the restorePlayerLoadout file.

 

What I want to be able to do is use the call function in code to run these functions however whenever I try to use it I get the error "Error Generic Error in Expression". I have tried combinations of spawn and execVM, but the error remains. 

 

Is there anything I am missing or not doing right?

Share this post


Link to post
Share on other sites

Try doing it this way instead

getPlayerLoadout = call compile preprocessfilelinenumbers "player\GetPlayerLoadout.sqf";
restorePlayerLoadout = call compile preprocessfilelinenumbers "player\restorePlayerLoadout.sqf";

//From now on, you can call your function using

player spawn getPlayerLoadout;

Additionally, using preprocessFileLineNumbers will log the line number of any errors that do occur using those two functions.

Share this post


Link to post
Share on other sites

Ok, tried that and it works to a certain extent (spawn function does execute the function), however it forces me to store the return array globally in variable playerLoadout to access it. My goal is that the getPlayerLoadout function return the array of information, spawn does not appear to accomplish as it runs the procedure outside of the calling code.

Share this post


Link to post
Share on other sites

Ok, tried that and it works to a certain extent (spawn function does execute the function), however it forces me to store the return array globally in variable playerLoadout to access it. My goal is that the getPlayerLoadout function return the array of information, spawn does not appear to accomplish as it runs the procedure outside of the calling code.

 

What about adding a variable to the unit's namespace via setVariable? That's probably even more convenient.

Share this post


Link to post
Share on other sites

@R3vo, that would be a solution however the manner these functions will need to be implemented requires the function to return with the array as it will be pushed to off server storage for persistence needs. I will try messing around with that and see if it makes any difference.

 

 

edit: 

Alrighty I did some debugging and found the following. Once the first

_weapons = weapons _player;

is called inside the getLoadoutPlayer.sqf / function call, the error pops up.. "Error Generic Error in Expression". I am guessing this might be a locality issue or maybe an issue with how I am passing the player variable into the function, however I added a debug hint 

hint format["%1 %2",_playerName,_playerUUID];

and this reports out my information without issue. I am still stumped as to how to get this working

Edited by mrgwilliam

Share this post


Link to post
Share on other sites

Works fine here setup as described in OP. Just added _playerloadout to the end of getPlayerLoadout.sqf so it returns the array.

Only errors im getting are with restore where you are not checking if items are blank, like if you do not have a backpack the array will contain "" and adding a backpack of "" causes Backpack with given name not found error.

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

×