Jump to content

Delete vehicles parked in safezones on restart


Halvhjearne

Recommended Posts

                    serverVehicleCounter set [count serverVehicleCounter,_type];
                };
                [_object] execVM "\z\addons\dayz_server\compile\Server_DeleteObjInsafezone.sqf";
I have setup the execVM like said but no luck getting it to run code is all correct only thing it could be is infistar.de conflict but I see no error in logs.

I'm using chernarus map

Link to comment
Share on other sites

Hi, added this today to me server, works great except that when vehicles are teleported to the assigned area - my case -  balota, they are unlocked ok BUT upon the next restart 3 hours later they are locked again BUT still where they have been teleported to, any ideas how to stop them locking again?

Link to comment
Share on other sites

Where would i add that in the code :)

what about running this to tp the cars to a set coord, then Maca134's to unlock any vehicle in that coord ??

it would keep it unlocked until someone drove it away then the following restart would lock.

kinda could clutter up the db with locked cars though.

Link to comment
Share on other sites

  • 1 month later...
  • 3 weeks later...
  • 3 months later...
  • 1 month later...

Hey Guys here is the part of my server_monitor.sqf

 

 

if (!((typeOf _object) in dayz_allowedObjects)) then {

 
//_object setvelocity [0,0,1];
_object call fnc_veh_ResetEH;
 
if(_ownerID != "0" && !(_object isKindOf "Bicycle")) then {
_object setvehiclelock "locked";
};
 
_totalvehicles = _totalvehicles + 1;
 
// total each vehicle
serverVehicleCounter set [count serverVehicleCounter,_type];
};
};

 

 

And here is the edited server_deleteObjInsafezone i changed the } forEach into } count and wrote down chernarus , dont know where my mistake is. the server_deleteObjInsafezone.sqf saved in dayzserver/compile

 

 

/*

VEHICLE CLEANUP ZONE
Script by HALV
*/
_obj = _this select 0;
 
if (!isServer) exitWith {diag_log "Server_DeleteObjInsafezone.sqf - ERROR: NOT SERVER?"};
 
//\\\\\\\\\\\\\\\\\\\\ Setup Area ////////////////////\\
 
//vehicle types to Check for
_delVeh = ["Air","Landvehicle","Ship","Tank"];
 
//Action to take when vehicle is detected in a [VEHICLE CLEANUP ZONE]
//0 Delete vehicles ingame but keep in database. NOTE: This will stack vehicles in database if not cleaned propper
//1 Tp vehicles outside [VEHICLE CLEANUP ZONE] ("radius" + 50 meter to 4x "radius" from VEHICLE CLEANUP ZONE pos eg: if radius is 100 vehicles are moved 150-400 meter away)
//2 Tp vehicles to a position within 125m of _safespot (remember to set a position below)
//3 will delete vehicles completly from database
_Action = 1;
 
//if _Action = 2 then enter the position you desire here (default is by grozovoy pass around 022010)
_safespot = [2283.19,14255,0];
//how large radius to spread them in this area in meters (default 125m)
_radius = 125;
 
//damaged above this amoun, vehicle is deleted (set to 1 to only delete completely destroyed vehicles)
_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","CSJ_GyroC","CSJ_GyroCover","CSJ_GyroP"];//,"ATV_Base_EP1"
 
//set to true, to unlock vehicles by default when TP'ed
_unlock = true;
 
//log text, this is what you want to look for in the logs, if you need to know something about a moved vehicle
_txt = "[VEHICLE CLEANUP ZONE]";
 
//Update vehicles to the hive, and make sure they are not moved each restart?
_updateHIVE = true;
 
//VEHICLE CLEANUP ZONE's/areas switch choosing the map name for cleanup location purposes
if(isNil "HALV_VEHICLE_CLEANUPZONES")then{
diag_log format["%1: selecting world to cleanup ...",_txt];
_chernarus = toLower format ["%1", chernarus];
switch (_chernarus)do {
//NAPF
case "napf":{
// diag_log format["%2: Cleanup zones for napf selected! (check: %1)",_chernarus,_txt]; //logging if right worldname was selected, if uncommented
HALV_VEHICLE_CLEANUPZONES = [
//position //radius //cityname/text
[[8246.3184,15485.867,0], 125, "Trader City Lenzburg"],
[[15506.952,13229.368,0], 125, "Trader city Emmen"],
[[12399.751,5074.5273,0], 125, "Trader City Schratten"],
[[10398.626,8279.4619,0], 125, "Bandit Vendor"],
[[5149.9814,4864.1191,0], 125, "Hero Vendor"],
[[2122.7954,7807.9878,0], 100, "West Wholesaler"],
[[5379.0342,16103.187,0], 100, "North Wholesaler"],
[[6772.8877,16983.27,0], 100, "Nordic Boats"],
[[16839.973,5264.0566,0], 100, "Pauls Boats"],
[[15128.379,16421.879,0], 100, "AWOLs Airfield"]
];
};
//chernarus
case "chernarus":{
// diag_log format["%2: Cleanup zones for chernarus selected! (check: %1)",_WorldName,_txt]; //logging if right worldname was selected, if uncommented
HALV_VEHICLE_CLEANUPZONES = [
//position radius cityname/text
[[6325.6772,7807.7412,0], 125, "Trader City Stary"],
[[4063.4226,11664.19,0], 125, "Trader City Bash"],
[[11447.472,11364.504,0], 125, "Trader City Klen"],
[[1606.6443,7803.5156,0], 125, "Bandit Camp"],
[[12944.227,12766.889,0], 125, "Hero Camp"],
[[13441.16,5429.3013,0], 100, "Wholesaler East"],
[[4510.7773,10774.518,0], 100, "Aircraft Dealer"],
[[7989.3354,2900.9946,0], 100, "Boat Dealer South"],
[[13532.614,6355.9497,0], 100, "Boat Dealer East"],
[[4361.4937,2259.9526,0], 100, "Wholesaler South"]
];
};
//tavi
case "tavi":{
// diag_log format["%2: Cleanup zones for tavi selected! (check: %1)",_WorldName,_txt]; //logging if right worldname was selected, if uncommented
HALV_VEHICLE_CLEANUPZONES = [
//position //radius //cityname/text
[[11698.81,15210.121,0], 75, "Trader City Lyepestok"],
[[15309.663,9278.4912,0], 75, "Trader City Sabina"],
[[5538.7354,8762.2695,0], 75, "Trader City Bilgrad"],
[[7376.6084,4296.5879,0], 75, "Trader City Branibor"],
[[10948.426,654.90265,0], 75, "Bandit Vendor"],
[[15587.822,16394.049,0], 75, "Hero Vendor"],
[[16555.732,10159.68,0], 75, "Aircraft Dealer"],
[[6815.0776,8534.1504,0], 75, "Aircraft Dealer 2"],
[[4066.3528,7265.0024,0], 75, "Misc. Vendor"],
[[17497.631,7159.0879,0], 75, "Misc. Vendor 2"],
[[17332.115,12930.239,0], 75, "Boat Dealer"],
[[10570.494,16772.477,0], 75, "Boat Dealer 2"],
[[10698.463,5983.665,0], 75, "Boat Dealer 3"],
[[5419.2437,9503.5479,0], 75, "Boat Dealer 4"],
[[13342.758,8611.9932,0], 75, "Wholesaler"],
[[9859.4209,7471.5684,0], 75, "Wholesaler"] // <-- no comma for last entry
];
};
/*
//myworldname
case "myworldnameinlowercase":{
// diag_log format["%2: Cleanup zones for myworldnameinlowercase selected! (check: %1)",_WorldName,_txt]; //logging if right worldname was selected, if uncommented
HALV_VEHICLE_CLEANUPZONES = [
//position //radius //cityname/text
[[7839.60,8414.73,381.33], 150, "my custom zone marker"],
[[7839.60,8414.73,381.33], 75, "my custom location"] // <-- no comma for last entry
];
};
*/
//default
default{
diag_log format["%2: Cleanup zones for %1 not availible ...",_WorldName,_txt]; //logging if right worldname was selected, if uncommented
HALV_VEHICLE_CLEANUPZONES = [
//position //radius //cityname/text
[[0,0,0], 1, "DEBUG"]
];
};
};
};
//\\\\\\\\\\\\\\\\\\\\  End Setup Area ////////////////////\\
 
/////////////// dont touch anything below this line unless you know what you are doing \\\\\\\\\\\\\\\
 
_possiblematch = false;
{if(_obj isKindOf _x)then{_possiblematch=true;};}count _delVeh;
if(_possiblematch)then{
{
_Spos = _x select 0;
_Rad = _x select 1;
_name = _x select 2;
_radats = _Rad+50;
_radx4 = _Rad+_Rad+_Rad+_Rad;
if(_obj distance _Spos < _Rad)then{
_defdel = false;
_typeOf = typeOf _obj;
_pos = getpos _obj;
_mags = getmagazinecargo _obj;
_weaps = getweaponcargo _obj;
_packs = getbackpackcargo _obj;
_objID = _obj getVariable["ObjectID","0"];
_objUID = _obj getVariable["ObjectUID","0"];
_objname = (gettext (configFile >> 'CfgVehicles' >> _typeOf >> 'displayName'));
diag_log format["%1: %2 (%3) by %4 @%5 %6 [iD:%7,UID:%8] Cargo: [%9,%10,%11]",_txt,_typeOf,_objname,_name,mapgridposition _pos,_pos,_objID,_objUID,_weaps,_mags,_packs];
if(_delbikmot)then{{if(_obj isKindOf _x)then{_defdel = true};}count _defdelar;};
if(_defdel)then{_Action=3;diag_log format["%2: %1 is Model to delete by default!",_typeOf,_txt];};
if(getDammage _obj > _dam)then{_Action=3;diag_log format["%2: %1 too damaged",_typeOf,_txt];};
if(_unlock and !_defdel and (locked _obj))then{_obj setVehicleLock "UNLOCKED";_obj setVariable ["R3F_LOG_disabled",false,true];diag_log format["%2: %1 Un-Locked",_typeOf,_txt];};
switch(_Action)do{
case 0:{deleteVehicle _obj;diag_log format["%2: %1 Deleted, but remains in DB (Dont forget to clean this up)",_typeOf,_txt];};
case 1:{
_newPos = [_Spos, _radats, _radx4, 10, 0, 2000, 0] call BIS_fnc_findSafePos;
_obj setpos _newPos;
//update to HIVE?
if(_updateHIVE)then{
private["_position","_worldspace","_fuel","_key"];
_position = getPosATL _obj;
_worldspace = [
round(direction _obj),
_position
]; 
_fuel = fuel _obj;
_key = format["CHILD:305:%1:%2:%3:",_objID,_worldspace,_fuel];
diag_log ("HIVE: WRITE: "+ str(_key));
_key call server_hiveWrite;
};
diag_log format["%6: %5 TP from %1 %2 to %3 %4",_pos,mapgridposition _pos,_newPos,mapgridposition _newPos,_typeOf,_txt];
};
case 2:{
_newPos = [_safespot, 0, _radius, 10, 0, 2000, 0] call BIS_fnc_findSafePos;
_obj setpos _newPos;
//update to HIVE?
if(_updateHIVE)then{
private["_position","_worldspace","_fuel","_key"];
_position = getPosATL _obj;
_worldspace = [
round(direction _obj),
_position
];
_fuel = fuel _obj;
_key = format["CHILD:305:%1:%2:%3:",_objID,_worldspace,_fuel];
diag_log ("HIVE: WRITE: "+ str(_key));
_key call server_hiveWrite;
};
diag_log format["%6: %5 TP from %1 %2 to %3 %4",_pos,mapgridposition _pos,_newPos,mapgridposition _newPos,_typeOf,_txt];
};
default{_msg = format["%2: %1",_typeOf,_txt];deleteVehicle _obj;[_objID,_objUID,_msg] call server_deleteObj;};
};
};
}count HALV_VEHICLE_CLEANUPZONES;
};

 

I am using epoch 1.0.5.1 but it dont run, i need help. I think i am to dumb.. O.o 

Link to comment
Share on other sites

I got a question to your script style.

 

You like using switch do, that's ok even tho switch uses more resources then IF. But: I think, that switch cases will actually run trough to see what happens in each case, therefore each case will be read, but only the matching or default case will be executed - please correct me, if i'm wrong.


Wouldn't it be a lot better, if you first of all put the default case on top and then inside the case use exitWith, to exit the switch and prevent further reading?

Also (i am absolutely unsure about this) - can't you execute code inside a switch, without going into a case? This would also help a lot, because it has less to read and you don't have to do it in each case... -- Means, if this actually works (i never really use switch).

switch(_Action)do{
	private["_position","_worldspace","_fuel"];

	_position = getPosATL _obj;

	_worldspace = [
		round(direction _obj),
		_position
	]; 

	_fuel = fuel _obj;

	case 0: {};
	case 1: {};
	case 2: {};
};

So again: This is not a "how to do it better", this is a "would that be better" post. I'm asking, not telling - because i don't know it better :) I just like clean and good code, that's all.

Link to comment
Share on other sites

I got a question to your script style.

 

You like using switch do, that's ok even tho switch uses more resources then IF. But: I think, that switch cases will actually run trough to see what happens in each case, therefore each case will be read, but only the matching or default case will be executed - please correct me, if i'm wrong.

Wouldn't it be a lot better, if you first of all put the default case on top and then inside the case use exitWith, to exit the switch and prevent further reading?

 

nope you are completly right on this.

if is allways faster then switch do, because switch do allways checks every single case.

 

so changing it to if commands would be less impact on the perfomance :)

Link to comment
Share on other sites

I got a question to your script style.

 

You like using switch do, that's ok even tho switch uses more resources then IF. But: I think, that switch cases will actually run trough to see what happens in each case, therefore each case will be read, but only the matching or default case will be executed - please correct me, if i'm wrong.

Wouldn't it be a lot better, if you first of all put the default case on top and then inside the case use exitWith, to exit the switch and prevent further reading?

Also (i am absolutely unsure about this) - can't you execute code inside a switch, without going into a case? This would also help a lot, because it has less to read and you don't have to do it in each case... -- Means, if this actually works (i never really use switch).

switch(_Action)do{
	private["_position","_worldspace","_fuel"];

	_position = getPosATL _obj;

	_worldspace = [
		round(direction _obj),
		_position
	]; 

	_fuel = fuel _obj;

	case 0: {};
	case 1: {};
	case 2: {};
};

So again: This is not a "how to do it better", this is a "would that be better" post. I'm asking, not telling - because i don't know it better :) I just like clean and good code, that's all.

 

tbh i dont know, i havent tried like that, but i think not ... read my answer below about switches

 

if is allways faster then switch do, because switch do allways checks every single case.

 

it is checking untill it finds the right exit, if we are talking one or two ifs, against a switch true do (where it checks if each statement is true), then you are correct that it is slower, but when used directly with the result like i do it is way faster than going through 10 if statements, also a switch gives more choices and allows you to expand your code more easily.

 

 

btw, this is a very old script wich could need an update to my current one, i just havent had the time to do so ...

Link to comment
Share on other sites

it is checking untill it finds the right exit, if we are talking one or two ifs, against a switch true do (where it checks if each statement is true), then you are correct that it is slower, but when used directly with the result like i do it is way faster than going through 10 if statements, also a switch gives more choices and allows you to expand your code more easily.

 

just echecked the wiki, yes you are right it is exiting as soon as it has found the matching statement :)

knowing.jpg

 

i just had this in mind: https://community.bistudio.com/wiki/Code_Optimisation#Make_it_pretty.

Link to comment
Share on other sites

answer at site 3 please guys. thanks! :)

 

as far as i can se you did not add the line to execute the script, in that case its not that big of a mystery why its not working, besides that i dont support if you edited my scripts below the settings area, so if you still have problems revert back to the original script (and install instructions) and then try again.

 

FYI @all ... this script will continue to work unless something fundamental about arma 2 or epoch changes (wich i doubt).

Link to comment
Share on other sites

so changing it to if commands would be less impact on the perfomance :)

This isnt completely correct:

"Checks if the given parameter matches any case. If so, the code block of that case will be executed. After that the switch ends so no further cases will be checked."

https://community.bistudio.com/wiki/switch_do

 

Im not entirly sure why such a huge script is needed for this. Just check each vehicles position when the server spawns them in @ startup.

Link to comment
Share on other sites

Im not entirly sure why such a huge script is needed for this. Just check each vehicles position when the server spawns them in @ startup.

 

mostly for functionality and easy use for the end user, had it not been for the fact that this was made for others to use aswell, it would propperbly not require quite as many variables and or loops used

Link to comment
Share on other sites

  • 4 weeks later...

So i am having this issue. Basically i have it set to TP the cars out randomly at server restart. But when i load back in after restart the cars are unlocked (In the file i set them to lock) And my key will no longer work on them :(, I have no RPT errors and i don't know why this is happening.

 

Any help would be much appreciated!

Link to comment
Share on other sites

Only thing i can say is: You did something wrong there then.

 

Maybe you post your code, so we can give you some real help instead?

Ok so now that i am home i can get you the files. I Included the RPT, server_monitor.sqf, and server_deleteObjInsafezone.sqf

 

I'm sure it's probley a simple error on my part but i can't find it :(

 

Thank's for any help in advance!

 

(BTW there is a lot of snap build errors, But i fixed that. Also i know it says "_Action = 3;" But i was using "_Action = 1;" i just set it like that untell i could sort of this losing ownership issue.

 

Files: (Google Drive) https://drive.google.com/folderview?id=0B9Ofd48hqAvmaUZud1p0N3dIekE&usp=sharing

Link to comment
Share on other sites

Ok so now that i am home i can get you the files...

 

the line is added on the wrong place. take a second look on the instructions

 

your code

           // total each vehicle
          serverVehicleCounter set [count serverVehicleCounter,_type];
      };
};      [_object] execVM "\z\addons\dayz_server\compile\Server_DeleteObjInsafezone.sqf";

might be unrelated to your problem thou...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...