Jump to content
Sign in to follow this  
Mirek

Script runs Twice instead of once. Dont know why.

Recommended Posts

I have a script named truck.sqf

if (isServer) then {

_vehicle_1 = objNull;
if (true) then
{
 _this = createVehicle ["Ural_UN_EP1", [8618.9258, 2599.2754, -4.2915344e-006], [], 0, "CAN_COLLIDE"];
 _vehicle_1 = _this;
 _this setDir 155.97241;
 _this setPos [8618.9258, 2599.2754, -4.2915344e-006];
 _this sethit ["wheel_1_1_steering",1];
};

_vehicle_2 = objNull;
if (true) then
{
 _this = createVehicle ["Ural_UN_EP1", [8608.3711, 2615.105, -1.5258789e-005], [], 0, "CAN_COLLIDE"];
 _vehicle_2 = _this;
 _this setDir -171.47652;
 _this setPos [8608.3711, 2615.105, -1.5258789e-005];
};

_vehicle_3 = objNull;
if (true) then
{
 _this = createVehicle ["Ural_UN_EP1", [8602.0576, 2628.5286, -5.9604645e-005], [], 0, "CAN_COLLIDE"];
 _vehicle_3 = _this;
 _this setDir -175.51186;
 _this setPos [8602.0576, 2628.5286, -5.9604645e-005];
};

_vehicle_4 = objNull;
if (true) then
{
 _this = createVehicle ["Ural_UN_EP1", [8596.2676, 2642.9153, -2.2888184e-005], [], 0, "CAN_COLLIDE"];
 _vehicle_4 = _this;
 _this setDir -189.62248;
 _this setPos [8596.2676, 2642.9153, -2.2888184e-005];
};

_vehicle_6 = objNull;
if (true) then
{
 _this = createVehicle ["UAZ_Unarmed_UN_EP1", [8593.1455, 2656.0056, 3.8146973e-006], [], 0, "CAN_COLLIDE"];
 _vehicle_6 = _this;
 _this setDir 151.63525;
 _this setPos [8593.1455, 2656.0056, 3.8146973e-006];
};

_vehicle_7 = objNull;
if (true) then
{
 _this = createVehicle ["UAZ_Unarmed_UN_EP1", [8587.5156, 2662.9124, 1.0490417e-005], [], 0, "CAN_COLLIDE"];
 _vehicle_7 = _this;
 _this setDir 194.97041;
 _this setPos [8587.5156, 2662.9124, 1.0490417e-005];
};

_vehicle_12 = objNull;
if (true) then
{
 _this = createVehicle ["LadaLM", [8634.1074, 2591.7109, 4.0054321e-005], [], 0, "CAN_COLLIDE"];
 _vehicle_12 = _this;
 _this setDir -8.3406734;
 _this setPos [8634.1074, 2591.7109, 4.0054321e-005];
};

_this = createCenter civilian;
_this setFriend [east, 0];
_center_1 = _this;

_group_1 = createGroup _center_1;

_group_3 = createGroup _center_1;

_group_4 = createGroup _center_1;

_group_5 = createGroup _center_1;

_unit_2 = objNull;
if (true) then
{
 _this = _group_5 createUnit ["Policeman", [8646.4141, 2559.5491, 1.5735626e-005], [], 0, "CAN_COLLIDE"];
 _unit_2 = _this;
 _this setDir 152.46233;
 _this setUnitAbility 0.60000002;
 if (true) then {_group_5 selectLeader _this;};
};

_unit_3 = objNull;
if (true) then
{
 _this = _group_4 createUnit ["Policeman", [8573.2393, 2697.1929, -2.6702881e-005], [], 0, "CAN_COLLIDE"];
 _unit_3 = _this;
 _this setDir -50.373871;
 _this setUnitAbility 0.60000002;
 if (false) then {_group_4 selectLeader _this;};
};

_this = createCenter resistance;
_this setFriend [east, 0];
_center_2 = _this;

_group_6 = createGroup _center_2;

_group_7 = createGroup _center_2;

_unit_4 = objNull;
if (true) then
{
 _this = _group_7 createUnit ["UN_CDF_Soldier_Officer_EP1", [8628.3105, 2565.7915, -5.7220459e-005], [], 0, "CAN_COLLIDE"];
 _unit_4 = _this;
 _this setDir 141.05481;
 _this setUnitAbility 0.60000002;
 if (true) then {_group_7 selectLeader _this;};
};

_unit_8 = objNull;
if (true) then
{
 _this = _group_7 createUnit ["UN_CDF_Soldier_MG_EP1", [8628.5488, 2568.9143, 2.0027161e-005], [], 0, "CAN_COLLIDE"];
 _unit_8 = _this;
 _this setDir 66.318787;
 _this setUnitAbility 0.60000002;
 if (false) then {_group_7 selectLeader _this;};
};

_unit_10 = objNull;
if (true) then
{
 _this = _group_7 createUnit ["UN_CDF_Soldier_AMG_EP1", [8627.6377, 2571.634, 3.9577484e-005], [], 0, "CAN_COLLIDE"];
 _unit_10 = _this;
 _this setUnitAbility 0.60000002;
 if (false) then {_group_7 selectLeader _this;};
};

_unit_12 = objNull;
if (true) then
{
 _this = _group_7 createUnit ["UN_CDF_Soldier_EP1", [8624.8496, 2569.9492, 1.7642975e-005], [], 0, "CAN_COLLIDE"];
 _unit_12 = _this;
 _this setDir -83.715508;
 _this setUnitAbility 0.60000002;
 if (false) then {_group_7 selectLeader _this;};
};

_unit_13 = objNull;
if (true) then
{
 _this = _group_6 createUnit ["UN_CDF_Soldier_Officer_EP1", [8595.0264, 2688.5332, -1.7642975e-005], [], 0, "CAN_COLLIDE"];
 _unit_13 = _this;
 _this setUnitAbility 0.60000002;
 if (false) then {_group_6 selectLeader _this;};
};

_unit_14 = objNull;
if (true) then
{
 _this = _group_6 createUnit ["UN_CDF_Soldier_MG_EP1", [8599.4121, 2687.4063, -4.5776367e-005], [], 0, "CAN_COLLIDE"];
 _unit_14 = _this;
 _this setDir 44.90382;
 _this setUnitAbility 0.60000002;
 if (true) then {_group_6 selectLeader _this;};
};

_unit_15 = objNull;
if (true) then
{
 _this = _group_6 createUnit ["UN_CDF_Soldier_AMG_EP1", [8593.7959, 2685.6555, -5.197525e-005], [], 0, "CAN_COLLIDE"];
 _unit_15 = _this;
 _this setDir -156.03745;
 _this setUnitAbility 0.60000002;
 if (false) then {_group_6 selectLeader _this;};
};

_unit_17 = objNull;
if (true) then
{
 _this = _group_6 createUnit ["UN_CDF_Soldier_EP1", [8597.4424, 2683.595, -2.0980835e-005], [], 0, "CAN_COLLIDE"];
 _unit_17 = _this;
 _this setDir 121.56821;
 _this setUnitAbility 0.60000002;
 if (false) then {_group_6 selectLeader _this;};
};

};

That spawns some vehicles and soldiers.

I call it from radio trigger

by

null=execVM "truck.sqf";

Problem is, that the script spawns everithing doubled. for example each car is actually two cars spawned in each other, so if you get in they separate, and you have sudenly two cars beside each other.

Cant find out why.

I will appreciate any idea how to fix it.

Share this post


Link to post
Share on other sites

Could be related to _this conflicting because it is one of the reserved variables, maybe? _this references what was passed into the script during the call/spawn/execvm.

https://community.bistudio.com/wiki/this

Might try replacing it with some other reference and see if that works.

--- edit --

I copied it over into editor on chernarus, and things only spawned things once - is it possible your trigger is running it twice?

I had no other mission stuff, just the script and trigger, so perhaps could still be _this being referenced.

Edited by OpusFmSPol

Share this post


Link to post
Share on other sites

Ok, thx i will try it.

Share this post


Link to post
Share on other sites

OK i tried to replace _this by _prvni in the code for the first truck, and it still spawns it twice.

Share this post


Link to post
Share on other sites

Ok i will try it at friday when i return home from work.

Share this post


Link to post
Share on other sites

The code will run regardless, so why all of the if trues, _veh = _this and _veh = objnull's? Couldn't it just simply be:

if (!isServer) exitWith;

_vehicle_1 = createVehicle ["Ural_UN_EP1", [8618.9258, 2599.2754, -4.2915344e-006], [], 0, "CAN_COLLIDE"];
_vehicle_1 setDir 155.97241;
_vehicle_1 setPos [8618.9258, 2599.2754, -4.2915344e-006];
_vehicle_1 sethit ["wheel_1_1_steering",1];
_vehicle_2 = createVehicle ["Ural_UN_EP1", [8608.3711, 2615.105, -1.5258789e-005], [], 0, "CAN_COLLIDE"];
_vehicle_2 setDir -171.47652;
_vehicle_2 setPos [8608.3711, 2615.105, -1.5258789e-005];
_vehicle_3 = createVehicle ["Ural_UN_EP1", [8602.0576, 2628.5286, -5.9604645e-005], [], 0, "CAN_COLLIDE"];
_vehicle_3 setDir -175.51186;
_vehicle_3 setPos [8602.0576, 2628.5286, -5.9604645e-005];
_vehicle_4 = createVehicle ["Ural_UN_EP1", [8596.2676, 2642.9153, -2.2888184e-005], [], 0, "CAN_COLLIDE"];
_vehicle_4 setDir -189.62248;
_vehicle_4 setPos [8596.2676, 2642.9153, -2.2888184e-005];
_vehicle_6 = createVehicle ["UAZ_Unarmed_UN_EP1", [8593.1455, 2656.0056, 3.8146973e-006], [], 0, "CAN_COLLIDE"];
_vehicle_6 setDir 151.63525;
_vehicle_6 setPos [8593.1455, 2656.0056, 3.8146973e-006];
_vehicle_7  = createVehicle ["UAZ_Unarmed_UN_EP1", [8587.5156, 2662.9124, 1.0490417e-005], [], 0, "CAN_COLLIDE"];
_vehicle_7  setDir 194.97041;
_vehicle_7  setPos [8587.5156, 2662.9124, 1.0490417e-005];
_vehicle_12 = createVehicle ["LadaLM", [8634.1074, 2591.7109, 4.0054321e-005], [], 0, "CAN_COLLIDE"];
_vehicle_12 setDir -8.3406734;
_vehicle_12 setPos [8634.1074, 2591.7109, 4.0054321e-005];

_center_1 = createCenter civilian;
_center_1 setFriend [east, 0];

_group_1 = createGroup _center_1;
_group_3 = createGroup _center_1;
_group_4 = createGroup _center_1;
_group_5 = createGroup _center_1;

_unit_2 = _group_5 createUnit ["Policeman", [8646.4141, 2559.5491, 1.5735626e-005], [], 0, "CAN_COLLIDE"];
_unit_2 setDir 152.46233;
_unit_2 setUnitAbility 0.60000002;
_group_5 selectLeader _unit_2;
_unit_3 = _group_4 createUnit ["Policeman", [8573.2393, 2697.1929, -2.6702881e-005], [], 0, "CAN_COLLIDE"];
_unit_3 setDir -50.373871;
_unit_3 setUnitAbility 0.60000002;
_group_4 selectLeader _unit_3;

_center_2 = createCenter resistance;
_center_2 setFriend [east, 0];

_group_6 = createGroup _center_2;
_group_7 = createGroup _center_2;

_unit_4 = _group_7 createUnit ["UN_CDF_Soldier_Officer_EP1", [8628.3105, 2565.7915, -5.7220459e-005], [], 0, "CAN_COLLIDE"];
_unit_4 setDir 141.05481;
_unit_4 setUnitAbility 0.60000002;
_group_7 selectLeader _unit_4;
_unit_8 = _group_7 createUnit ["UN_CDF_Soldier_MG_EP1", [8628.5488, 2568.9143, 2.0027161e-005], [], 0, "CAN_COLLIDE"];
_unit_8 setDir 66.318787;
_unit_8 setUnitAbility 0.60000002;
_group_7 selectLeader _unit_8;
_unit_10 = _group_7 createUnit ["UN_CDF_Soldier_AMG_EP1", [8627.6377, 2571.634, 3.9577484e-005], [], 0, "CAN_COLLIDE"];
_unit_10 setUnitAbility 0.60000002;
_group_7 selectLeader _unit_10;
_unit_12 = _group_7 createUnit ["UN_CDF_Soldier_EP1", [8624.8496, 2569.9492, 1.7642975e-005], [], 0, "CAN_COLLIDE"];
_unit_12 setDir -83.715508;
_unit_12 setUnitAbility 0.60000002;
_group_7 selectLeader _unit_12;
_unit_13 = _group_6 createUnit ["UN_CDF_Soldier_Officer_EP1", [8595.0264, 2688.5332, -1.7642975e-005], [], 0, "CAN_COLLIDE"];
_unit_13 setUnitAbility 0.60000002;
_group_6 selectLeader _unit_13;
_unit_14 = _group_6 createUnit ["UN_CDF_Soldier_MG_EP1", [8599.4121, 2687.4063, -4.5776367e-005], [], 0, "CAN_COLLIDE"];
_unit_14 setDir 44.90382;
_unit_14 setUnitAbility 0.60000002;
_group_6 selectLeader _unit_14;
_unit_15 = _group_6 createUnit ["UN_CDF_Soldier_AMG_EP1", [8593.7959, 2685.6555, -5.197525e-005], [], 0, "CAN_COLLIDE"];
_unit_15 setDir -156.03745;
_unit_15 setUnitAbility 0.60000002;
_group_6 selectLeader _unit_15;
_unit_17 = _group_6 createUnit ["UN_CDF_Soldier_EP1", [8597.4424, 2683.595, -2.0980835e-005], [], 0, "CAN_COLLIDE"];
_unit_17 setDir 121.56821;
_unit_17 setUnitAbility 0.60000002;
_group_6 selectLeader _unit_17;

Share this post


Link to post
Share on other sites
The code will run regardless, so why all of the if trues, _veh = _this and _veh = objnull's?

Well because i dont typed that code, i placed all of the units and vehicles in 3D editor, and this is output file that arma Generated for me. I just deleted lines of code that i dont need, and added the line:

If (isServer) then {

and the line

_vehicle_1 sethit ["wheel_1_1_steering",1];

to damage the left front wheel of the first truck,

and the } bracket at the end.

typing the code myself, finding out the propper coordinates to place the objects, and then checking it if it is ok would take to long.

In 3D editor you just pick your unit, place it, its3D so you allready see if its placed correctly and you dont have to check it, and then you just save it, then you go to the file with the saved 3d editor mission, change few lines in mission.sqf rename it, save it to the file where you have your 2D editor mission, test it once, and its done most of the times.

This is actualy the first time i have any problem with it.

If i would make the script manualy then i would have to search for the exact coordinates for each object and i would have to testrun the script every time when i place an object to see if its placed correctly, i would have to remember numbers, and i would not see what iam doing untill i run the script, wich sucks.

Edited by Mirek

Share this post


Link to post
Share on other sites

Oh wow, didn't know that the 3D-Editor would actually produce that crappy code markup.... it was a pain in the ass to decipher what was going on.

So I beautified it a little and did test it with Radio-Trigger as well as putting it into the init.sqf and both yielded the same result: No duplicates, everything was normal and working as intended.

// truck.sqf
if (isServer) then
{
_vehicles	= 
[
//	Vehicle-className		3D-Coordinates								direction		Optional: Damage
	["Ural_UN_EP1",			[8618.9258, 2599.2754,	-4.2915344e-006],	155.97241,		["wheel_1_1_steering",1]],
	["Ural_UN_EP1",			[8608.3711, 2615.105,	-1.5258789e-005],	-171.47652],
	["Ural_UN_EP1",			[8602.0576, 2628.5286,	-5.9604645e-005],	-175.51186],
	["Ural_UN_EP1", 		[8596.2676, 2642.9153,	-2.2888184e-005],	-189.62248],
	["UAZ_Unarmed_UN_EP1",	[8593.1455, 2656.0056,	3.8146973e-006],	151.63525],
	["UAZ_Unarmed_UN_EP1",	[8587.5156, 2662.9124,	1.0490417e-005],	194.97041],
	["LadaLM",				[8634.1074, 2591.7109,	4.0054321e-005],	-8.3406734]
];

// Create the vehicles
_vehicleTemp = objNull;
{
	_vehicleTemp	= createVehicle [_x select 0, _x select 1, [], 0, "CAN_COLLIDE"];
	_vehicleTemp	setDir (_x select 2);
	_vehicleTemp	setPos (_x select 1);

	// apply damages if present
	if (count _x > 3) then
	{
		_cnt	= (count _x) - 1;
		for "_i" from 3 to _cnt do
		{
			_vehicleTemp	setHit (_x select _i);
		};
	};

} forEach _vehicles;

_units = 
[
//				Unit-Class						3D-Coordinates								Direction		Leader
	[
		civilian,
		[
			[
				["Policeman",					[8646.4141, 2559.5491, 1.5735626e-005],		152.46233,		true]
			],
			[
				["Policeman", 					[8573.2393, 2697.1929, -2.6702881e-005],	-50.373871,		false]
			]
		]
	],
	[
		resistance,
		[
			[
				["UN_CDF_Soldier_Officer_EP1",	[8628.3105, 2565.7915,	-5.7220459e-005],	141.05481,		true],
				["UN_CDF_Soldier_MG_EP1", 		[8628.5488, 2568.9143,	2.0027161e-005], 	66.318787,		false],
				["UN_CDF_Soldier_AMG_EP1", 		[8627.6377, 2571.634,	3.9577484e-005], 	0,				false],
				["UN_CDF_Soldier_EP1",			[8624.8496, 2569.9492,	1.7642975e-005], 	-83.715508,		false]
			],
			[
				["UN_CDF_Soldier_Officer_EP1",	[8595.0264, 2688.5332,	-1.7642975e-005],	0,				false],
				["UN_CDF_Soldier_MG_EP1",		[8599.4121, 2687.4063,	-4.5776367e-005],	44.90382,		true],
				["UN_CDF_Soldier_AMG_EP1",		[8593.7959, 2685.6555,	-5.197525e-005],	-156.03745,		false],
				["UN_CDF_Soldier_EP1",			[8597.4424, 2683.595,	-2.0980835e-005],	121.56821,		false]
			]
		]
	]
];

// Create the units
_hq		= objNull;
_group	= grpNull;
_unit	= objNull;
{
	_hq	= createCenter (_x select 0);
	_hq	setFriend [east, 0];

	{
		_group	= createGroup _hq;

		{
			_unit	= _group createUnit [_x select 0, _x select 1, [], 0, "CAN_COLLIDE"];
			_unit	setDir (_x select 2);
			_unit	setPos (_x select 1);
			_unit	setUnitAbility 0.60000002;

			if ((_x select 3)) then
			{
				_group selectLeader _unit;
			};

		} forEach _x;

	} forEach (_x select 1);

} forEach _units;
};

Share this post


Link to post
Share on other sites

Wow! thank you guys, thank you very much.

I think i will go with Icemans code, cause i actually understand it all.

Animus code is too Advanced for me. I understand some of it, but most of it i just dont. But thanks anyway.

And yes 3D editor produces this, i also somewhat felt that it is not entirely nice code, but i cant be picky, it is still better than to have to make the code myself, with my heavily limited knowledge of even the basics of coding.

Share this post


Link to post
Share on other sites
I think i will go with Icemans code, cause i actually understand it all.

Your code bud. I just took out all of the un-needed stuff =). Though I could do everything the script does in 4 lines or less with call compile format haha. No need to rewriate anything in any case.

Edited by Iceman77

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  

×