Need help with Anti Vehicle script..

titan

New Member
i been trying to write a script that deletes vehicles in the trader zones in epoch when the server restarts.
originally i had the idea to teliport the vehicles to random locations on the map but that is beyond my skill level at the moment.
Code:
waitUntil {!isNil "dayz_animalCheck"};
sleep 10;

private["_VehicleList"];

if (isServer) then
{
_VehicleList = nearestObjects [[6311.915, 7775.5518],["AH6X_DZ","AN2_DZ","ArmoredSUV_PMC_DZE","ATV_CZ_EP1","ATV_US_EP1","C130J_US_EP1","car_hatchback","car_sedan","CH_47F_EP1_DZE","CSJ_GyroC","CSJ_GyroCover","CSJ_GyroP","datsun1_civil_1_open","datsun1_civil_2_covered","datsun1_civil_3_open","Fishing_Boat","GAZ_Vodnik_DZE","GAZ_Vodnik_MedEvac","GLT_M300_LT","GLT_M300_ST","GNT_C185","GNT_C185C","GNT_C185R","GNT_C185U","hilux1_civil_1_open","hilux1_civil_2_covered","hilux1_civil_3_open_EP1","HMMWV_Ambulance","HMMWV_Ambulance_CZ_DES_EP1","HMMWV_DES_EP1","HMMWV_DZ","HMMWV_M1035_DES_EP1","HMMWV_M1151_M2_CZ_DES_EP1_DZE","HMMWV_M998A2_SOV_DES_EP1_DZE","Ikarus","Ikarus_TK_CIV_EP1","JetSkiYanahui_Case_Blue","JetSkiYanahui_Case_Green","JetSkiYanahui_Case_Red","JetSkiYanahui_Case_Yellow","Kamaz","KamazRefuel_DZ","Lada1","Lada1_TK_CIV_EP1","Lada2","Lada2_TK_CIV_EP1","LadaLM","LandRover_CZ_EP1","LandRover_MG_TK_EP1_DZE","LandRover_Special_CZ_EP1_DZE","LandRover_TK_CIV_EP1","M1030_US_DES_EP1","MH6J_DZ","Mi17_Civilian_DZ","Mi17_DZE","MMT_Civ","MtvrRefuel_DES_EP1_DZ","MTVR_DES_EP1","MV22_DZ","Offroad_DSHKM_Gue_DZE","Old_bike_TK_INS_EP1","Old_moto_TK_Civ_EP1","PBX","Pickup_PK_GUE_DZE","Pickup_PK_INS_DZE","Pickup_PK_TK_GUE_EP1_DZE","RHIB","S1203_ambulance_EP1","S1203_TK_CIV_EP1","Skoda","SkodaBlue","SkodaGreen","SkodaRed","Smallboat_1","Smallboat_2","SUV_Blue","SUV_Camo","SUV_Charcoal","SUV_Green","SUV_Orange","SUV_Pink","SUV_Red","SUV_Silver","SUV_TK_CIV_EP1","SUV_White","SUV_Yellow","tractor","TT650_Civ","TT650_Ins","TT650_TK_CIV_EP1","UAZ_CDF","UAZ_INS","UAZ_MG_TK_EP1_DZE","UAZ_RU","UAZ_Unarmed_TK_CIV_EP1","UAZ_Unarmed_TK_EP1","UAZ_Unarmed_UN_EP1","UH1H_DZE","UH1Y_DZE","UH60M_EP1_DZE","UralRefuel_TK_EP1_DZ","Ural_CDF","Ural_TK_CIV_EP1","Ural_UN_EP1","V3S_Open_TK_CIV_EP1","V3S_Open_TK_EP1","V3S_Refuel_TK_GUE_EP1_DZ","VolhaLimo_TK_CIV_EP1","Volha_1_TK_CIV_EP1","Volha_2_TK_CIV_EP1","VWGolf","Zodiac"], 75];  
VehCount = count _VehicleList;
i = 0;
for "i" from 0 to VehCount do
    {
        v = _VehicleList select i;
        v setDamage 1;
    };
};
titleText ["Deleted All Vehicles within 75 meters of Trader Zones!.", "PLAIN"];titleFadeOut 5;
diag_log ("ANTI-VEH INIT");

i put this in a .sqf, and add entry into the init.sqf and it runs ok but no vehicles are destroyed.
i have also tried deleting them rather than destroying them.

it works fine without the if (isServer) but executes every time a player joins!
 
Last edited:
What if you try running it from server_functions.sqf before the server starts to stream the objects from the database?
 
hi. thanks for responding but did that but still no joy. i suppose the have to have spawned on the map first. i was thinking of using a publicVariable - addpublicVariableEventHandler
to tell the other clients not to run it as it has already run. but as i am still learning . anyway this is my latest code..
Code:
waitUntil {!isNil "dayz_animalCheck"};

publicVariable "delVehicle";
delVehicle = 0;

while {delVehicle == 0} do {

private["_VehicleList"];

_VehicleList = nearestObjects [[6331.0352, 7802.3911],["AH6X_DZ","AN2_DZ","ArmoredSUV_PMC_DZE","ATV_CZ_EP1","ATV_US_EP1","C130J_US_EP1","car_hatchback","car_sedan","CH_47F_EP1_DZE","CSJ_GyroC","CSJ_GyroCover","CSJ_GyroP","datsun1_civil_1_open","datsun1_civil_2_covered","datsun1_civil_3_open","Fishing_Boat","GAZ_Vodnik_DZE","GAZ_Vodnik_MedEvac","GLT_M300_LT","GLT_M300_ST","GNT_C185","GNT_C185C","GNT_C185R","GNT_C185U","hilux1_civil_1_open","hilux1_civil_2_covered","hilux1_civil_3_open_EP1","HMMWV_Ambulance","HMMWV_Ambulance_CZ_DES_EP1","HMMWV_DES_EP1","HMMWV_DZ","HMMWV_M1035_DES_EP1","HMMWV_M1151_M2_CZ_DES_EP1_DZE","HMMWV_M998A2_SOV_DES_EP1_DZE","Ikarus","Ikarus_TK_CIV_EP1","JetSkiYanahui_Case_Blue","JetSkiYanahui_Case_Green","JetSkiYanahui_Case_Red","JetSkiYanahui_Case_Yellow","Kamaz","KamazRefuel_DZ","Lada1","Lada1_TK_CIV_EP1","Lada2","Lada2_TK_CIV_EP1","LadaLM","LandRover_CZ_EP1","LandRover_MG_TK_EP1_DZE","LandRover_Special_CZ_EP1_DZE","LandRover_TK_CIV_EP1","M1030_US_DES_EP1","MH6J_DZ","Mi17_Civilian_DZ","Mi17_DZE","MMT_Civ","MtvrRefuel_DES_EP1_DZ","MTVR_DES_EP1","MV22_DZ","Offroad_DSHKM_Gue_DZE","Old_bike_TK_INS_EP1","Old_moto_TK_Civ_EP1","PBX","Pickup_PK_GUE_DZE","Pickup_PK_INS_DZE","Pickup_PK_TK_GUE_EP1_DZE","RHIB","S1203_ambulance_EP1","S1203_TK_CIV_EP1","Skoda","SkodaBlue","SkodaGreen","SkodaRed","Smallboat_1","Smallboat_2","SUV_Blue","SUV_Camo","SUV_Charcoal","SUV_Green","SUV_Orange","SUV_Pink","SUV_Red","SUV_Silver","SUV_TK_CIV_EP1","SUV_White","SUV_Yellow","tractor","TT650_Civ","TT650_Ins","TT650_TK_CIV_EP1","UAZ_CDF","UAZ_INS","UAZ_MG_TK_EP1_DZE","UAZ_RU","UAZ_Unarmed_TK_CIV_EP1","UAZ_Unarmed_TK_EP1","UAZ_Unarmed_UN_EP1","UH1H_DZE","UH1Y_DZE","UH60M_EP1_DZE","UralRefuel_TK_EP1_DZ","Ural_CDF","Ural_TK_CIV_EP1","Ural_UN_EP1","V3S_Open_TK_CIV_EP1","V3S_Open_TK_EP1","V3S_Refuel_TK_GUE_EP1_DZ","VolhaLimo_TK_CIV_EP1","Volha_1_TK_CIV_EP1","Volha_2_TK_CIV_EP1","VWGolf","Zodiac"], 100];   
VehCount = count _VehicleList;
i = 0;
for "i" from 0 to VehCount do
    {
        v = _VehicleList select i;
        deleteVehicle v;
    };
delVehicle = 1;
    titleText ["Deleted All Vehicles within 100 meters of Trader Zones !.","PLAIN"];titlefadeOut 5;
};

this still works but again it runs every time someone connects!

if someone works this out could they give a a detailed description on how publicVaribles work.

http://community.bistudio.com/wiki/addPublicVariableEventHandler

http://community.bistudio.com/wiki/Variables

some of this makes sense but ...
 
make sure you post this on dayzepoch.com and specifically look for a member named AxeCop.
 
You need to make sure a client doesn't run it, only the server or else it will run everytime a client connects.

Code:
waitUntil {!isNil "dayz_animalCheck"};
if (isClient) exitWith {};
 
nice initiative ... i have been thinking of making something like this, but i never had time

i think you need this to only run from the server and implement it where vehicles are spawned in instead of running it clientside.
then check if they are in one of the zones and if they are, skip it and delete it from db.

also you do not need to use all these vehicle types, just use these:
Code:
["Air","Landvehicle","Ship","Tank"]
depending on the vehicles you use on your server you can leave out tank and idk if ship is actually needed, but i put it there just in case
 
you inspired me to write my own version of this ... however im getting an error now, since no player is activating this

It works and vehicles are deleted in the defined areas (also in db) and it writes a small log of vehicle, vehicle type and content(weapons,mags,bags).

heres what i did:

in server_functions.sqf below:
Code:
server_deleteObj =            compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_deleteObj.sqf";     //Removes the object from the DB
add this:
Code:
server_deleteObjInsafezone = compile preprocessFileLineNumbers "\z\addons\dayz_server\compile\server_deleteObjInsafezone.sqf";     //Removes object in safezones from the DB

in server_monitor.sqf find this:
Code:
                    // total each vehicle
                    serverVehicleCounter set [count serverVehicleCounter,_type];
                };
add the line like this:
Code:
                    serverVehicleCounter set [count serverVehicleCounter,_type];
                };
                [_object] call server_deleteObjInsafezone;
then make a new txt file, call it server_deleteObjInsafezone.sqf and put this in it:
Code:
//Script by HALV
private["_obj","_typeOf","_dist","_delVeh","_safezones","_possiblematch","_Action","_safespot","_dam","_delbikmot","_defdelar"];
_obj = _this select 0;
_typeOf = typeOf _obj;
//vehicle types to Check for
_delVeh = ["Air","Landvehicle","Ship","Tank"];
// Delete/Tp vehicles within this distance from safezone areas
_dist=100;
//Action to take when vehicle is detected in a safezone
//0 Delete vehicles ingame but keep in database. NOTE: This will stack vehicles in database if not cleaned propper
//1 Tp vehicles outside safezone (150-400m from safezone pos)
//2 Tp vehicles to a position within 125m of _safespot (remember to set a position below)
//3 will delete vehicles completly from database
_Action=2;
//if _Action=2 enter a position here (default is by grozovoy pass around 022010)
_safespot=[2283.19,14255,0];
//damaged above this amount will be deleted
_dam=0.90;

//if true will delete vehicles matching array below by default
_delbikmot=true;
//if above is true will delete these by default
_defdelar=["Bicycle","Motorcycle","ATV_Base_EP1","CSJ_GyroC","CSJ_GyroCover","CSJ_GyroP"];

//set to true, to unlock by default
_unlock=true;

//safezone areas
_safezones = [
[6325.6772,7807.7412,0],//trader city Stary
[4063.4226,11664.19, 0],//trader city Bash
[11447.472,11364.504,0],//trader city Klen
[1606.6443,7803.5156,0],//Bandit Trader
[12944.227,12766.889,0],//Hero Trader
[8110.9663,9246.5137,0],//Old Mansion
[13441.16,5429.3013, 0],//BoatDealerEast
[4510.7773,10774.518,0],//AirVehicles
[7989.3354,2900.9946,0],//BoatDealerSouth
[13532.614,6355.9497,0],//boatTraderEast
[4361.4937,2259.9526,0] //wholesaleSouth
];

///************ dont touch anything below this line unless you know what you are doing ************///
_possiblematch=false;
{if(_obj isKindOf _x)then{_possiblematch=true;};}forEach _delVeh;
if(_possiblematch)then{
    {
        if(_obj distance _x < _dist)then{
private["_pos","_mags","_weaps","_packs","_objID","_objUID","_Spos","_nearestCity","_textCity","_txt"];
            _Spos        = _x;
            _pos        = getpos _obj;
            _mags        = getmagazinecargo _obj;
            _weaps        = getweaponcargo _obj;
            _packs        = getbackpackcargo _obj;
            _objID        = _obj getVariable["ObjectID","0"];
            _objUID        = _obj getVariable["ObjectUID","0"];
            _textCity    = "Unknown";
            _nearestCity = nearestLocations [_Spos, ["NameCityCapital","NameCity","NameVillage","NameLocal"],1000];
            if (count _nearestCity > 0) then {_textCity = text (_nearestCity select 0)};
            _txt = (gettext (configFile >> 'CfgVehicles' >> _typeOf >> 'displayName'));
            diag_log format["VEHICLE IN SAFEZONE: %1 (%2) @ %3 %4 %5 [ID:%6,UID:%7] Cargo: [%8,%9,%10]",_txt,_typeOf,_textCity,mapgridposition _pos,_pos,_objID,_objUID,_weaps,_mags,_packs];
            if(_delbikmot)then{{if(_obj isKindOf _x)then{_Action=3;diag_log "Model from delete by default detected...";};}forEach _defdelar;};
            if(getDammage _obj > _dam)then{_Action=3;diag_log "Vehicle too damaged";};
            if(_unlock and (locked _obj))then{_obj setVehicleLock "UNLOCKED";_obj setVariable ["R3F_LOG_disabled",false,true];diag_log "Vehicle set unlocked";};
            switch(_Action)do{
                case 0:{
                    deleteVehicle _obj;
                    diag_log "Vehicle delteted, but remains in DB";
                };
                case 1:{
                    private["_newPos"];
                    _newPos = [_Spos, 150, 400, 10, 0, 2000, 0] call BIS_fnc_findSafePos;
                    _obj setpos _newPos;
                    diag_log format["Vehicle teleported from %1 %2 to %3 %4",_pos,mapgridposition _pos,_newPos,mapgridposition _newPos];
                };
                case 2:{
                    private["_newPos"];
                    _newPos = [_safespot, 0, 125, 10, 0, 2000, 0] call BIS_fnc_findSafePos;
                    _obj setpos _newPos;
                    diag_log format["Vehicle teleported from %1 %2 to %3 %4",_pos,mapgridposition _pos,_newPos,mapgridposition _newPos];
                };
                default{
                    deleteVehicle _obj;
                    [_objID,_objUID,"SERVER"] call server_deleteObj;
                };
            };
        };
    }forEach _safezones;
};

edit as you like, but as i said, since no player is activating this, it has a log error every time it deletes a vehicle

this is the error i get:
Code:
23:38:03 "DELETING A VEHICLE IN SAFEZONE: GNT_C185U ([4139.71,1465.8,0]) @ [4166.62,1476.33,-0.181437] [ID:407,UID:0] with cargo [[[],[]],[[],[]],[[],[]]]"
23:38:03 "DELETE: <null> Deleted by ID: 407"
23:38:03 Error in expression <g format["DELETE: %1 Deleted by ID: %2",_activatingPlayer,_id];
} else  {

_key >
23:38:03   Error position: <_activatingPlayer,_id];
} else  {

_key >
23:38:03   Error Undefined variable in expression: _activatingplayer
23:38:03 File z\addons\dayz_server\compile\server_deleteObj.sqf, line 15

use it as you like, this works as intended :)
(safezones areas are for cherno)
 
Last edited:
The _activatingPlayer is just for logging reasons, so you should be able to do something like this to remove that error for _activatingPlayer when it's nil.

Code:
if {!(isNil "_activatingPlayer")} then {
    diag_log format["DELETE: %1 Deleted by ID: %2",_activatingPlayer,_id];
};

You'd have to have a custom server_deleteObj.sqf of course.
 
the error is irreleveant tbh, but yea i was thinking of just parsing a string like "SERVER" to trick it, i think that might do the trick aswell
 
fixed (edited post above)

Big thanks to titan, for the original idea for this, +1 to you
 
Last edited:
thanks ... it was quite simple really
i didnt mean to hijack your thread, but i just got kinda excided about it, since this is quite often a big hassle on my server, with vehicles blocking traders.

now i just teleport the vehicles to a safelocation and sell them on auction in the eavning, to highest bidding player ... problem solved+we have fun auctions now ;)
 
Back
Top