Jump to content

Recommended Posts

I am trying to implement a safezone.

Rules of safezone:
Players who spawn inside safezone are invulnerable until they leave the safezone trigger. If they return there is a 10 second delay before they are invincible again.

I managed to get that part working. 

 

// Create trigger centered on the safezone marker for vehicles
_safezoneTriggerVehicle = createTrigger ["EmptyDetector", getPos _logic];
_triggerSize = [(_markerSize select 0), (_markerSize select 1), 0, false, 100];
_safezoneTriggerVehicle setTriggerArea _triggerSize;
_safezoneTriggerVehicle setTriggerActivation ["ANY", "PRESENT", true];

_safezoneTriggerVehicle setTriggerStatements [
    "this && {count (thisList select {alive _x && (_x isKindOf 'LandVehicle' || _x isKindOf 'Air')}) > 0}",
    "
    {
        if (_x isKindOf 'LandVehicle' || _x isKindOf 'Air') then {
            _x allowDamage false;
            hint format ['%1 is now invulnerable', _x];
        };
    } forEach (thisList select {alive _x && (_x isKindOf 'LandVehicle' || _x isKindOf 'Air')});
    ",
    "
    {
        if (_x isKindOf 'LandVehicle' || _x isKindOf 'Air') then {
            _x allowDamage true;
            hint format ['%1 is now vulnerable', _x];
        };
    } forEach (thisList select {alive _x && (_x isKindOf 'LandVehicle' || _x isKindOf 'Air')});
    "
];


However, I also need this to apply to players who get in vehicles, any vehicles spawned by the player (not yet implemented), as well as any vehicle being driven by a player. I've tried the following, but the vehicle and player don't become invincible again after reentering the trigger:
 

// Create trigger centered on the safezone marker for vehicles
_safezoneTriggerVehicle = createTrigger ["EmptyDetector", getPos _logic];
_triggerSize = [(_markerSize select 0), (_markerSize select 1), 0, false, 100];
_safezoneTriggerVehicle setTriggerArea _triggerSize;
_safezoneTriggerVehicle setTriggerActivation ["ANY", "PRESENT", true];

_safezoneTriggerVehicle setTriggerStatements [
    "this && {count (thisList select {alive _x && (_x isKindOf 'LandVehicle' || _x isKindOf 'Air')}) > 0}",
    "
    {
        if (_x isKindOf 'LandVehicle' || _x isKindOf 'Air') then {
            _x allowDamage false;
            hint format ['%1 is now invulnerable', _x];
        };
    } forEach (thisList select {alive _x && (_x isKindOf 'LandVehicle' || _x isKindOf 'Air')});
    ",
    "
    {
        if (_x isKindOf 'LandVehicle' || _x isKindOf 'Air') then {
            _x allowDamage true;
            hint format ['%1 is now vulnerable', _x];
        };
    } forEach (thisList select {alive _x && (_x isKindOf 'LandVehicle' || _x isKindOf 'Air')});
    "
];


 I assume its something to do with the changing state of the player on the vehicle, but am not sure. I have combed through forums over the last 2 days, and all I find are old, generally outdated examples. Same with youtube. Any guidance would be appreicated:
full script:

https://pastebin.com/AExnxN2h

Share this post


Link to post
Share on other sites

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
}];

 

  • Like 1

Share this post


Link to post
Share on other sites

Hey, I've had a ponder on this. I'm not very knowledgeable with arma scripting so take this with a grain of salt

 

_Safezones = ["Safezone_1"];

_SafezoneSafety =
{
	 private ["_Unit"];
	 _Unit = _this select 0;
     _Unit allowdamage false;
	 vehicle _Unit allowDamage false;
};

_SafezoneUnSafety =
{
	 private ["_Unit"];
	 _Unit = _this select 0;
     _Unit allowdamage true;
	 vehicle _Unit allowDamage true;
};

while {true} do
{
    {
	 private _unit = _x;
		{
			if (_unit inarea _x) then
			{
			 [_unit] spawn _SafezoneSafety;
			} else
			{
			 [_unit] spawn _SafezoneUnSafety;
			};
		} forEach _Safezones;
	} forEach allplayers;
	 sleep 1;
};

I've briefly tested the script and it works (at least in single player should hopefully work in multiplayer too?)

 

In essence you put down a marker called Safezone_1 and add it into the safezones array. Then the loop will check if any players are in the marker and spawn the safezone safety function to make them invulnerable. If the player is in a vehicle then it will make the vehicle invulnerable too. You can add more markers to the array as well.

 

This code may be subject to exploits and will need some indepth testing and tweaking however I think this covers the bare bones.

 

I'm not sure how to make it so that newly spawned players into the safe zone will be invulnerable without making the loop redundant.

 

Could adapt this for use in a trigger however I prefer scripts.

 

I've tried to add in hints however can't figure out how to do it without the hint popping up constantly. Could put down a trigger that displays a hint when entering and exiting the marker?

 

I hope this helps 

  • Like 2

Share this post


Link to post
Share on other sites
On 5/17/2024 at 5:24 AM, II OMEGA101 II said:

Hey, I've had a ponder on this. I'm not very knowledgeable with arma scripting so take this with a grain of salt

 


_Safezones = ["Safezone_1"];

_SafezoneSafety =
{
	 private ["_Unit"];
	 _Unit = _this select 0;
     _Unit allowdamage false;
	 vehicle _Unit allowDamage false;
};

_SafezoneUnSafety =
{
	 private ["_Unit"];
	 _Unit = _this select 0;
     _Unit allowdamage true;
	 vehicle _Unit allowDamage true;
};

while {true} do
{
    {
	 private _unit = _x;
		{
			if (_unit inarea _x) then
			{
			 [_unit] spawn _SafezoneSafety;
			} else
			{
			 [_unit] spawn _SafezoneUnSafety;
			};
		} forEach _Safezones;
	} forEach allplayers;
	 sleep 1;
};

I've briefly tested the script and it works (at least in single player should hopefully work in multiplayer too?)

 

In essence you put down a marker called Safezone_1 and add it into the safezones array. Then the loop will check if any players are in the marker and spawn the safezone safety function to make them invulnerable. If the player is in a vehicle then it will make the vehicle invulnerable too. You can add more markers to the array as well.

 

This code may be subject to exploits and will need some indepth testing and tweaking however I think this covers the bare bones.

 

I'm not sure how to make it so that newly spawned players into the safe zone will be invulnerable without making the loop redundant.

 

Could adapt this for use in a trigger however I prefer scripts.

 

I've tried to add in hints however can't figure out how to do it without the hint popping up constantly. Could put down a trigger that displays a hint when entering and exiting the marker?

 

I hope this helps 

Thanks for the suggestion!

I suppose a marker would be more efficient than a trigger. This should be fairly easy to start with, I'm trying to iterate as I go. Not sure if I will have the same issue I had with the trigger, if so I will report back. The issue was that the player exiting a vehicle within the trigger caused them to be vulnerable for 10 seconds. The vehicle would not remain invulnerable. 
 

Share this post


Link to post
Share on other sites

The loop checks every second if there is any player inside the safe zone. The player's vehicle will be protected if the player is in it however if the player isn't in it then it can be destroyed in the safe zone.

 

The other limitations with this as well is that the vehicle will stay invulnerable (if a player was in it when the loop fired) if driven outside the safe zone when there is no player in it however if the player gets back in the vehicle outside a safe zone it will become vulnerable again. Using markers makes some things harder as well as easier unfortunately.

 

 

  • Like 1

Share this post


Link to post
Share on other sites
On 5/18/2024 at 3:55 AM, II OMEGA101 II said:

The loop checks every second if there is any player inside the safe zone. The player's vehicle will be protected if the player is in it however if the player isn't in it then it can be destroyed in the safe zone.

 

The other limitations with this as well is that the vehicle will stay invulnerable (if a player was in it when the loop fired) if driven outside the safe zone when there is no player in it however if the player gets back in the vehicle outside a safe zone it will become vulnerable again. Using markers makes some things harder as well as easier unfortunately.

 

 

I wound up going with a trigger in the end but I utilized parts of your approach. Still needs some more rigorous testing, but I think this might work:

https://pastebin.com/knHsGNJs

Wound up adding some functionality to kill enemy players.

 

            else 
            {    
                if (_entity == player) then { _entity commandChat "You've entered an enemy safezone."; };
                if (_entity isKindOf "man") then {_entity call BIS_fnc_neutralizeUnit;};
                if (count (crew _vehicle) > 0) then
                {
                    _vehicle call BIS_fnc_neutralizeUnit;
                };
            };
        } forEach _new_safezone;

 

  • Like 1

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

×