Skip to content

Commit 29db9ba

Browse files
committed
Merge pull request #94 from fritogotlayed/DUWSR-93
DUWSR-93 Update cleanup logic that is negatively impacting players.
2 parents 213904a + 76472e4 commit 29db9ba

File tree

2 files changed

+112
-79
lines changed

2 files changed

+112
-79
lines changed

source/INIT.sqf

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,14 @@ if (isServer) then {
262262

263263
if (isServer) then {
264264
// group cleaning script
265-
0 = [
266-
60*60, // seconds to delete dead bodies (0 means don't delete)
267-
60*60, // seconds to delete dead vehicles (0 means don't delete)
268-
60*60, // seconds to delete dropped weapons (0 means don't delete)
269-
0, // seconds to deleted planted explosives (0 means don't delete)
270-
60*60 // seconds to delete dropped smokes/chemlights (0 means don't delete)
271-
] execVM 'repetitive_cleanup.sqf';
265+
clean = [
266+
5*60, // seconds to delete dead bodies (0 means don't delete)
267+
5*60, // seconds to delete dead vehicles (0 means don't delete)
268+
0, // seconds to delete immobile vehicles (0 means don't delete)
269+
5*60, // seconds to delete dropped weapons (0 means don't delete)
270+
0, // seconds to deleted planted explosives (0 means don't delete)
271+
10*60 // seconds to delete dropped smokes/chemlights (0 means don't delete)
272+
] execVM 'repetitive_cleanup.sqf';
272273
};
273274

274275
if (!isServer) then {

source/repetitive_cleanup.sqf

Lines changed: 104 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,103 @@
11
/*
2-
NAME: repetitive_cleanup.sqf
3-
VERSION: 1.7
4-
5-
DESCRIPTION:
6-
Can delete everything that is not really needed
7-
dead bodies, dropped items, smokes, chemlights, explosives, empty groups
8-
Works even on Altis, it eats only items which are 100m from all units
9-
10-
USAGE:
11-
in server's init
12-
[
13-
60, // seconds to delete dead bodies (0 means don't delete)
14-
5*60, // seconds to delete dead vehicles (0 means don't delete)
15-
2*60, // seconds to delete dropped weapons (0 means don't delete)
16-
10*60, // seconds to deleted planted explosives (0 means don't delete)
17-
0 // seconds to delete dropped smokes/chemlights (0 means don't delete)
18-
] execVM 'repetitive_cleanup.sqf';
19-
20-
will delete dead bodies after 60 seconds (1 minute)
21-
will delete dead vehicles after 5*60 seconds (5 minutes)
22-
will delete weapons after 2*60 seconds (2 minutes)
23-
will delete planted explosives after 10*60 seconds (10 minutes)
24-
will not delete any smokes/chemlights since its disabled (set to 0)
2+
NAME: repetitive_cleanup.sqf
3+
VERSION: 1.9
4+
5+
DESCRIPTION:
6+
Can delete everything that is not really needed
7+
dead bodies, dropped items, smokes, chemlights, explosives, empty groups
8+
Works even on Altis, it eats only items which are/were 100m from all units
9+
10+
USAGE:
11+
in server's init
12+
[
13+
60, // seconds to delete dead bodies (0 means don't delete)
14+
5*60, // seconds to delete dead vehicles (0 means don't delete)
15+
3*60, // seconds to delete immobile vehicles (0 means don't delete)
16+
2*60, // seconds to delete dropped weapons (0 means don't delete)
17+
10*60, // seconds to deleted planted explosives (0 means don't delete)
18+
0 // seconds to delete dropped smokes/chemlights (0 means don't delete)
19+
] execVM 'repetitive_cleanup.sqf';
20+
21+
will delete dead bodies after 60 seconds (1 minute)
22+
will delete dead vehicles after 5*60 seconds (5 minutes)
23+
will delete immobile vehicles after 3*60 seconds (3 minutes)
24+
will delete weapons after 2*60 seconds (2 minutes)
25+
will delete planted explosives after 10*60 seconds (10 minutes)
26+
will not delete any smokes/chemlights since its disabled (set to 0)
27+
28+
If you want something to withstand the clean up, paste this into it's init:
29+
this setVariable["persistent",true];
2530
*/
2631

2732
if (!isServer) exitWith {}; // isn't server
2833

2934
#define PUSH(A,B) A set [count (A),B];
3035
#define REM(A,B) A=A-[B];
3136

32-
private ["_ttdBodies","_ttdVehicles","_ttdWeapons","_ttdPlanted","_ttdSmokes","_delete","_unit"];
37+
private ["_ttdBodies","_ttdVehiclesDead","_ttdVehiclesImmobile","_ttdWeapons","_ttdPlanted","_ttdSmokes","_addToCleanup","_unit","_objectsToCleanup","_timesWhenToCleanup","_removeFromCleanup"];
3338

3439
_ttdBodies=[_this,0,0,[0]] call BIS_fnc_param;
35-
_ttdVehicles=[_this,1,0,[0]] call BIS_fnc_param;
36-
_ttdWeapons=[_this,2,0,[0]] call BIS_fnc_param;
37-
_ttdPlanted=[_this,3,0,[0]] call BIS_fnc_param;
38-
_ttdSmokes=[_this,4,0,[0]] call BIS_fnc_param;
40+
_ttdVehiclesDead=[_this,1,0,[0]] call BIS_fnc_param;
41+
_ttdVehiclesImmobile=[_this,2,0,[0]] call BIS_fnc_param;
42+
_ttdWeapons=[_this,3,0,[0]] call BIS_fnc_param;
43+
_ttdPlanted=[_this,4,0,[0]] call BIS_fnc_param;
44+
_ttdSmokes=[_this,5,0,[0]] call BIS_fnc_param;
3945

40-
if (_ttdWeapons<=0 && _ttdPlanted<=0 && _ttdSmokes<=0 && _ttdBodies<=0 && _ttdVehicles<=0) exitWith {};
46+
if({_x>0}count _this==0) exitWith {}; // all times are 0, we do not want to run this script at all
4147

42-
_objects=[];
43-
_items=[];
48+
_objectsToCleanup=[];
49+
_timesWhenToCleanup=[];
4450

45-
_delete = {
51+
_addToCleanup = {
4652
_object = _this select 0;
47-
_time = _this select 1;
48-
if(_objects find _object == -1) then {
49-
PUSH(_objects,_object)
50-
PUSH(_items,_time+time)
51-
};
53+
if(!(_object getVariable["persistent",false])) then {
54+
_newTime = (_this select 1)+time;
55+
_index = _objectsToCleanup find _object;
56+
if(_index == -1) then {
57+
PUSH(_objectsToCleanup,_object)
58+
PUSH(_timesWhenToCleanup,_newTime)
59+
} else {
60+
_currentTime = _timesWhenToCleanup select _index;
61+
if(_currentTime>_newTime) then {
62+
_timesWhenToCleanup set[_index, _newTime];
63+
};
64+
};
65+
};
5266
};
5367

54-
while{true} do {
55-
56-
sleep 10;
57-
if (_ttdBodies>0) then {
58-
{
59-
if(!isPlayer _x) then {
60-
[_x, _ttdBodies] call _delete;
61-
};
62-
} forEach allDeadMen;
63-
};
64-
65-
if (_ttdVehicles>0) then {
66-
{
67-
if(!isPlayer _x) then {
68-
[_x, _ttdVehicles] call _delete;
69-
};
70-
} forEach (allDead - allDeadMen);
68+
_removeFromCleanup = {
69+
_object = _this select 0;
70+
_index = _objectsToCleanup find _object;
71+
if(_index != -1) then {
72+
_objectsToCleanup set[_index, 0];
73+
_timesWhenToCleanup set[_index, 0];
7174
};
75+
};
7276

73-
{
77+
while{true} do {
78+
sleep 10;
79+
{
7480
_unit = _x;
75-
7681
if (_ttdWeapons>0) then {
7782
{
78-
{
79-
[_x, _ttdWeapons] call _delete;
83+
{
84+
[_x, _ttdWeapons] call _addToCleanup;
8085
} forEach (getpos _unit nearObjects [_x, 100]);
8186
} forEach ["WeaponHolder","GroundWeaponHolder","WeaponHolderSimulated"];
8287
};
8388

8489
if (_ttdPlanted>0) then {
8590
{
86-
{
87-
[_x, _ttdPlanted] call _delete;
91+
{
92+
[_x, _ttdPlanted] call _addToCleanup;
8893
} forEach (getpos _unit nearObjects [_x, 100]);
8994
} forEach ["TimeBombCore"];
9095
};
9196

9297
if (_ttdSmokes>0) then {
9398
{
94-
{
95-
[_x, _ttdSmokes] call _delete;
99+
{
100+
[_x, _ttdSmokes] call _addToCleanup;
96101
} forEach (getpos _unit nearObjects [_x, 100]);
97102
} forEach ["SmokeShell"];
98103
};
@@ -105,19 +110,46 @@ while{true} do {
105110
};
106111
} forEach allGroups;
107112

108-
{
113+
if (_ttdBodies>0) then {
114+
{
115+
[_x, _ttdBodies] call _addToCleanup;
116+
} forEach allDeadMen;
117+
};
118+
119+
if (_ttdVehiclesDead>0) then {
120+
{
121+
if(_x == vehicle _x) then { // make sure its vehicle
122+
[_x, _ttdVehiclesDead] call _addToCleanup;
123+
};
124+
} forEach (allDead - allDeadMen); // all dead without dead men == mostly dead vehicles
125+
};
126+
127+
if (_ttdVehiclesImmobile>0) then {
128+
{
129+
if(!canMove _x && {alive _x}count crew _x==0) then {
130+
[_x, _ttdVehiclesImmobile] call _addToCleanup;
131+
} else {
132+
[_x] call _removeFromCleanup;
133+
};
134+
} forEach vehicles;
135+
};
136+
137+
REM(_objectsToCleanup,0)
138+
REM(_timesWhenToCleanup,0)
139+
140+
{
109141
if(isNull(_x)) then {
110-
_objects set[_forEachIndex, 0];
111-
_items set[_forEachIndex, 0];
142+
_objectsToCleanup set[_forEachIndex, 0];
143+
_timesWhenToCleanup set[_forEachIndex, 0];
112144
} else {
113-
if(_items select _forEachIndex < time) then {
145+
if(_timesWhenToCleanup select _forEachIndex < time) then {
114146
deleteVehicle _x;
115-
_objects set[_forEachIndex, 0];
116-
_items set[_forEachIndex, 0];
147+
_objectsToCleanup set[_forEachIndex, 0];
148+
_timesWhenToCleanup set[_forEachIndex, 0];
117149
};
118-
};
119-
} forEach _objects;
150+
};
151+
} forEach _objectsToCleanup;
120152

121-
REM(_objects,0)
122-
REM(_items,0)
153+
REM(_objectsToCleanup,0)
154+
REM(_timesWhenToCleanup,0)
123155
};

0 commit comments

Comments
 (0)