Home   Help Search Login Register  

Author Topic: Weapons check  (Read 3049 times)

0 Members and 1 Guest are viewing this topic.

Offline Zipper5

  • BIS Team
  • ****
Weapons check
« on: 22 Aug 2009, 19:57:14 »
Heh, soon as one problem is solved, another pops up. That's mission making in a nutshell...

Anyways, here's my next issue: I've found many people miss the Gear selections provided by the mission maker when testing or just simply playing the mission. For this mission, Gear selection is quite important. What I am trying to do is check the default loadout (the loadout I've given him) of the player against what he has when the mission starts. If there's no difference, a hint will be displayed notifying him about it and it will add all of the Gear selection to the vehicle he starts off in.

Now, here's how I've attempted to approach the issue, which does not work:

Code: [Select]
_mags = magazines player;
_weaps = weapons player;

_startMags = [
"30Rnd_556x45_Stanag",
"30Rnd_556x45_Stanag",
"30Rnd_556x45_Stanag",
"30Rnd_556x45_Stanag",
"30Rnd_556x45_Stanag",
"30Rnd_556x45_Stanag",
"HandGrenade_West",
"HandGrenade_West",
"SmokeShell",
"SmokeShell",
"1Rnd_HE_M203",
"1Rnd_HE_M203",
"FlareRed_M203",
"FlareGreen_M203",
"15Rnd_9x19_M9",
"15Rnd_9x19_M9",
"15Rnd_9x19_M9",
"15Rnd_9x19_M9"
];

_startWeaps = [
"M4A1_HWS_GL_camo",
"M9",
"Binocular",
"NVGoggles"
];

if {_mags = _startMags} then
{
if {_weaps = _startWeaps} then
{
hint "Since your weapon loadout has remained the same, presumably you missed the available gear selection. For this reason, it has been added to this helicopter.\nIt is accessable by selecting Gear in your Action Menu.";
Gear selection follows...
};
};

So, judging from that, by what means should I be approaching this issue to get it to work?
Thanks guys, and sorry for the trouble. :D

Edit: Noticed a typo, fixed it, but it still doesn't work anyways.
« Last Edit: 22 Aug 2009, 20:20:32 by Zipper5 »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Weapons check
« Reply #1 on: 22 Aug 2009, 20:33:56 »
Use == instead of = in comparisons, = is just for assignments.

Offline Zipper5

  • BIS Team
  • ****
Re: Weapons check
« Reply #2 on: 22 Aug 2009, 21:18:42 »
Ah ok, fixed that. Thanks Mandoble. Unfortunately, the issue still persists. I get the following error message:

Code: [Select]
Error if: type code, expected Bool

*link to script*, line 39
(null)

(null)

Offline Deadfast

  • Members
  • *
Re: Weapons check
« Reply #3 on: 22 Aug 2009, 21:38:34 »
You're wrapping conditions in curly brackets, use round ones ;)


Code: [Select]
_mags = magazines player;
_weaps = weapons player;

_startMags = [
"30Rnd_556x45_Stanag",
"30Rnd_556x45_Stanag",
"30Rnd_556x45_Stanag",
"30Rnd_556x45_Stanag",
"30Rnd_556x45_Stanag",
"30Rnd_556x45_Stanag",
"HandGrenade_West",
"HandGrenade_West",
"SmokeShell",
"SmokeShell",
"1Rnd_HE_M203",
"1Rnd_HE_M203",
"FlareRed_M203",
"FlareGreen_M203",
"15Rnd_9x19_M9",
"15Rnd_9x19_M9",
"15Rnd_9x19_M9",
"15Rnd_9x19_M9"
];

_startWeaps = [
"M4A1_HWS_GL_camo",
"M9",
"Binocular",
"NVGoggles"
];

if (_mags == _startMags) then
{
if (_weaps == _startWeaps) then
{
hint "Since your weapon loadout has remained the same, presumably you missed the available gear selection. For this reason, it has been added to this helicopter.\nIt is accessable by selecting Gear in your Action Menu.";
//Gear selection follows...
};
};

Offline Zipper5

  • BIS Team
  • ****
Re: Weapons check
« Reply #4 on: 22 Aug 2009, 22:31:08 »
Heh, ok. Thanks Deadfast. Jeeze, all these SQF syntax errors. You can tell I'm only just starting to learn how to script in SQF...

Unfortunately, that still throws up an error, though it's a different one this time:

Code: [Select]
(null)
(null)


entry,Display (dialog),Control,Team member,Task,Location

*link to script*, line 39

 :confused:

Edit: This is what the current script looks like:

Code: [Select]
_mags = magazines player;
_weaps = weapons player;
_veh = vehicle player;

_startMags = [
"30Rnd_556x45_Stanag",
"30Rnd_556x45_Stanag",
"30Rnd_556x45_Stanag",
"30Rnd_556x45_Stanag",
"30Rnd_556x45_Stanag",
"30Rnd_556x45_Stanag",
"HandGrenade_West",
"HandGrenade_West",
"SmokeShell",
"SmokeShell",
"1Rnd_HE_M203",
"1Rnd_HE_M203",
"FlareRed_M203",
"FlareGreen_M203",
"15Rnd_9x19_M9",
"15Rnd_9x19_M9",
"15Rnd_9x19_M9",
"15Rnd_9x19_M9"
];

_startWeaps = [
"M4A1_HWS_GL_camo",
"M9",
"Binocular",
"NVGoggles"
];

sleep 2;

if (_mags == _startMags) then
{
if (_weaps == _startWeaps) then
{
hint "Since your weapon loadout has remained the same, presumably you missed the available gear selection. For this reason, it has been added to the helicopter.\n\nIt is accessable by selecting Gear in your Action Menu.\n\nYou can also change your squad members' loadouts by going to the Map screen, selecting Units, highlighting the member whose gear you wish to change, and selecting Gear.";

_veh addWeaponCargo ["M4A1_AIM", 4];
_veh addWeaponCargo ["M4A1_RCO_GL", 2];
_veh addWeaponCargo ["M4A1_HWS_GL", 2];
_veh addWeaponCargo ["M4SPR", 1];
_veh addWeaponCargo ["DMR", 1];
_veh addWeaponCargo ["MP5A5", 2];
_veh addWeaponCargo ["MP5SD", 2];
_veh addWeaponCargo ["M249", 2];
_veh addWeaponCargo ["M9", 5];
_veh addWeaponCargo ["M9SD", 2];
_veh addWeaponCargo ["M136", 2];
_veh addWeaponCargo ["Stinger", 2];
_veh addWeaponCargo ["Binocular", 4];
_veh addWeaponCargo ["NVGoggles", 4];

_veh addMagazineCargo ["30Rnd_556x45_Stanag", 54];
_veh addMagazineCargo ["20Rnd_762x51_DMR", 12];
_veh addMagazineCargo ["30Rnd_9x19_MP5", 12];
_veh addMagazineCargo ["30Rnd_9x19_MP5SD", 12];
_veh addMagazineCargo ["200Rnd_556x45_M249", 8];
_veh addMagazineCargo ["15Rnd_9x19_M9", 40];
_veh addMagazineCargo ["15Rnd_9x19_M9SD", 16];
_veh addMagazineCargo ["M136", 2];
_veh addMagazineCargo ["Stinger", 2];
_veh addMagazineCargo ["HandGrenade_West", 30];
_veh addMagazineCargo ["SmokeShell", 30];
_veh addMagazineCargo ["PipeBomb", 12];
};
};

waitUntil {!(w1 in wh1) && !(w2 in wh1) && !(w3 in wh1) && !(w4 in wh1)};

clearWeaponCargo wh1;
clearMagazineCargo wh1;

exit
« Last Edit: 22 Aug 2009, 22:36:56 by Zipper5 »

Offline Deadfast

  • Members
  • *
Re: Weapons check
« Reply #5 on: 23 Aug 2009, 00:13:25 »
Ah yeah, just realized you were comparing arrays. Unfortunately you can't do that like this, you need to compare every single array component with a respective counterpart.


Here's a function I made for this purpose:
Code: [Select]
_arrayCompare =
{
private ["_array1", "_array2", "_i", "_return"];

_array1 = _this select 0;
_array2 = _this select 1;

_return = true;
if ( (count _array1) != (count _array2) ) then
{
_return = false;
}
else
{
_i = 0;
while {_i < (count _array1) && _return} do
{
if ( (typeName (_array1 select _i)) != (typeName (_array2 select _i)) ) then
{
_return = false;
}
else
{
if (typeName (_array1 select _i) == "ARRAY") then
{
if (!([_array1 select _i, _array2 select _i] call _arrayCompare)) then
{
_return = false;
};
}
else
{
if ((_array1 select _i) != (_array2 select _i)) then
{
_return = false;
};
};
};
_i = _i + 1;
};
};

_return
};

Returns true if arrays match, false if not.


BTW, get rid of that exit at the end of the script, SQF scripts always end themselves with the end of the file ;)




This is how your script should look like:
Code: [Select]
_arrayCompare =
{
private ["_array1", "_array2", "_i", "_return"];

_array1 = _this select 0;
_array2 = _this select 1;

_return = true;
if ( (count _array1) != (count _array2) ) then
{
_return = false;
}
else
{
_i = 0;
while {_i < (count _array1) && _return} do
{
if ( (typeName (_array1 select _i)) != (typeName (_array2 select _i)) ) then
{
_return = false;
}
else
{
if (typeName (_array1 select _i) == "ARRAY") then
{
if (!([_array1 select _i, _array2 select _i] call _arrayCompare)) then
{
_return = false;
};
}
else
{
if ((_array1 select _i) != (_array2 select _i)) then
{
_return = false;
};
};
};
_i = _i + 1;
};
};

_return
};

_mags = magazines player;
_weaps = weapons player;
_veh = vehicle player;

_startMags = [
"30Rnd_556x45_Stanag",
"30Rnd_556x45_Stanag",
"30Rnd_556x45_Stanag",
"30Rnd_556x45_Stanag",
"30Rnd_556x45_Stanag",
"30Rnd_556x45_Stanag",
"HandGrenade_West",
"HandGrenade_West",
"SmokeShell",
"SmokeShell",
"1Rnd_HE_M203",
"1Rnd_HE_M203",
"FlareRed_M203",
"FlareGreen_M203",
"15Rnd_9x19_M9",
"15Rnd_9x19_M9",
"15Rnd_9x19_M9",
"15Rnd_9x19_M9"
];

_startWeaps = [
"M4A1_HWS_GL_camo",
"M9",
"Binocular",
"NVGoggles"
];

sleep 2;

if ([_mags, _startMags] call _arrayCompare && [_weaps, _startWeaps] call _arrayCompare) then
{
hint "Since your weapon loadout has remained the same, presumably you missed the available gear selection. For this reason, it has been added to the helicopter.\n\nIt is accessable by selecting Gear in your Action Menu.\n\nYou can also change your squad members' loadouts by going to the Map screen, selecting Units, highlighting the member whose gear you wish to change, and selecting Gear.";

_veh addWeaponCargo ["M4A1_AIM", 4];
_veh addWeaponCargo ["M4A1_RCO_GL", 2];
_veh addWeaponCargo ["M4A1_HWS_GL", 2];
_veh addWeaponCargo ["M4SPR", 1];
_veh addWeaponCargo ["DMR", 1];
_veh addWeaponCargo ["MP5A5", 2];
_veh addWeaponCargo ["MP5SD", 2];
_veh addWeaponCargo ["M249", 2];
_veh addWeaponCargo ["M9", 5];
_veh addWeaponCargo ["M9SD", 2];
_veh addWeaponCargo ["M136", 2];
_veh addWeaponCargo ["Stinger", 2];
_veh addWeaponCargo ["Binocular", 4];
_veh addWeaponCargo ["NVGoggles", 4];

_veh addMagazineCargo ["30Rnd_556x45_Stanag", 54];
_veh addMagazineCargo ["20Rnd_762x51_DMR", 12];
_veh addMagazineCargo ["30Rnd_9x19_MP5", 12];
_veh addMagazineCargo ["30Rnd_9x19_MP5SD", 12];
_veh addMagazineCargo ["200Rnd_556x45_M249", 8];
_veh addMagazineCargo ["15Rnd_9x19_M9", 40];
_veh addMagazineCargo ["15Rnd_9x19_M9SD", 16];
_veh addMagazineCargo ["M136", 2];
_veh addMagazineCargo ["Stinger", 2];
_veh addMagazineCargo ["HandGrenade_West", 30];
_veh addMagazineCargo ["SmokeShell", 30];
_veh addMagazineCargo ["PipeBomb", 12];
};

waitUntil {!(w1 in wh1) && !(w2 in wh1) && !(w3 in wh1) && !(w4 in wh1)};

clearWeaponCargo wh1;
clearMagazineCargo wh1;


EDIT: Updated the function so it now can work with nested arrays too, merged the 2 IFs
EDIT2: Fixed the function
« Last Edit: 23 Aug 2009, 11:46:07 by Deadfast »

Offline Zipper5

  • BIS Team
  • ****
Re: Weapons check
« Reply #6 on: 23 Aug 2009, 09:43:43 »
Thanks for that Deadfast. However, now I get an error about _array1 not being defined.

Offline Deadfast

  • Members
  • *
Re: Weapons check
« Reply #7 on: 23 Aug 2009, 11:44:27 »
Haha, no wonder, somehow I managed to leave out the defining part of the function, modifying my previous post.

Done and sorry about that :D
« Last Edit: 23 Aug 2009, 11:46:38 by Deadfast »