look into event handler "HandleDamage" and "inArea" command
using the "HandleDamage" event handler by returning a false or is it true?, you can disable damage, and you set the logics like when the player enters the area and in 10 seconds the player's damage gets disabled, you can use setVariables to achieve this
player addEventHandler ["HandleDamage",{
_player =_this select 0;
_yourPos = getMarkerPos "test";
_r = false;
// look into 'inArea ' command instead: https://community.bistudio.com/wiki/inArea
// this is for a test compares the distance between player and a marker named 'test'
if (_player distance _yourPos <= 250) then {
_r = false; // if your character is taking damage when close to the marker, try setting this to true and the below one to false, I kinda forgot whether its true/false to disable damage
} else {
_r = true;
};
_r
}];
I have a custom function setup in my scenario which:
Spawns in an IFV
Spawns a group to crew it
Spawns a group to ride in the back
Tells both groups to drive to a marker and eject the infantry
Tells both groups to attack an area with BIS_fnc_taskAttack
It works as expected, in fact, quite well.
There's just 1 problem - every 2nd time I spawn this function, the infantry in the back dismount as soon as they spawn in and hoof it all the way to the marker. I've tested multiple times and it's consistent. For example, if I spawn this function 8 times, the 1st, 3rd, 5th, and 7th time will work perfectly and the 2nd, 4th, 6th, and 8th will dismount the infantry as soon as they spawn. This occurs in both a singleplayer and multiplayer (LAN) environment. It's too consistent to be a random error - it's clearly something I've missed in how my function is set up but I've had no luck finding a lead for about 5 days now.
Here's the function (it is defined within cfgfunctions.hpp and works without spitting out errors when I spawn it):
if !(isServer) exitWith {};
_unitClass = "Unknown";
//DEFINE GROUPS
_bIfvGroup = ["B_crew_F","B_crew_F"];
_bIfvInfGroup = ["B_soldier_F","B_soldier_F","B_Patrol_Soldier_MG_F","B_engineer_F","B_soldier_F","B_recon_F"];
//SPAWN IFV
_bNewVehicleIfv = createVehicle ["B_APC_Wheeled_01_cannon_F", [27635,23853,0], [], 0, "NONE"];
_bNewVehicleIfv setDir 227;
_bNewVehicleIfv lockturret [[0,0],true];
clearWeaponCargoGlobal _bNewVehicleIfv;
clearMagazineCargoGlobal _bNewVehicleIfv;
clearBackpackCargoGlobal _bNewVehicleIfv;
clearItemCargoGlobal _bNewVehicleIfv;
//SPAWN IFV CREW
newBluforIfvCrew = createGroup [west,true];
{
_newBluforCrewUnit = _x createUnit [getMarkerPos "bAiSpawn02",newBluforIfvCrew,"newBluforCrewUnit=this"];
{
[newBluforCrewUnit] call LIZ_fnc_bCrewLoadout;
if alive driver _bNewVehicleIfv then {newBluforCrewUnit moveInGunner _bNewVehicleIfv;} else {newBluforCrewUnit moveInDriver _bNewVehicleIfv;};
newBluforCrewUnit disableAI "FSM";
newBluforCrewUnit allowFleeing 0;
newBluforIfvCrew setSpeedMode "FULL";
} foreach units (newBluforIfvCrew);
} foreach _bIfvGroup;
_bNewVehicleIfv lockDriver true;
sleep 2;
//SPAWN IFV INFANTRY
newBluforIfvInfGroup = createGroup [west,true];
{
_newBluforMechUnit = _x createUnit [getMarkerPos "bAiSpawn02",newBluforIfvInfGroup,"newBluforMechUnit=this"];
{
if (typeOf newBluforMechUnit == "B_soldier_F") then {_unitClass = "Rifleman";};
if (typeOf newBluforMechUnit == "B_Patrol_Soldier_MG_F") then {_unitClass = "MG";};
if (typeOf newBluforMechUnit == "B_engineer_F") then {_unitClass = "AT";};
if (typeOf newBluforMechUnit == "B_recon_F") then {_unitClass = "Recon";};
switch (_unitClass) do {
case "Rifleman":
{
[newBluforMechUnit] spawn LIZ_fnc_bRifleLoadout;
};
case "MG":
{
[newBluforMechUnit] spawn LIZ_fnc_bMgLoadout;
};
case "AT":
{
[newBluforMechUnit] spawn LIZ_fnc_bAtLoadout;
};
case "Recon":
{
[newBluforMechUnit] spawn LIZ_fnc_bReconLoadout;
};
};
newBluforMechUnit moveInCargo _bNewVehicleIfv;
newBluforIfvInfGroup setSpeedMode "FULL";
} foreach units (newBluforIfvInfGroup);
} foreach _bIfvInfGroup;
sleep 1;
//RANDOM OBJECTIVE MARKER
_randomDismountMarker = ["dismountMarker01","dismountMarker02","dismountMarker03","dismountMarker04"] call BIS_fnc_selectRandom;
_randomObjMarker = ["combatMarker01","combatMarker02","combatMarker03"] call BIS_fnc_selectRandom;
//SEND ORDERS FOR IFV CREW
_wp1 = newBluforIfvCrew addWaypoint [getMarkerPos _randomDismountMarker, 0];
_wp1 setWaypointType "TR UNLOAD";
_wp1 setWaypointSpeed "FULL";
//SEND ORDERS FOR INFANTRY GROUP
_wp2 = newBluforIfvInfGroup addWaypoint [getMarkerPos _randomDismountMarker, 0];
_wp2 setWaypointType "GETOUT";
newBluforIfvInfGroup setBehaviourStrong "AWARE";
newBluforIfvInfGroup setSpeedMode "FULL";
[newBluforIfvCrew, 0] synchronizeWaypoint [ [newBluforIfvInfGroup, 0] ];
//IFV LEAVES INFANTRY ATTACKS
waitUntil {({_x in _bNewVehicleIfv} count (units newBluforIfvInfGroup)) < 6};
[newBluforIfvInfGroup] spawn LIZ_fnc_eject;
waitUntil {({_x in _bNewVehicleIfv} count (units newBluforIfvInfGroup)) < 1};
sleep 2;
[newBluforIfvInfGroup, getMarkerPos _randomObjMarker] call BIS_fnc_taskAttack;
[newBluforIfvCrew, getMarkerPos _randomObjMarker] call BIS_fnc_taskAttack;
Currently this function is triggered by me using a Radio Trigger for testing - 0 = [] spawn LIZ_fnc_bIfvSpawn. I also considered that my other function LIZ_fnc_eject (which ejects the infantry from the IFV) might have something to do with it, so here it is:
_infantry = _this select 0;
{
unassignVehicle (_x);
(_x) action ["EJECT", vehicle _x];
sleep 0.2;
} foreach units (_infantry);
sleep 3;
If you can see my error, or if I've unwittingly left out some key piece of information, please let me know.