Jump to content
Sign in to follow this  
BEAKSBY

Problem with my "if" conditions logic...please help me solve

Recommended Posts

HI folks,

I using two addEventHandler "Killed", the first for only empty vehicles and vehicles with crew inside, and the second for only soliers (outside of vehicles).

I cant't figure out why only the second addEventHandler "Killed" is firing even when a vehicle with crew is destroyed. When I hide the second addEventHandler "Killed" with comments the first one works fine, but obviously the soldiers outside portion will not fire.

here's the "if" conditions for the first for only empty vehicles and vehicles with crew inside:

if ((side group _killer != side group _unit) && (side _killer != sideEnemy) && (typeOf vehicle _unit isKindOf "LandVehicle") ) then {

here's the "if" conditions for only soliers (outside of vehicles):

if ((side group _killer != side group _unit) && (side _killer != sideEnemy) && (vehicle _unit == _unit) && (typeOf vehicle _unit isKindOf "Man")) then {money = 12.5};

Here's my entire initServer.sqf

{  
  //--- Add killed EH to unit FOR VEHICLES AND UNITS IN VEHICLES
  _handle = _x addEventHandler [ "Killed", { 

   _unit = _this select 0; 
   _killer = _this select 1; 
   _handle = _unit getVariable [ "DNA_EH_Killed_Money", -1 ]; 
    money=0;	 

      	if ((side group _killer != side group _unit) && (side _killer != sideEnemy) && (typeOf vehicle _unit isKindOf "LandVehicle") ) then {   //--- Check if opposite side is killed by _killer && _Killer is not an renegade 
     		//if (typeOf vehicle _unit isKindOf "LandVehicle") then {  //---condition of vehicles only
hint "vehicle or vehicle with soldiers inside killed";

       }; 
   } ]; 
   //--- Store killed EH handle in unit namespace 
   _x setVariable [ "DNA_EH_Killed_Money", _handle ]; 

}  forEach vehicles;  // THIS WORKS  

{  
   //--- Add killed EH to unit FOR UNITS ONLY (NOT IN VEHICLES)
   _handle = _x addEventHandler [ "Killed", { 

       _unit = _this select 0; 
       _killer = _this select 1; 
       _handle = _unit getVariable [ "DNA_EH_Killed_Money", -1 ]; 
	money=0;	

      	//--- Check if opposite side is killed by _killer  && _Killer is not an renegade && "_unit is NOT in a vehicle" (vehicle _unit == _unit) 
   	if ((side group _killer != side group _unit) && (side _killer != sideEnemy) && (vehicle _unit == _unit) && (typeOf vehicle _unit isKindOf "Man")) then {
hint "soldier killed";
money =12.5};
   } ]; 
   //--- Store killed EH handle in unit namespace 
   _x setVariable [ "DNA_EH_Killed_Money", _handle ]; 

}  forEach allUnits; // THIS WORKS  

Edited by BEAKSBY

Share this post


Link to post
Share on other sites

if ((side group _killer != side group _unit) && (side _killer != sideEnemy) && (_unit isKindOf "Man") ) then { for man}else {for vehicle};

Share this post


Link to post
Share on other sites
if ((side group _killer != side group _unit) && (side _killer != sideEnemy) && (_unit isKindOf "Man") ) then { for man}else {for vehicle};

Thanks Mariodu62,

I just tried as you suggested above but also does not work since the hint returns soldier killed, whether a vehicle, vehicle with soldiers inside or soldier is killed...

{  
  //--- Add killed EH to unit FOR VEHICLES AND UNITS IN VEHICLES
  _handle = _x addEventHandler [ "Killed", { 

   _unit = _this select 0; 
   _killer = _this select 1; 
   _handle = _unit getVariable [ "DNA_EH_Killed_Money", -1 ]; 
    money=0;	 

	if ((side group _killer != side group _unit) && (side _killer != sideEnemy) && (_unit isKindOf "Man") ) then {
	hint "soldier killed";

	} else {
	hint "vehicle or vehicle with soldiers inside killed";

      	// if ((side group _killer != side group _unit) && (side _killer != sideEnemy) && (typeOf vehicle _unit isKindOf "LandVehicle") ) then {   //--- Check if opposite side is killed by _killer && _Killer is not an renegade 
     		//if (typeOf vehicle _unit isKindOf "LandVehicle") then {  //---condition of vehicles only


       }; 
   } ]; 
   //--- Store killed EH handle in unit namespace 
   _x setVariable [ "DNA_EH_Killed_Money", _handle ]; 

}  forEach vehicles + allUnits;  // THIS WORKS  

---------- Post added at 16:00 ---------- Previous post was at 15:03 ----------

Problem solved with this:

{  
  //--- Add killed EH to unit FOR VEHICLES AND UNITS IN VEHICLES
  _handle = _x addEventHandler [ "Killed", { 

   _unit = _this select 0; 
   _killer = _this select 1; 
   _handle = _unit getVariable [ "DNA_EH_Killed_Money", -1 ]; 
    money=0;	 

      	if ((side group _killer != side group _unit) && (side _killer != sideEnemy) && (typeOf vehicle _unit isKindOf "LandVehicle") ) then {   //--- Check if opposite side is killed by _killer && _Killer is not an renegade 
     		//if (typeOf vehicle _unit isKindOf "LandVehicle") then {  //---condition of vehicles only
	//hint "vehicle or vehicle with soldiers inside killed";

{
__x =_x;    
{
if (( typeof _x) in __x ) then {money = money + (__x select 0)/2};    
} foreach crew _unit + [_unit]; 
} foreach veh; 

_vehicle = getText (configFile >> "cfgVehicles" >> typeof _unit >> "displayname");                     
_picture = getText (configFile >> "cfgVehicles" >> typeof _unit  >> "picture");

	//}; 
        //--- Add money to the client 
	[ [money, _unit, _picture, _vehicle, count crew _unit], "DNA_fnc_addMoney", side group _killer ] call BIS_fnc_MP;                 
/**/
       }; 
   } ]; 
   //--- Store killed EH handle in unit namespace 
   _x setVariable [ "DNA_EH_Killed_Money", _handle ]; 

}  forEach vehicles;  // THIS WORKS  

{  
   //--- Add killed EH to unit FOR UNITS ONLY (NOT IN VEHICLES)
   _handle = _x addEventHandler [ "Killed", { 

       _unit = _this select 0; 
       _killer = _this select 1; 
       _handle = _unit getVariable [ "DNA_EH_Killed_Money", -1 ]; 
	money=0;	

      	//--- Check if opposite side is killed by _killer  && _Killer is not an renegade && "_unit is NOT in a vehicle" (vehicle _unit == _unit) 
   	if ((side group _killer != side group _unit) && (side _killer != sideEnemy) && (vehicle _unit == _unit) && (typeOf vehicle _unit isKindOf "Man")) then {;
	money = 12.5;
	// hint "soldier killed";


	_vehicle = getText (configFile >> "cfgVehicles" >> typeof _unit >> "displayname");       
[ [money, _unit, _picture, _vehicle, count crew _unit], "DNA_fnc_addMoney", side group _killer ] call BIS_fnc_MP;          
/**/};	
   } ]; 
   //--- Store killed EH handle in unit namespace 
   _x setVariable [ "DNA_EH_Killed_Money", _handle ]; 

}  forEach allUnits; // THIS WORKS  

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  

×