Jump to content
Sign in to follow this  
bardosy

if/else obj== problem

Recommended Posts

I created this script for a base defend. (Base have to be defended by players, but these script help them a little).

It create a solder if they are less then five and if a machinegunner post is empty they get in, but if all occupied, they just defend the base. But many else state never run and I don't know why. Please take look at it and if you find the problem (or you have a suggestion) tell me.

if (!isServer) exitWith{};


vedok=[];
_nextspawn=1;
while {true} do {
if ({alive _x} count vedok < 5) then {
	_group = createGroup West;
	_creapos = bspawn1;
	if (_nextspawn==1) then {
		_creapos = bspawn1;
	};
	if (_nextspawn==2) then {
		_creapos = bspawn2;
	};
	_unit = _group createUnit ["BAF_Soldier_GL_MTP",_creapos, [], 0, "NONE"];
	_unit setCombatMode "RED";
	_unit setBehaviour "AWARE";
	_unit setRank "SERGEANT";
	_unit setskill 0.7;
	_unit setDir getDir _creapos;
	vedok = vedok + [_unit];

	_machinegun = britbase5; //it's a sendbag, but earlier I used objNull, but I found objNull never equal with itself
	_machinegunstr = "";
	if (count(crew bmg1)==0) then {
		_machinegun = bmg1;
		_machinegunstr = "northern";
	} else {
		if (count(crew bmg2)==0) then {
			_machinegun = bmg2;
			_machinegunstr = "southern";
		} else {
			if (count(crew bmg3)==0) then {
				_machinegun = bmg3;
				_machinegunstr = "eastern";
			};
		};
	};
	if (_machinegun == britbase5) then {
                       //this state never run (even if there is no empty machine gun). Can you tell me why?
		_wp = _group addWaypoint [getPos britbase5, 20];
		_wp showWaypoint "NEVER";
		_wp setWaypointSpeed "NORMAL";
		_wp setWaypointFormation "DIAMOND";
		_wp setWaypointType "SAD";
		_unit sideChat "I start the fight with enemy!";
	} else {
                       // it works fine
		_unit assignAsGunner _machinegun;
		[_unit] orderGetIn true;
		_unit sideChat format["I handle %1 machinegun!",_machinegunstr];
	};

	_nextspawn=_nextspawn+1;

} else {
	_bmg1crew = crew bmg1;
	_bmg2crew = crew bmg2;
	_bmg3crew = crew bmg3;
	{
		if (!(_x in _bmg1crew) and !(_x in _bmg2crew) and !(_x in _bmg3crew)) then {
			_machinegun = britbase5;
			if (count(crew bmg1)==0) then {
				_machinegun = bmg1;
				_machinegunstr = "northern";
			} else {
				if (count(crew bmg2)==0) then {
					_machinegun = bmg2;
					_machinegunstr = "southern";
				} else {
					if (count(crew bmg3)==0) then {
						_machinegun = bmg3;
						_machinegunstr = "eastern";
					};
				};
			};
			if (_machinegun != britbase5) then {
                                       //this state also never run (even if there are empty mg post and there are jobless solders) Can you tell me why?
				_x assignAsGunner _machinegun;
				[_x] orderGetIn true;
				_unit sideChat format["Leave it to me! I will get in %1 machinegun!",_machinegunstr];
			};
		};
	} forEach vedok;
};

if ({!alive _x} count vedok > 5) then {
	{
		if (!alive _x) then {
			vedok = vedok-[_x];
			deleteVehicle _x;
		};
		sleep 1;
	} forEach vedok;
};


if (_nextspawn==3) then {_nextspawn=1;};
sleep 40;
};

Share this post


Link to post
Share on other sites

Seems to work here or as much as I can understand it.

Even this bit where I placed a hint , the unit spawns and performs the SAD when all guns are manned.

if (_machinegun == britbase5) then {

hint "debug";

//this state never run (even if there is no empty machine gun). Can you tell me why?

Set up was as follows

3x m2 guns named bmg2,bmg2,bmg3

2 spawn game points (game logics named bspawn1,bspawn2)

1 sand bag fence named britbase5

When run I get 1 unit every 40 seconds, they mount each gun until all are full and then the next unit that spawns runs around.

Here's my working version and another version just using the editor and a couple of lines of code in a trigger and init box although will only work on static gun.

https://www.dropbox.com/s/xm0sdbcefcyomog/move_into_gun.utes.7z

Edited by F2k Sel

Share this post


Link to post
Share on other sites

Isn't _machinegun only defined locally so it can't be used outside the script?

//Edit ok what I meant is that _machinegun is defined within a scope, not outside, so it shouldn't be useable? ;o

Edited by tryteyker

Share this post


Link to post
Share on other sites

F2k sel, you are right! It works! Sorry for the problem, i just spent tooo much time to debug this script with original version, when I used objNull instead of britbase5. And objNull didnt work. But when i changed it to britbase5 it somehow didnt reload the script in the mission and when i tried, it didmnt work, just like with objNull. But now (a few days later) I tried it again, and now it works! Thanks for the help!

Tryteyker, thank you too! _machinegun is local and never used anywhere else in the mission.

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  

×