From 987baf940fd907b29ec4a1a0bf4ba87689641448 Mon Sep 17 00:00:00 2001 From: 3Mydlo3 Date: Sun, 4 Feb 2024 00:11:58 +0100 Subject: [PATCH 1/7] Clear empty vehicles on police spawns when new vehicle is spawned --- addons/police/functions/fnc_spawnVehicle.sqf | 29 ++++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/addons/police/functions/fnc_spawnVehicle.sqf b/addons/police/functions/fnc_spawnVehicle.sqf index a8a91a8e..ef577899 100644 --- a/addons/police/functions/fnc_spawnVehicle.sqf +++ b/addons/police/functions/fnc_spawnVehicle.sqf @@ -16,6 +16,8 @@ * Public: No */ +#define SPAWNPOINT_SAFEZONE 5 + params ["_vehicleClassname", "_spawner"]; private _vehicleType = (_vehicleClassname call BIS_fnc_objectType) select 1; @@ -27,13 +29,30 @@ private _spawnPoints = if (_vehicleType isEqualTo "Helicopter" || {_vehicleType +(_spawner getVariable QGVAR(spawnPoints)) }; -// Find empty spawn position +// Find spawn position private _position = []; private _direction = 0; -while {_position isEqualTo [] && {!(_spawnPoints isEqualTo [])}} do { - private _spawnPoint = [_spawnPoints] call EFUNC(common,deleteAtRandom); - private _objects = (getPos _spawnPoint) nearEntities 5; - if (_objects isEqualTo []) exitWith { + +private _emptySpawnPointIndex = _spawnPoints findIf {getPos _x nearEntities SPAWNPOINT_SAFEZONE isEqualTo []}; +if (_emptySpawnPointIndex isNotEqualTo -1) then { + private _spawnPoint = _spawnPoints select _emptySpawnPointIndex; + _position = getPos _spawnPoint; + _direction = getDir _spawnPoint; +} else { + // Maybe there is a position that has unoccupied vehicle + private _fullSpawnPointsWithoutCrew = _spawnPoints select { + private _nearEntities = getPos _x nearEntities SPAWNPOINT_SAFEZONE; + if (_nearEntities isEqualTo []) exitWith { false }; + _nearEntities findIf {crew _x isEqualTo []} isEqualTo -1 + }; + + if (_fullSpawnPointsWithoutCrew isNotEqualTo []) exitWith { + private _spawnPoint = [_fullSpawnPointsWithoutCrew] call EFUNC(common,deleteAtRandom); + + // Clear the area + _spawnPoint nearEntities SPAWNPOINT_SAFEZONE + apply {deleteVehicle _x}; + _position = getPos _spawnPoint; _direction = getDir _spawnPoint; }; From 302263141fe506f45201b92bfee95b678be6be95 Mon Sep 17 00:00:00 2001 From: 3Mydlo3 Date: Mon, 5 Feb 2024 19:23:07 +0100 Subject: [PATCH 2/7] Fix vehicle exploding on spawn --- addons/police/functions/fnc_spawnVehicle.sqf | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/addons/police/functions/fnc_spawnVehicle.sqf b/addons/police/functions/fnc_spawnVehicle.sqf index ef577899..30acd484 100644 --- a/addons/police/functions/fnc_spawnVehicle.sqf +++ b/addons/police/functions/fnc_spawnVehicle.sqf @@ -35,23 +35,30 @@ private _direction = 0; private _emptySpawnPointIndex = _spawnPoints findIf {getPos _x nearEntities SPAWNPOINT_SAFEZONE isEqualTo []}; if (_emptySpawnPointIndex isNotEqualTo -1) then { + systemChat "Found empty spawnpoint"; private _spawnPoint = _spawnPoints select _emptySpawnPointIndex; _position = getPos _spawnPoint; _direction = getDir _spawnPoint; } else { // Maybe there is a position that has unoccupied vehicle + systemChat "Looking for unoccupied vehicles"; private _fullSpawnPointsWithoutCrew = _spawnPoints select { private _nearEntities = getPos _x nearEntities SPAWNPOINT_SAFEZONE; if (_nearEntities isEqualTo []) exitWith { false }; - _nearEntities findIf {crew _x isEqualTo []} isEqualTo -1 + _nearEntities findIf {crew _x isEqualTo []} isNotEqualTo -1 }; if (_fullSpawnPointsWithoutCrew isNotEqualTo []) exitWith { + systemChat "Found unoccupied vehicles"; private _spawnPoint = [_fullSpawnPointsWithoutCrew] call EFUNC(common,deleteAtRandom); // Clear the area + systemChat "Deleting vehicles"; _spawnPoint nearEntities SPAWNPOINT_SAFEZONE - apply {deleteVehicle _x}; + apply { + deleteVehicle _x; + systemChat format ["Deleted vehicle %1", typeOf _x]; + }; _position = getPos _spawnPoint; _direction = getDir _spawnPoint; @@ -67,4 +74,5 @@ if (_position isEqualTo []) exitWith { }; // Spawn vehicle -[_vehicleClassname, _position, _direction, true, false, true] call EFUNC(civilian,createVehicle); +systemChat "Creating vehicle"; +[EFUNC(civilian,createVehicle), [_vehicleClassname, _position, _direction, true, false, true]] call CBA_fnc_execNextFrame; From fc31f72d57bca9313730cc4bb6ce50d134444e00 Mon Sep 17 00:00:00 2001 From: 3Mydlo3 Date: Thu, 15 Feb 2024 00:36:29 +0100 Subject: [PATCH 3/7] Add missing semicolon --- addons/police/functions/fnc_spawnVehicle.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/police/functions/fnc_spawnVehicle.sqf b/addons/police/functions/fnc_spawnVehicle.sqf index 30acd484..557b44b4 100644 --- a/addons/police/functions/fnc_spawnVehicle.sqf +++ b/addons/police/functions/fnc_spawnVehicle.sqf @@ -45,7 +45,7 @@ if (_emptySpawnPointIndex isNotEqualTo -1) then { private _fullSpawnPointsWithoutCrew = _spawnPoints select { private _nearEntities = getPos _x nearEntities SPAWNPOINT_SAFEZONE; if (_nearEntities isEqualTo []) exitWith { false }; - _nearEntities findIf {crew _x isEqualTo []} isNotEqualTo -1 + _nearEntities findIf {crew _x isEqualTo []} isNotEqualTo -1; }; if (_fullSpawnPointsWithoutCrew isNotEqualTo []) exitWith { From 52b78a37b37d9df589e32e26513711f142c47dd7 Mon Sep 17 00:00:00 2001 From: 3Mydlo3 Date: Thu, 15 Feb 2024 15:11:26 +0100 Subject: [PATCH 4/7] Add isNotEqualTo keyword --- tools/sqf_validator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/sqf_validator.py b/tools/sqf_validator.py index a76b9793..6da3364b 100644 --- a/tools/sqf_validator.py +++ b/tools/sqf_validator.py @@ -12,7 +12,7 @@ open = codecs.open def validKeyWordAfterCode(content, index): - keyWords = ["for", "do", "count", "each", "forEach", "else", "and", "not", "isEqualTo", "in", "call", "spawn", "execVM", "catch", "param", "select", "apply"]; + keyWords = ["for", "do", "count", "each", "forEach", "else", "and", "not", "isEqualTo", "isNotEqualTo", "in", "call", "spawn", "execVM", "catch", "param", "select", "apply"]; for word in keyWords: try: subWord = content.index(word, index, index+len(word)) From f55985cd4b0c734b04256112a09ee5f85f647951 Mon Sep 17 00:00:00 2001 From: 3Mydlo3 Date: Thu, 15 Feb 2024 15:14:34 +0100 Subject: [PATCH 5/7] Remove semicolon --- addons/police/functions/fnc_spawnVehicle.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/police/functions/fnc_spawnVehicle.sqf b/addons/police/functions/fnc_spawnVehicle.sqf index 557b44b4..30acd484 100644 --- a/addons/police/functions/fnc_spawnVehicle.sqf +++ b/addons/police/functions/fnc_spawnVehicle.sqf @@ -45,7 +45,7 @@ if (_emptySpawnPointIndex isNotEqualTo -1) then { private _fullSpawnPointsWithoutCrew = _spawnPoints select { private _nearEntities = getPos _x nearEntities SPAWNPOINT_SAFEZONE; if (_nearEntities isEqualTo []) exitWith { false }; - _nearEntities findIf {crew _x isEqualTo []} isNotEqualTo -1; + _nearEntities findIf {crew _x isEqualTo []} isNotEqualTo -1 }; if (_fullSpawnPointsWithoutCrew isNotEqualTo []) exitWith { From 2deaa918044bfa48b8d45f957f39e8c2ca2fee0a Mon Sep 17 00:00:00 2001 From: 3Mydlo3 Date: Thu, 15 Feb 2024 15:52:40 +0100 Subject: [PATCH 6/7] Replace systemChat with LOG/TRACE/INFO --- addons/police/functions/fnc_spawnVehicle.sqf | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/police/functions/fnc_spawnVehicle.sqf b/addons/police/functions/fnc_spawnVehicle.sqf index 30acd484..d4b8fb4d 100644 --- a/addons/police/functions/fnc_spawnVehicle.sqf +++ b/addons/police/functions/fnc_spawnVehicle.sqf @@ -35,13 +35,13 @@ private _direction = 0; private _emptySpawnPointIndex = _spawnPoints findIf {getPos _x nearEntities SPAWNPOINT_SAFEZONE isEqualTo []}; if (_emptySpawnPointIndex isNotEqualTo -1) then { - systemChat "Found empty spawnpoint"; + LOG("Found empty spawnpoint"); private _spawnPoint = _spawnPoints select _emptySpawnPointIndex; _position = getPos _spawnPoint; _direction = getDir _spawnPoint; } else { // Maybe there is a position that has unoccupied vehicle - systemChat "Looking for unoccupied vehicles"; + LOG("Looking for unoccupied vehicles"); private _fullSpawnPointsWithoutCrew = _spawnPoints select { private _nearEntities = getPos _x nearEntities SPAWNPOINT_SAFEZONE; if (_nearEntities isEqualTo []) exitWith { false }; @@ -49,15 +49,15 @@ if (_emptySpawnPointIndex isNotEqualTo -1) then { }; if (_fullSpawnPointsWithoutCrew isNotEqualTo []) exitWith { - systemChat "Found unoccupied vehicles"; + LOG("Found unoccupied vehicles"); private _spawnPoint = [_fullSpawnPointsWithoutCrew] call EFUNC(common,deleteAtRandom); // Clear the area - systemChat "Deleting vehicles"; + LOG("Deleting vehicles"); _spawnPoint nearEntities SPAWNPOINT_SAFEZONE apply { deleteVehicle _x; - systemChat format ["Deleted vehicle %1", typeOf _x]; + TRACE_1("Deleted vehicle %1", typeOf _x); }; _position = getPos _spawnPoint; @@ -74,5 +74,5 @@ if (_position isEqualTo []) exitWith { }; // Spawn vehicle -systemChat "Creating vehicle"; +INFO_2("Creating vehicle %1 at position %2",_vehicleClassname,str _position); [EFUNC(civilian,createVehicle), [_vehicleClassname, _position, _direction, true, false, true]] call CBA_fnc_execNextFrame; From 9ea10d6b82b5157d935919e1fcdc6da314b31bb3 Mon Sep 17 00:00:00 2001 From: 3Mydlo3 Date: Thu, 15 Feb 2024 15:53:40 +0100 Subject: [PATCH 7/7] Reorder TRACE log to actually be able to log something --- addons/police/functions/fnc_spawnVehicle.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/police/functions/fnc_spawnVehicle.sqf b/addons/police/functions/fnc_spawnVehicle.sqf index d4b8fb4d..f34caf5b 100644 --- a/addons/police/functions/fnc_spawnVehicle.sqf +++ b/addons/police/functions/fnc_spawnVehicle.sqf @@ -56,8 +56,8 @@ if (_emptySpawnPointIndex isNotEqualTo -1) then { LOG("Deleting vehicles"); _spawnPoint nearEntities SPAWNPOINT_SAFEZONE apply { + TRACE_1("Deleting vehicle %1",typeOf _x); deleteVehicle _x; - TRACE_1("Deleted vehicle %1", typeOf _x); }; _position = getPos _spawnPoint;