Jump to content

[Outdated] New safezone script and a.i remover from safezone (works with dzai and dzms) (works for 1.0.6.2)


nova

Recommended Posts

This is a new version of a safezone script and an a.i/a.i vehicle remover. To be used in conjunction with the 1061 safezone script. So say your safe zone is being bombarded with roaming a.i and you are tired of going to safe zones to delete them this will do it automatically when you go within 350 meters of an roaming a.i while in a safezone. The distance is customizable. The new safezone script allows you to receive god mode for 20 secs after you leave the safe zone IF you have stayed in the safezone long enough. This will avoid players from touching the safe zone and taking off for a way to avoid combat from other players. All credits go to @juandayz for this. Uploaded with his permission. 

 

1- into mpmission\your instance\scripts\  create a new folder called "safezone"

2-into this folder create this sqf:

safezone_ai_remover.sqf

Spoiler
  1. //SAFEZONES UNITS AND VEHICLES REMOVER FROM SAFEZONES BY NOVA AND JUANDAYZ
  2.  
  3. private ["_playerpos","_ai_to_be_removed","_Safezone_radio","_all_nearest_veh"];
  4.  
  5.  
  6. while {true} do {
  7.  
  8. waitUntil {isInTraderCity};
  9.  
  10. _playerpos = getPos (vehicle player);
  11. _player = player;
  12. _ai_to_be_removed = _playerpos nearEntities ["Man",350];
  13. _Safezone_radio = 350;
  14. _all_nearest_veh = _playerpos nearEntities [["LandVehicle","Helicopter","Plane","Ship"],_Safezone_radio];
  15.  
  16. {
  17. if ((_x in allunits) and !(_x in serverTraders) and !(_x in playableunits))then{
  18.  
  19. _x setdamage 1;
  20. deletevehicle _x;
  21. };
  22.  
  23. } forEach _ai_to_be_removed;
  24.  
  25. {
  26. if (vehicle _x getVariable ["aiveh",0] == 1) then {
  27. if (_player == driver _x) then {
  28. _x setVariable ["aiveh",0];
  29. }else{
  30. deletevehicle _x;
  31. _vehicleID = _x getVariable ["ObjectID", "0"];
  32. _vehicleUID = _x getVariable ["ObjectUID", "0"];
  33. [_vehicleID,_vehicleUID] call server_deleteObj;
  34. PVDZ_obj_Destroy = [_vehicleID,_vehicleUID,_x];
  35. publicVariableServer "PVDZ_obj_Destroy";
  36. };
  37. };
  38. } forEach _all_nearest_veh;
  39.  
  40. uiSleep 5;
  41. };

 

3-open your init.sqf

Spoiler

find :


if (DZE_R3F_WEIGHT) then {execVM "\z\addons\dayz_code\external\R3F_Realism\R3F_Realism_Init.sqf";};

below paste:


// REMOVE AI FROM Safe Zones 
    [] execVM "scripts\safezone\safezone_ai_remover.sqf";

 

4-Now if ure using DZAI:

Spoiler

open DZAI\init\dzai_functions.sqf  then find lines in red and add lines in blue:

DZAI_protectObject = {
    private ["_objectMonitor","_object"];
    _object = _this;
    
    _objectMonitor = missionNamespace getVariable [DZAI_serverObjectMonitor,[]];
    _objectMonitor set [count _objectMonitor,_object];
    DZAI_monitoredObjects set [count DZAI_monitoredObjects,_object];
    _object setVariable ["ObjectID",""];
    _object setVariable ["ObjectUID",""];
  
  _object setvariable ["aiveh",1,true]; 
    true
};

 

5-If ure using DZMS then do the same:

Spoiler

Open DZMS\DZMSFunctions.sqf  then find lines in red and add lines in blue:

DZMSProtectObj = {
    private ["_object","_objectID"];
    _object = _this select 0;
    
    _objectID = str(round(random 999999));
    _object setVariable ["ObjectID", _objectID, true];
    _object setVariable ["ObjectUID", _objectID, true];
    _object setVectorUp surfaceNormal position _object;
 
   _object setvariable ["aiveh",1,true];
    
    if (_object isKindOf "ReammoBox") then {
        // PermaLoot on top of ObjID because that "arma logic"
        _object setVariable ["permaLoot",true];
    };

    if (DZMSEpoch) then {
        PVDZE_serverObjectMonitor set [count PVDZE_serverObjectMonitor, _object];
    } else {
        dayz_serverObjectMonitor set [count dayz_serverObjectMonitor, _object];
    };
    
    if (!((typeOf _object) in ["USVehicleBox","USLaunchersBox","AmmoBoxSmall_556","AmmoBoxSmall_762","MedBox0","USBasicWeaponsBox","USBasicAmmunitionBox","RULaunchersBox"]) || DZMSSceneryDespawnLoot) then {
        _object setVariable["DZMSCleanup",true];
    };
    true
};

 

6-If you are using some kind of other script that spawns enemy ai vehicles then add the same variable.. for example:

Spoiler

Example A:

Spoiler

_carrier =  createVehicle [_plane_class, [(_positionp select 0) + 50, (_positionp select 1) + 50],[], 0, "FLY"];
_carrier         setVehicleVarName "heli";
_carrier         setFuel 1;
_carrier         engineOn true;

{_carrier removeWeapon _x} forEach weapons _carrier;
_carrier addweapon "M230";
_carrier addmagazine "1200Rnd_30x113mm_M789_HEDP";
//_carrier addweapon "M240_veh";
//_carrier addmagazine "1200Rnd_762x51_M240";
_carrier         setVehicleAmmo 1;
_carrier         flyInHeight 150;
_carrier        limitSpeed 60;
_carrier         setVehicleLock "LOCKED";
_carrier         addEventHandler ["GetOut",{(_this select 0) setFuel 0;(_this select 0) setDamage 1;}];
dayz_serverObjectMonitor set [count dayz_serverObjectMonitor,_carrier];

_carrier setvariable ["aiveh",1,true];

Example b:

Spoiler

_vehicle_11 = objNull;
if (true) then
{
  _this = createVehicle ["BAF_Offroad_W", [(_pos select 0) - 4.5, (_pos select 1) - 5,-0.012], [], 0, "CAN_COLLIDE"];
  _vehicle_11 = _this;

dayz_serverObjectMonitor set [count dayz_serverObjectMonitor,_this];
  _this setvariable ["aiveh",1,true];
};

 

7- If you are using WAI, in wai\compile\vehicle_patrol.sqf find:

Spoiler

_vehicle = createVehicle [_veh_class, [(_startingpos select 0),(_startingpos select 1), 0], [], 0, "CAN_COLLIDE"];
_vehicle setFuel 1;
_vehicle engineOn true;
_vehicle setVehicleAmmo 1;
_vehicle addEventHandler ["GetOut",{(_this select 0) setFuel 0;(_this select 0) setDamage 1;}];
_vehicle allowCrewInImmobile true; 
_vehicle lock true;
     
dayz_serverObjectMonitor set [count dayz_serverObjectMonitor,_vehicle];
 

 

add  _vehicle setvariable ["aiveh",1,true];

 

Link to comment
Share on other sites

Replace all lines in safezone_ai_remover.sqf with

Spoiler
  1. //SAFEZONES UNITS AND VEHICLES REMOVER FROM SAFEZONES BY NOVA AND JUANDAYZ
  2.  
  3. private ["_playerpos","_ai_to_be_removed","_Safezone_radio","_all_nearest_veh"];
  4.  
  5.  
  6. while {true} do {
  7.  
  8. waitUntil {isInTraderCity};
  9.  
  10. _playerpos = getPos (vehicle player);
  11. _player = player;
  12. _ai_to_be_removed = _playerpos nearEntities ["Man",350];
  13. _Safezone_radio = 350;
  14. _all_nearest_veh = _playerpos nearEntities [["LandVehicle","Helicopter","Plane","Ship"],_Safezone_radio];
  15.  
  16. {
  17. if ((_x in allunits) and !(_x in serverTraders) and !(_x in playableunits))then{
  18.  
  19. _x setdamage 1;
  20. deletevehicle _x;
  21. };
  22.  
  23. } forEach _ai_to_be_removed;
  24.  
  25. {
  26. if (vehicle _x getVariable ["aiveh",0] == 1) then {
  27. if (_player == driver _x) then {
  28. _x setVariable ["aiveh",0];
  29. }else{
  30. deletevehicle _x;
  31. _vehicleID = _x getVariable ["ObjectID", "0"];
  32. _vehicleUID = _x getVariable ["ObjectUID", "0"];
  33. [_vehicleID,_vehicleUID] call server_deleteObj;
  34. PVDZ_obj_Destroy = [_vehicleID,_vehicleUID,_x];
  35. publicVariableServer "PVDZ_obj_Destroy";
  36. };
  37. };
  38. } forEach _all_nearest_veh;
  39.  
  40. uiSleep 5;
  41. };

this should work for ya. also updated main post with this

Link to comment
Share on other sites

  • 8 months later...
19 hours ago, G2K said:

OP said " To be used in conjunction with the 1061 safezone script".  

Could someone point me in the direction of the mod he is referring to. it's underlined like it should be a hyperlink but it does not work.

Thanks.

It doesn't matter what kind of safezone script you are using because this script uses the positions of the trader zones (with this check waitUntil {isInTraderCity};". You can use any safezone script you want.

Link to comment
Share on other sites

6 hours ago, nova said:

ya works with any safezone script really as @Relentless says

Ok, thanks for the reply. a little off topic but is there a way to use this code so it is not tied to a safe zone but just a 'zone' where if any AI (plus vehicles)go into said zone they will delete?  I'm running a Tavi server and the DZAI vehicle patrols love the big bridge. they go there and have big AI parties on the ends of the bridge, Making it a dangerous place for players.  I currently have 16 patrols and 75% of them hang out at the bridge. so i was thinking if I could make an AI delete zone on either side the bridge then they will respawn and traverse the map.

Either way thinks for your and Relentless's help.

Link to comment
Share on other sites

To be honest, i'm not sure if you can. I haven't worked with arma 2 in a long time now haha. I can suggest maybe try to add in black lists zones for the bridge in the DZAI to see if that works. However if someone knows how then someone can edit this script and share. The more options the better I say. 

Link to comment
Share on other sites

  • 1 year later...

Hi guys,

I'm using this script with 106.2 and although it appears to be working I'm getting an undefined variable showing up in my RPT.

Any idea how I can fix this please?

Here is the RPT snippet:

Error in expression <D", "0"];
[_vehicleID,_vehicleUID] call server_deleteObj;
PVDZ_obj_Destroy = [_v>
  Error position: <server_deleteObj;
PVDZ_obj_Destroy = [_v>
  Error Undefined variable in expression: server_deleteobj
File mpmissions\__CUR_MP.Panthera2\scripts\safezone\safezone_ai_remover.sqf, line 33

 

Link to comment
Share on other sites

That I can't be too sure of :/ I haven't touched arma for so long I have forgotten. However does it spam the rpt over and over? If not and if it still works then I wouldn't worry about it too much. But if it becomes a problem then perhaps someone else knows a fix for it. If so i'll add it to the main post.

Link to comment
Share on other sites

  • 3 weeks later...
On 5/8/2020 at 1:15 AM, nova said:

That I can't be too sure of :/ I haven't touched arma for so long I have forgotten. However does it spam the rpt over and over? If not and if it still works then I wouldn't worry about it too much. But if it becomes a problem then perhaps someone else knows a fix for it. If so i'll add it to the main post.

I haven't yet solved the problem but I will eventually. It's no big deal really and doesn't spam the RPT but I'd prefer a nice clean RPT log. I might even try and remove or divert the AI in some other way using blacklisting or something. Thanks for taking the time to answer though, much appreciated! 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Discord

×
×
  • Create New...