Jump to content
Sign in to follow this  
spitfire007

Problem making AND's and OR's play well together.

Recommended Posts

I am trying to add in some extra contidtions to a script that already works.

Here is what works.

waitUntil
{
   sleep 1; 
_playerPresent = false;
#ifdef __A2NET__
_currTime = floor(netTime);
#else
   _currTime = floor(time);
#endif
   if(_currTime - _startTime >= sideMissionTimeout) then {_result = 1;};
   {if((isPlayer _x) AND (_x distance _box <= missionRadiusTrigger)) then {_playerPresent = true};}forEach playableUnits;
   _unitsAlive = ({alive _x} count units CivGrpS);
   (_result == 1) OR ((_playerPresent) AND (_unitsAlive < 1)) OR (damage _box == 1) 
};

What I am trying to do is add in a check to see if both boxes are damaged.

So what I have tried is.

(_result == 1) OR ((_playerPresent) AND (_unitsAlive < 1)) OR damage _box == 1 AND damage _box2 == 1

(_result == 1) OR ((_playerPresent) AND (_unitsAlive < 1)) OR (damage _box == 1) AND (damage _box2 == 1)

(_result == 1) OR ((_playerPresent) AND (_unitsAlive < 1)) OR ((damage _box == 1) AND (damage _box2 == 1))

Is this something to do with lazy evaluation ?

Because it's not working for me .. and I just don't get it.

Share this post


Link to post
Share on other sites

Try this:

(_result == 1) OR (((_playerPresent) AND (_unitsAlive < 1)) OR (((damage _box) == 1) AND ((damage _box2)) == 1)) 

Share this post


Link to post
Share on other sites

Well . thanks for looking at it ...

It looked good to me !

But it still does not work as I expect it to.

I tried this too.

(_result == 1) OR ((_playerPresent) AND (_unitsAlive < 1)) OR (((damage _box) == 1) AND ((damage _box2)) == 1)

It just seems like it should work as you described above !

Share this post


Link to post
Share on other sites

How do you want it to work? I understood you want it to end the mission if both of the boxes are destroyed?

Share this post


Link to post
Share on other sites

Are you sure that _box2, referring to the correct object, absolutely certainly is accessible/exists in that scope?

Share this post


Link to post
Share on other sites

Yes that is correct. I need it to continue the script once any of the conditions in the waituntil are true.

So, in this case it is to continue if.

1. the mission times out (_result == 1)

OR.

2. a player is within 30m of the boxes AND all the AI have been killed. (_playerPresent) AND (_unitsAlive < 1)

OR

both the ammo boxes _box and _box2 have been destroyed. (damage _box == 1) AND (damage _box2 == 1)

Everything works exactly as expected if you only use this line.

(_result == 1) OR ((_playerPresent) AND (_unitsAlive < 1)) OR (damage _box == 1)

The problem is when you add the second box .. if you try to check that BOTH boxes are destroyed it just exits the waituntil.

---------- Post added at 01:54 ---------- Previous post was at 01:08 ----------

Are you sure that _box2, referring to the correct object, absolutely certainly is accessible/exists in that scope?

I am certain it's referring to the correct object.

As for scope. The two boxes are made right after each other so I can't see why the scope is a problem.

Here is the whole script. Thanks for looking !

#include "setup.sqf"
#include "sideMissionDefines.sqf";

if(!isServer) exitwith {};

private ["_result","_missionMarkerName","_missionType","_startTime","_returnData","_randomPos","_randomIndex","_vehicleClass","_box","_box2","_vehicle","_picture","_vehicleName","_hint","_currTime","_playerPresent","_unitsAlive"];

//Mission Initialization.
_result = 0;
_missionMarkerName = "AirWreck_Marker";
_missionType = "Aircraft Wreck";
_nerfBoxes = ["basicUS","basicUS2","basicRU","basicRU2","basicGER","basicPMC","basicSpecial","basicSpecial2","basicSpecial3"];
#ifdef __A2NET__
_startTime = floor(netTime);
#else
_startTime = floor(time);
#endif


//Get Mission Location
_returnData = call createMissionLocation;
_randomPos = _returnData select 0;
_randomIndex = _returnData select 1;


[sideMissionDelayTime] call createWaitCondition;


[_missionMarkerName,_randomPos,_missionType] call createClientMarker;

//Vehicle Class, Posistion, Fuel, Ammo, Damage
_vehicle = ["C130J_US_EP1",[(_randomPos select 0) + 50, (_randomPos select 1) + 50,0],0,0,1,"NONE"] call createMissionVehicle;

_box = createVehicle ["USLaunchersBox",[(_randomPos select 0), (_randomPos select 1),0],[], 0, "NONE"];
[_box,"mission_Side_USLaunchers"] call fn_refillbox;

_box2 = _nerfBoxes select (random (count _nerfBoxes - 1));
_safePos = [_randomPos, 2, 10, 1, 0, 60 * (pi / 180), 0] call BIS_fnc_findSafePos;
[_box2, _safePos] execVM "spawning\boxCreation.sqf";   

_picture = getText (configFile >> "cfgVehicles" >> typeOf _vehicle >> "picture");
_vehicleName = getText (configFile >> "cfgVehicles" >> typeOf _vehicle >> "displayName");
_hint = parseText format ["<t align='center' color='%4' shadow='2' size='1.75'>Side Objective</t><br/><t align='center' color='%4'>------------------------------</t><br/><t align='center' color='%5' size='1.25'>%1</t><br/><t align='center'><img size='5' image='%2'/></t><br/><t align='center' color='%5'>A<t color='%4'> %3</t> has come down under enemy fire!</t>", _missionType, _picture, _vehicleName, sideMissionColor, subTextColor];
[nil,nil,rHINT,_hint] call RE;

CivGrpS = createGroup civilian;
[CivGrpS,_randomPos] spawn createSmallGroup;


#ifdef __A2NET__
_startTime = floor(netTime);
#else
_startTime = floor(time);
#endif
waitUntil
{
   sleep 1; 
_playerPresent = false;
#ifdef __A2NET__
_currTime = floor(netTime);
#else
   _currTime = floor(time);
#endif
   if(_currTime - _startTime >= sideMissionTimeout) then {_result = 1;};
   {if((isPlayer _x) AND (_x distance _box <= missionRadiusTrigger)) then {_playerPresent = true};}forEach playableUnits;
   _unitsAlive = ({alive _x} count units CivGrpS);
   (_result == 1) OR ((_playerPresent) AND (_unitsAlive < 1)) OR (damage _box == 1)
//(_result == 1) OR ((_playerPresent) AND (_unitsAlive < 1)) OR (((damage _box) == 1) AND ((damage _box2)) == 1)

};

if(_result == 1) then
{
//Mission Failed.
   deleteVehicle _box;
   deleteVehicle _box2;
   deleteVehicle _vehicle;
   {deleteVehicle _x;}forEach units CivGrpS;
   deleteGroup CivGrpS;
   _hint = parseText format ["<t align='center' color='%4' shadow='2' size='1.75'>Objective Failed</t><br/><t align='center' color='%4'>------------------------------</t><br/><t align='center' color='%5' size='1.25'>%1</t><br/><t align='center'><img size='5' image='%2'/></t><br/><t align='center' color='%5'>Objective failed, better luck next time.</t>", _missionType, _picture, _vehicleName, failMissionColor, subTextColor];
[nil,nil,rHINT,_hint] call RE;


} else {

 if ((damage _box) == 1) then 
 {
   deleteVehicle _vehicle;
   {deleteVehicle _x;}forEach units CivGrpS;
   deleteGroup CivGrpS;
   _hint = parseText format ["<t align='center' color='%4' shadow='2' size='1.75'>2: Objective Failed</t><br/><t align='center' color='%4'>------------------------------</t><br/><t align='center' color='%5' size='1.25'>%1</t><br/><t align='center'><img size='5' image='%2'/></t><br/><t align='center' color='%5'>Objective failed, someone blew up the crates.</t>", _missionType, _picture, _vehicleName, failMissionColor, subTextColor];
[nil,nil,rHINT,_hint] call RE;
//Reset the mission spawn bool


} else {

   //Mission Complete.
   deleteVehicle _vehicle;
   {deleteVehicle _x;}forEach units CivGrpS;
deleteGroup CivGrpS;
   _hint = parseText format ["<t align='center' color='%4' shadow='2' size='1.75'>Objective Complete</t><br/><t align='center' color='%4'>------------------------------</t><br/><t align='center' color='%5' size='1.25'>%1</t><br/><t align='center'><img size='5' image='%2'/></t><br/><t align='center' color='%5'>The ammo caches have been collected.</t>", _missionType, _picture, _vehicleName, successMissionColor, subTextColor];
[nil,nil,rHINT,_hint] call RE;

};
};

//Reset Mission Spot.
MissionSpawnMarkers select _randomIndex set[1, false];
[_missionMarkerName] call deleteClientMarker;

Share this post


Link to post
Share on other sites

As far as I can tell _box2 is a string not a vehicle-object (it should tell in rpt though) -

_nerfBoxes = ["basicUS","basicUS2","basicRU","basicRU2","basicGER","basicPMC","basicSpecial","basicSpecial2","basicSpecial3"]; 
...
_box2 = _nerfBoxes select (random (count _nerfBoxes - 1));
...
[_box2, _safePos] execVM "spawning\boxCreation.sqf";

So, perhaps the boxCreation.sqf returns the object? So maybe the last line above should instead look like -

[s]_box2 = [_box2, _safePos] execVM "spawning\boxCreation.sqf";[/s]

Disregard that... forgot that execVM returns the script handle, so I'm unsure how boxCreation.sqf would provide a reference to the actual object. If it's the same boxCreation.sqf as apparently is used in some wasteland missions, then that one doesn't seem to provide a direct way for referencing the vehicle-object that was created. However I suppose you could do something like that after the execVM (but before the waitUntil in which you check for the box damage) -

private[...,"_boxcreation"];
...
_boxcreation = [_box2, _safePos] execVM "spawning\boxCreation.sqf";
...
waitUntil{scriptDone _boxcreation};
_box2 = nearestObject [_safePos, _box2];//Note that up to this point I expect the _box2 to be the string, from here on it would be the box itself (hopefully)

If I'm reading the code correctly, you're spawning the second box quite close to the first one so if there's a chance that the second box is of the same type as the first (wouldn't appear to be such chance with that boxCreation.sqf and that _nerfBoxes but I'm still providing this just in case) you might instead of the last line need something like -

//If it's the same boxCreation.sqf I think it is, then it spawns the box at up to 30m away, leaving a small margin, I've put 40 here; if you know yours to work different, adjust as necessary
_boxes = nearestObjects [_safePos, [_box2], 40];
{
if(_x != _box1)exitWith{_box2=_x};
}forEach _boxes;

However this expects these two to be the only two ammoboxes with with such classes in the area. The provided script doesn't suggest presence of more, so it should be ok.

Also in the commented line, there appears to be little (probabaly insignificant) parenthesizing typo at the last expression -

//(... AND ((damage _box2)) == 1)

which is probably meant as

//(... AND ((damage _box2) == 1))

Edited by geqqo

Share this post


Link to post
Share on other sites

Thanks for that. 2 posts and you are hitting the ground running geqqo .. well done.

I see now that it is a string and not an object.

There was no return on the boxCreation.sqf so I put _box2 at the bottom as a return and used

_box2 = [_box2, _safePos] execVM "spawning\boxCreation.sqf";

To call it.

Unfortunately _box2 no longer spawns in...

Sorry if this is a bit noob .. but I am still on my scripting L plates.

if(!X_Server) exitWith {};

private ["_selectedBox", "_selectedBoxPos", "_finishedBox", "_currBox","_box2"];

_selectedBox = _this select 0;
_selectedBoxPos = _this select 1;

switch(_selectedBox) do {
case "basicUS": { // Basic US 1 is mainly M16's and standard US Army weaponry
   	_currBox = createVehicle ["USBasicWeaponsBox", _selectedBoxPos,[], 30, "NONE"];

       // Clear prexisting weapons first
       clearMagazineCargoGlobal _currBox;
	clearWeaponCargoGlobal _currBox;

       // Add new weapons before ammunition
       _currBox addWeaponCargoGlobal ["M16A2",2];
	_currBox addWeaponCargoGlobal ["M16A2GL",2];
	_currBox addWeaponCargoGlobal ["M4A1_HWS_GL",2];
       _currBox addWeaponCargoGlobal ["M249_EP1",1];
       _currBox addWeaponCargoGlobal ["M24",2];

	_currBox addWeaponCargoGlobal ["M9",8];	

       // Add ammunition
       _currBox addMagazineCargoGlobal ["15Rnd_9x19_M9",50];
       _currBox addMagazineCargoGlobal ["30Rnd_556x45_Stanag",75];
       _currBox addMagazineCargoGlobal ["200Rnd_556x45_M249",10];
       _currBox addMagazineCargoGlobal ["5Rnd_762x51_M24",30];
       _currBox addMagazineCargoGlobal ["HandGrenade",10];
       _currBox addMagazineCargoGlobal ["1Rnd_HE_M203",15];
       _currBox addMagazineCargoGlobal ["1Rnd_Smoke_M203",15];  
   };
   case "basicUS2": { // Basic US 2 is a few M4's and some combat shotguns
   	_currBox = createVehicle ["USBasicWeaponsBox", _selectedBoxPos,[], 30, "NONE"];

       // Clear prexisting weapons first
       clearMagazineCargoGlobal _currBox;
	clearWeaponCargoGlobal _currBox;

       // Add new weapons before ammunition
       _currBox addWeaponCargoGlobal ["M4A3_CCO_EP1",2];
	_currBox addWeaponCargoGlobal ["M4A1_RCO_GL",2];
	_currBox addWeaponCargoGlobal ["M1014",2];
       _currBox addWeaponCargoGlobal ["m240_scoped_EP1",1];
       _currBox addWeaponCargoGlobal ["M4SPR",2];

	_currBox addWeaponCargoGlobal ["M9",8];	

       // Add ammunition
       _currBox addMagazineCargoGlobal ["15Rnd_9x19_M9",50];
       _currBox addMagazineCargoGlobal ["30Rnd_556x45_Stanag",75];
       _currBox addMagazineCargoGlobal ["100Rnd_762x51_M240",10];
       _currBox addMagazineCargoGlobal ["HandGrenade",10];
       _currBox addMagazineCargoGlobal ["1Rnd_HE_M203",10];
       _currBox addMagazineCargoGlobal ["1Rnd_Smoke_M203",10];
       _currBox addMagazineCargoGlobal ["8Rnd_B_Beneli_74Slug",25];
       _currBox addMagazineCargoGlobal ["8Rnd_B_Beneli_Pellets",25];
   };
   case "basicRU": { // Basic RU 1 is mainly AK's and better pistols, footsoldier weapons.
   	_currBox = createVehicle ["RUBasicWeaponsBox", _selectedBoxPos,[], 30, "NONE"];

       // Clear prexisting weapons first
       clearMagazineCargoGlobal _currBox;
	clearWeaponCargoGlobal _currBox;

       // Add new weapons before ammunition
       _currBox addWeaponCargoGlobal ["ksvk",1];
	_currBox addWeaponCargoGlobal ["AK_107_GL_kobra",2];
	_currBox addWeaponCargoGlobal ["AKS_74_U",4];
       _currBox addWeaponCargoGlobal ["Sa58V_CCO_EP1",2];
       _currBox addWeaponCargoGlobal ["RPK_74",1];

	_currBox addWeaponCargoGlobal ["MakarovSD",4];	
       _currBox addWeaponCargoGlobal ["Sa61_EP1",4];	

       // Add ammunition
       _currBox addMagazineCargoGlobal ["30Rnd_545x39_AK",50];
       _currBox addMagazineCargoGlobal ["30Rnd_762x39_SA58",25];
       _currBox addMagazineCargoGlobal ["75Rnd_545x39_RPK",5];
       _currBox addMagazineCargoGlobal ["8Rnd_9x18_MakarovSD",24];
       _currBox addMagazineCargoGlobal ["20Rnd_B_765x17_Ball",24];
       _currBox addMagazineCargoGlobal ["5Rnd_127x108_KSVK",12];
       _currBox addMagazineCargoGlobal ["HandGrenade",10];
       _currBox addMagazineCargoGlobal ["1Rnd_HE_GP25",15];
       _currBox addMagazineCargoGlobal ["1Rnd_SMOKE_GP25",15];
   };
   case "basicRU2": { // More Ak's and some shotguns and other crap
   	_currBox = createVehicle ["RUBasicWeaponsBox", _selectedBoxPos,[], 30, "NONE"];

       // Clear prexisting weapons first
       clearMagazineCargoGlobal _currBox;
	clearWeaponCargoGlobal _currBox;

       // Add new weapons before ammunition
       _currBox addWeaponCargoGlobal ["AK_47_M",4];
	_currBox addWeaponCargoGlobal ["Saiga12K",2];
       _currBox addWeaponCargoGlobal ["AKS_74_GOSHAWK",1];
       _currBox addWeaponCargoGlobal ["SVD",1];
       _currBox addWeaponCargoGlobal ["AKS_74_pso",2];

       _currBox addWeaponCargoGlobal ["MakarovSD",4];	
	_currBox addWeaponCargoGlobal ["Makarov",4];	

       // Add ammunition
       _currBox addMagazineCargoGlobal ["30Rnd_545x39_AK",50];
       _currBox addMagazineCargoGlobal ["10Rnd_762x54_SVD",20];
       _currBox addMagazineCargoGlobal ["30Rnd_762x39_AK47",35];
       _currBox addMagazineCargoGlobal ["8Rnd_9x18_Makarov",24];
       _currBox addMagazineCargoGlobal ["8Rnd_9x18_MakarovSD",24];
       _currBox addMagazineCargoGlobal ["HandGrenade",5];
       _currBox addMagazineCargoGlobal ["8Rnd_B_Saiga12_74Slug",25];
       _currBox addMagazineCargoGlobal ["8Rnd_B_Saiga12_Pellets",25];
   };
   case "basicGER": { // G36s everywhere...
   	_currBox = createVehicle ["GERBasicWeapons_EP1", _selectedBoxPos,[], 30, "NONE"];

       // Clear prexisting weapons first
       clearMagazineCargoGlobal _currBox;
	clearWeaponCargoGlobal _currBox;

       // Add new weapons before ammunition
       _currBox addWeaponCargoGlobal ["G36C_camo",2];
	_currBox addWeaponCargoGlobal ["G36_C_SD_eotech",2];
	_currBox addWeaponCargoGlobal ["G36a",2];
       _currBox addWeaponCargoGlobal ["MG36",1];
       _currBox addWeaponCargoGlobal ["MP5A5",2];
       _currBox addWeaponCargoGlobal ["MP5SD",2];

	_currBox addWeaponCargoGlobal ["glock17_EP1",4];	
       _currBox addWeaponCargoGlobal ["UZI_SD_EP1",4];	

       // Add ammunition

       _currBox addMagazineCargoGlobal ["30Rnd_9x19_MP5SD",25];
       _currBox addMagazineCargoGlobal ["30Rnd_9x19_MP5",25];
       _currBox addMagazineCargoGlobal ["30Rnd_556x45_G36",50];
       _currBox addMagazineCargoGlobal ["100Rnd_556x45_BetaCMag",10];
       _currBox addMagazineCargoGlobal ["30Rnd_556x45_G36SD",30];
       _currBox addMagazineCargoGlobal ["17Rnd_9x19_glock17",24];
       _currBox addMagazineCargoGlobal ["30Rnd_9x19_UZI_SD",24];
       _currBox addMagazineCargoGlobal ["HandGrenade",10];
   };
   case "basicPMC": { // Most OP weapons in the game, this will be a saught after crate.
   	_currBox = createVehicle ["Ammobox_PMC", _selectedBoxPos,[], 30, "NONE"];

       // Clear prexisting weapons first
       clearMagazineCargoGlobal _currBox;
	clearWeaponCargoGlobal _currBox;

       // Add new weapons before ammunition
       _currBox addWeaponCargoGlobal ["M8_carbine",2];
	_currBox addWeaponCargoGlobal ["M8_carbineGL",2];   
       _currBox addWeaponCargoGlobal ["m8_holo_sd",2];
       _currBox addWeaponCargoGlobal ["m8_SAW",1];
	_currBox addWeaponCargoGlobal ["AA12_PMC",2];

	_currBox addWeaponCargoGlobal ["M9",4];	
       _currBox addWeaponCargoGlobal ["M9SD",4];	

       // Add ammunition
       _currBox addMagazineCargoGlobal ["30Rnd_556x45_Stanag",50];

       _currBox addMagazineCargoGlobal ["20Rnd_B_AA12_Pellets",25];
       _currBox addMagazineCargoGlobal ["20Rnd_B_AA12_74Slug",25];
       _currBox addMagazineCargoGlobal ["20Rnd_B_AA12_HE",6];
       _currBox addMagazineCargoGlobal ["30Rnd_556x45_StanagSD",25];
       _currBox addMagazineCargoGlobal ["100Rnd_556x45_BetaCMag_airLock",10];
       _currBox addMagazineCargoGlobal ["15Rnd_9x19_M9SD",20];
       _currBox addMagazineCargoGlobal ["15Rnd_9x19_M9",24];
       _currBox addMagazineCargoGlobal ["HandGrenade",10];
       _currBox addMagazineCargoGlobal ["1Rnd_HE_M203",10];
       _currBox addMagazineCargoGlobal ["1Rnd_Smoke_M203",10];
   };
   case "basicSpecial": { // Silent weapons
   	_currBox = createVehicle ["SpecialWeaponsBox", _selectedBoxPos,[], 30, "NONE"];

       // Clear prexisting weapons first
       clearMagazineCargoGlobal _currBox;
	clearWeaponCargoGlobal _currBox;

       // Add new weapons before ammunition
       _currBox addWeaponCargoGlobal ["m8_compact_pmc",2];
       _currBox addWeaponCargoGlobal ["m8_sharpshooter",2];
       _currBox addWeaponCargoGlobal ["SCAR_L_CQC_CCO_SD",2];
       _currBox addWeaponCargoGlobal ["SCAR_L_CQC_EGLM_Holo",2];
       _currBox addWeaponCargoGlobal ["M40A3",2];

       _currBox addWeaponCargoGlobal ["UZI_SD_EP1",4];
       _currBox addWeaponCargoGlobal ["M9SD",4];

       // Add ammunition
       _currBox addMagazineCargoGlobal ["5Rnd_762x51_M24",30];
       _currBox addMagazineCargoGlobal ["30Rnd_556x45_Stanag",50];
       _currBox addMagazineCargoGlobal ["30Rnd_556x45_StanagSD",50];
       _currBox addMagazineCargoGlobal ["15Rnd_9x19_M9SD",24];
       _currBox addMagazineCargoGlobal ["30Rnd_9x19_UZI_SD",24];
       _currBox addMagazineCargoGlobal ["1Rnd_HE_M203",10];
       _currBox addMagazineCargoGlobal ["1Rnd_Smoke_M203",10];
   };
   case "basicSpecial2": { // BAF weapons
   	_currBox = createVehicle ["SpecialWeaponsBox", _selectedBoxPos,[], 30, "NONE"];

       // Clear prexisting weapons first
       clearMagazineCargoGlobal _currBox;
	clearWeaponCargoGlobal _currBox;

       // Add new weapons before ammunition
       _currBox addWeaponCargoGlobal ["BAF_L85A2_RIS_CWS",1];
       _currBox addWeaponCargoGlobal ["BAF_LRR_scoped",1];
	_currBox addWeaponCargoGlobal ["BAF_L86A2_ACOG",2];
	_currBox addWeaponCargoGlobal ["BAF_L85A2_UGL_Holo",2];
       _currBox addWeaponCargoGlobal ["BAF_L110A1_Aim",2];

	_currBox addWeaponCargoGlobal ["glock17_EP1",8];	

       // Add ammunition
       _currBox addMagazineCargoGlobal ["30Rnd_556x45_Stanag",100];
       _currBox addMagazineCargoGlobal ["200Rnd_556x45_L110A1",20];
       _currBox addMagazineCargoGlobal ["5Rnd_86x70_L115A1",10];
       _currBox addMagazineCargoGlobal ["17Rnd_9x19_glock17",24];
       _currBox addMagazineCargoGlobal ["BAF_L109A1_HE",10];
       _currBox addMagazineCargoGlobal ["1Rnd_HE_M203",10];
       _currBox addMagazineCargoGlobal ["1Rnd_Smoke_M203",10];
   };
   case "basicSpecial3": { // Maggoty weapons, mostly shit
   	_currBox = createVehicle ["TKBasicWeapons_EP1", _selectedBoxPos,[], 30, "NONE"];

       // Clear prexisting weapons first
       clearMagazineCargoGlobal _currBox;
	clearWeaponCargoGlobal _currBox;

       // Add new weapons before ammunition
       _currBox addWeaponCargoGlobal ["AK_47_S",2];
	_currBox addWeaponCargoGlobal ["LeeEnfield",2];
	_currBox addWeaponCargoGlobal ["FN_FAL",2];
       _currBox addWeaponCargoGlobal ["VSS_Vintorez",1];
       _currBox addWeaponCargoGlobal ["PK",1];
       _currBox addWeaponCargoGlobal ["huntingrifle",1];
       _currBox addWeaponCargoGlobal ["bizon_silenced",2];

	_currBox addWeaponCargoGlobal ["revolver_EP1",4];	 
       _currBox addWeaponCargoGlobal ["Colt1911",4];

       // Add ammunition
       _currBox addMagazineCargoGlobal ["30Rnd_762x39_AK47",50];
       _currBox addMagazineCargoGlobal ["100Rnd_762x54_PK",10];
       _currBox addMagazineCargoGlobal ["5x_22_LR_17_HMR",25];
       _currBox addMagazineCargoGlobal ["64Rnd_9x19_SD_Bizon",35];
       _currBox addMagazineCargoGlobal ["6Rnd_45ACP",24];
       _currBox addMagazineCargoGlobal ["7Rnd_45ACP_1911",24];
       _currBox addMagazineCargoGlobal ["HandGrenade",15];
       _currBox addMagazineCargoGlobal ["20Rnd_762x51_FNFAL",35];
       _currBox addMagazineCargoGlobal ["10x_303",50];
       _currBox addMagazineCargoGlobal ["10Rnd_9x39_SP5_VSS",10];
   };
   case "mission_Mid_BAF": { // Broad selection mid-high tier weapons 
   	_currBox = createVehicle ["BAF_BasicWeapons", _selectedBoxPos,[], 30, "NONE"];

       // Clear prexisting weapons first
       clearMagazineCargoGlobal _currBox;
	clearWeaponCargoGlobal _currBox;

       // Add new weapons before ammunition
       _currBox addWeaponCargoGlobal ["BAF_LRR_scoped",1];
       _currBox addWeaponCargoGlobal ["SVD_CAMO",2];
	_currBox addWeaponCargoGlobal ["M14_EP1",1];			
	_currBox addWeaponCargoGlobal ["BAF_L7A2_GPMG",1];
       _currBox addWeaponCargoGlobal ["BAF_L110A1_Aim",1];
	_currBox addWeaponCargoGlobal ["BAF_L85A2_RIS_CWS",1];
       _currBox addWeaponCargoGlobal ["BAF_L85A2_RIS_Holo",1];
       _currBox addWeaponCargoGlobal ["BAF_L85A2_UGL_Holo",1];		
	_currBox addWeaponCargoGlobal ["FN_FAL_ANPVS4",1];
	_currBox addWeaponCargoGlobal ["M9",4];	 
       _currBox addWeaponCargoGlobal ["M9SD",4];

       // Add ammunition
       _currBox addMagazineCargoGlobal ["30Rnd_556x45_Stanag",50];
       _currBox addMagazineCargoGlobal ["15Rnd_9x19_M9",25];
	_currBox addMagazineCargoGlobal ["15Rnd_9x19_M9SD",25];
       _currBox addMagazineCargoGlobal ["100Rnd_762x51_M240",10];
       _currBox addMagazineCargoGlobal ["1Rnd_HE_M203",5];
       _currBox addMagazineCargoGlobal ["1Rnd_Smoke_M203",5];
       _currBox addMagazineCargoGlobal ["6Rnd_45ACP",5];
       _currBox addMagazineCargoGlobal ["HandGrenade",5];
	_currBox addMagazineCargoGlobal ["200Rnd_556x45_L110A1",10];
       _currBox addMagazineCargoGlobal ["5Rnd_86x70_L115A1",10];
       _currBox addMagazineCargoGlobal ["20Rnd_762x51_DMR",10];
       _currBox addMagazineCargoGlobal ["20Rnd_762x51_FNFAL",15];
	_currBox addMagazineCargoGlobal ["10Rnd_762x54_SVD",20]; 		
   };
};

//added these lines to return back to the main script.
_box2 = _currBox;

_box2

Share this post


Link to post
Share on other sites

I saw your post just now. Oddly enough I didn't see your post immediately when doing the multiple edits to my post (even though I did the last edit a good while after your post). My edited post should still apply (you will not be needing the modifications you did to the boxCreation.sqf).

Share this post


Link to post
Share on other sites

Thanks for putting in so much work on this.

_box2 is now spawning with the code below.

private[...,"_boxcreation"];
...
_boxcreation = [_box2, _safePos] execVM "spawning\boxCreation.sqf";
...
waitUntil{scriptDone _boxcreation};
_box2 = nearestObject [_safePos, _box2];//Note that up to this point I expect the _box2 to be the string, from here on it would be the box itself (hopefully)

You are right the ammo boxes are different. One is launchers the other guns.

So

_box2 = nearestObject [_safePos, _box2];

Should be ok.

BUT ...

It still does not detect that _box2 has been blown up.

I used this to make sure _box was being detected correctly.

(_result == 1) OR ((_playerPresent) AND (_unitsAlive < 1)) OR (damage _box == 1)

Then this for _box2.

(_result == 1) OR ((_playerPresent) AND (_unitsAlive < 1)) OR (damage _box2 == 1)

No go unfortunately.

Share this post


Link to post
Share on other sites

Ahh, I disregarded a detail in there - the _box2 isn't even the classname, but the "key-string" that the boxCreation.sqf expects, so the nearestObject will currently always give a null object. So there's various ways to solve this. A more experienced scripter might be able to tell which solution would be the most advisable here but here's what comes to my mind -

1. If you're only using the boxCreation.sqf in this instance (or don't mind changing the other instances to use the classnames as well), then modifying the expected strings in boxCreation.sqf (and _nerfBoxes) to the classnames (e.g. case "basicUS": -> case "USBasicWeaponsBox":). Otherwise a lookup table could do the job (e.g. one array with ["basicUS",...] (which you already have as _nerfBoxes) and another with ["USBasicWeaponsBox",...] and then something like _array2 select (_nerfBoxes find _box2) for the respective nearestObject's argument).

2. A global variable. E.g. either modifying the boxCreation to write to a specific global variable and read that after the script is done or make it accept a name for a global variable as a string (should you intend to have multiple scripts spawning in crates independently (with different global variables)) which it would write back to (getVariable/setVariable with missionNamespace).

3. Preprocess/compile the file into a variable* (function) and call it having modified the last line of the boxCreation.sqf to return _currBox. * (or if you're only going to ever call it once then might just _box2 = call compile preprocessFile "spawning\boxCreation.sqf" without storing the compile result to a variable).

Edited by geqqo

Share this post


Link to post
Share on other sites

Much appreciated geqqo.

I will try the above and report back. Probably tomorrow .. my eyes are kind of bloodshot looking at too much code today !

Share this post


Link to post
Share on other sites

The best way to do this would probably be to either preprocess the boxcreation script or include it in the mission file as a whole and make it return the actual created box. A solution depending on the nearestobject command is quite horrible tbh.

This way there's no need to create a global variable and no waituntils need to be implemented just in case.

Then you could do it like this:

//End the boxcreation with the created box, simple as this:
_box = createvehicle...
_box;

//The created box would be _createdbox.
_createdbox = [_box2, _safePos] call boxCreation;

Share this post


Link to post
Share on other sites

Agreed, I was just about to edit above that the 3rd option would likely be the best one to go by.

Share this post


Link to post
Share on other sites

Perfect !

It is now working 100% as expected using Viba's solution above.

If this board had rep points you would both be getting them.

Much appreciated guys, I would NEVER have figured this out myself and I have learnt a lot from both of you. :bounce3:

Edited by spitfire007

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
Sign in to follow this  

×