Jump to content

atmo

Member
  • Content Count

    77
  • Joined

  • Last visited

  • Medals

Community Reputation

25 Excellent

1 Follower

About atmo

  • Rank
    Corporal

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Thank you @phronk. I was inspired by the Line of Sight tool in Steel Division. It's very cool. I'll keep tweaking it to see it I can come up with a faster method or visually more appealing. I would like to be able to create 'blobs' with smooth filled curves but I notice you can't fill a drawPolygon so it's triangles or similar it seems. Unless anyone has any ideas how to do that, I would be interested.
  2. I used lineIntersectsSurfaces because it returns a position, so if the ray hits something within the area you are testing you can say it is visible. It seems pretty fast altogether. The frame rate drop comes with more drawRectangles…. Atmo
  3. Hi all, I've made a script to check the visibility of positions on the map. An example mission is here I hope I've done this right. 1 min Video And the code is here for those interested. /* CheckVisibility.sqf Author: Atmo Date: April 2019 Version: 1.0 Params : None Description: Checks the visibility of a 2000m square around the position left clicked on in the map. It checks a position 2m off the ground to the test position. Checks 30m squares - could change the size if you want but it could get intensive... Running script toggles activation of the eventHandlers so running once turns it on, running it again stops it. Use: single left click (Default mode): - shows non-visible areas as red pressing 'alt' and left clicking: - shows visible areas in green. Some examples: 1) From an action in an players init this addAction ["Check Visibility", "fn_CheckVisibility.sqf"]; 2) compile the function from the description.ext and then call it - I'll let you do that. */ if (!hasInterface) exitWith {["fn_CheckVisibility only runs on client"] call BIS_fnc_error}; // Every time script runs toggle eventHandlers private _EHs = missionNamespace getVariable [format["BIS_stackedEventHandlers_%1", "onMapSingleClick"], []]; if (_EHs findIf {(_x select 0) isEqualTo "Atmo_CV_EH"} == -1) then { ["Atmo_CV_EH", "onMapSingleClick", { // _pos, _shift, _alt are parameters of onMapSingleClick EH private _positions = []; // Array of positions tested private _size = 30; // Size of squares (if you change this also change _size in Draw EH) // Set the drawing method for the ctrlEventHandler missionNamespace setVariable ["Atmo_CV_mode", _alt]; // Convert _pos to ASL + 2m private _origin = (ATLToASL _pos) vectorAdd [0,0, 2]; for "_i" from -1000 to 1000 step _size do { for "_j" from -1000 to 1000 step _size do { _testPos = ATLToASL (_pos VectorAdd [_i, _j, 2]); _visibility = 0; // Cast a line to the point _intersectPos = lineIntersectsSurfaces [_origin, _testpos, player, objNull, true, 1, "VIEW", "FIRE"] select 0 select 0; if (isNil "_intersectPos") then { // It didn't intersect anything = it is visible _visibility = 1; } else { // The line hit something - is thing it hit in the area we are testing? if (_intersectPos inArea [_testPos, _size, _size, 0, true, -1]) then {_visibility = 1}; }; if (_alt) then { if (_visibility == 1) then { _positions append [_testPos]; }; } else { if (_visibility == 0) then { _positions append [_testPos]; }; }; }; }; missionNamespace setVariable ["Atmo_CV_Positions", _positions]; }] call BIS_fnc_addStackedEventHandler; // Add draw EventHandler to the map display - Oooo, er, should I use displayAddEventHandler? private _map = findDisplay 12 displayCtrl 51; private _id = _map ctrlAddEventHandler ["Draw", { params ["_control"]; // Get the mode of drawing - false: 'alt' wasn't pressed show not visible in red, true: show visible in green private _mode = missionNamespace getVariable ["Atmo_CV_mode", false]; private _rgba = [[0.5,0,0,0.8], [0,0.5,0,0.8]] select _mode; private _positions = missionNamespace getVariable ["Atmo_CV_Positions", []]; private _size = 15; { _control drawRectangle [_x, _size, _size, 0, _rgba, "#(rgb,1,1,1)color(1,1,1,1)"] ; } forEach _positions; private _pos = missionNamespace getVariable ["Atmo_CV_cursorPos", [0,0]]; _control drawIcon ["#(rgb,1,1,1)color(1,1,1,1)", [0,0,1,1], _pos, 0, 0, 0, "Check Visibility (click +/- alt)"]; }]; // Save the EH id missionNamespace setVariable ["Atmo_CV_DrawEHid", _id]; _id = _map ctrlAddEventHandler ["MouseMoving", { params ["_control", "_xPos", "_yPos", "_mouseOver"]; _pos = _control posScreenToWorld [_xPos + 0.1, _yPos - 0.1]; missionNamespace setVariable ["Atmo_CV_cursorPos", _pos]; }]; // Save the EH id missionNamespace setVariable ["Atmo_CV_MouseMoveEHid", _id]; } else { // The event handler is already there - delete them all //remove onMapSingleClick private _removed = ["Atmo_CV_EH", "onMapSingleClick"] call BIS_fnc_removeStackedEventHandler; // remove Draw eventHandler on the map private _map = findDisplay 12 displayCtrl 51; _map ctrlRemoveEventHandler ["Draw", missionNamespace getVariable "Atmo_CV_DrawEHid"]; _map ctrlRemoveEventHandler ["MouseMoving", missionNamespace getVariable "Atmo_CV_MouseMoveEHid"]; missionNamespace setVariable ["Atmo_CV_Positions", []]; }; (Nice) Comments appreciated - scripters let me know if you see any glaring errors! Atmo
  4. Nah ok... Result: 2.275 ms Cycles: 440/10000 Code: someList = allUnits apply {[trigger1 distanceSqr _x, _x]}; someList sort true; closestUnit = (someList select 0) param [1, objNull]; Result: 15.2576 ms Cycles: 66/10000 Code: [allUnits, trigger1] call BIS_fnc_nearestPosition; for about 1500 units.... 😞
  5. OK, for a small amount of units it is 'efficient' but....code wise you first go through the someList array once with the 'apply' that's O(n), then you sort with what I presume is a quicksort which on average works at O(n log n), and in the worst case scenario at O(n^2)… whereas BIS_fnc_nearestPosition goes through the list once O(n).. It may be faster with sorting and then pinching the first element for small numbers (in the tens maybe) but I'm not so sure about larger arrays.... (I will go and test this for fun) but I think the issue really is cleaner code? [allUnits,trigger1] call Bis_fnc_nearestPosition; one line, can accept objects/positions/markers. Shouldn't we encourage safe, clean code which will always work? Some day we may have 1000 people on a server and if 'legacy code' is not going to cripple a function in the future we should be wary maybe? The 'worst case scenario' has an O(n^2) efficiency in it. but I am probably picking hairs..An interesting discussion. Atmo 🙂
  6. Does BIS_fnc_nearestPostiion do the job? https://community.bistudio.com/wiki/BIS_fnc_nearestPosition Only one pass through the data.. no sorting...etc
  7. Edit ....Oh wow, necrothreading.... 1 year exactly....sorry but.. Although not answering your question specifically.... The issue I have found is that the 'string' part can't have any ' " in it. You can set up some code in the missionNameSpace such as missionNameSpace setVariable ["myTag_SomeCode", {hint "Hello"; hint "Goodbye";}]; then _text = "<execute expression = 'call myTag_SomeCode' >Long line of text which you can click goes here OK? </execute>"; player createDiaryRecord ["mySubject", ["myTitle", _text]]; and that works from the diary in the map.. haven't tried within a task... I may have missed a trick with the code as a string in the tag... it never seems to want to work if you have any ' or " characters in it but, as I say, I might be missing something simple here. I know I'll call up some superusers! @killzone_kid, @Larrow? Any ideas? (and the rest of you!) Atmo
  8. Yes, @pierremgi The issue I think I noticed was that sometimes, as above, objects seem to be their own crew..... This self referencing, I think, is the crux if the problem, but it seems to be able to delete <Null Objects> (thank god!) So the solution I have shown to work is in the first pass DeleteVehicleCrew - this will delete them *on the next frame* so you wait a bit and then *deleteVehicle*… Of course it shouldn't matter and you do it all together it will just wait until the next loop of deleteVehicle to delete the ones without a crew. (then the pd3 *will* be deleted). As an aside you obviously can control what and who gets deleted you can put a timestamp on the object or test how far it is from a player etc before trying to delete it.... in "Killed" EH // Set a time killed variable onto the killed unit. // We can use this in our cleanup script. _killed setVariable ["TOD", Servertime]; // TOD = Time Of Death then // Dead { _TOD = _x getVariable ["TOD", 0]; // Time Of Death - variable added in the 'Killed' Event Handler. //diag_log format ["allDead: %1, class %2, TOD %3, %4", _forEachIndex, typeOf _x, _TOD, _serverTime - _TOD]; if (_serverTime - _TOD > 600) then { {(vehicle _x) deleteVehicleCrew _x} foreach crew _x; }; //_netID = _x call BIS_fnc_netId; //_object = _netID call BIS_fnc_objectFromNetID; //diag_log format ["allDead: %1, class: %2, netID %3, object %4, crew %5, vehicle %6", _forEachIndex, typeOf _x, _netID, _object, crew _x, vehicle _x]; } forEach allDead; // MUST pause - each deletion above is done *next* frame (only if we really want it to show - obviously in the next pass it would delete it....just that *at least one frame must have passed for it to be deleted....*) sleep 1; // Second pass - now delete the vehicles. { deleteVehicle _x; } forEach allDead; etc etc.. that bit is trivial. Atmo
  9. Ah, @magicsrp So; finally, I got back to this.. Sorry. It seems you must have a pause between two passes of deleting stuff... [] spawn { while {true} do { scriptName "Cleanup"; sleep 5; _before = count allDead; // First pass - delete all vehicle crews in allDead collection { {(vehicle _x) deleteVehicleCrew _x} foreach crew _x; } forEach allDead; // MUST pause - each deletion above is done *next* frame sleep 1; // Second pass - now delete the vehicles. { deleteVehicle _x; } forEach allDead; diag_log format ["AllDead : %1 : %2", _before, count AllDead]; hint format["AllDead : %1, %2", _before, count allDead]; }; }; I forgot I had done that, I should correct the previous post A test mission is at,,,,Stress Test GC Let me know if it works your end. Sorry about being so late.... so so busy... ! Atmo
  10. You right... I copy and pasted then wrong thing... { {(vehicle _x) deleteVehicleCrew _x} foreach crew _x; deleteVehicle _x; } forEach allDead; I didn't reload the mission just looked through a likely candidate from my folders.... I was in a bit of a rush so my apologies. I do promise to set up a test mission. It isn't going to happened tonight (14th.... jeez)…. Atmo
  11. @magicsrp Hi,, did you try { _x deleteVehicleCrew _x; } forEach allDead; With the remains collector enabled in the mission editor? Running the above once in a while seems to fix the issue. Can't quite find where I put it now but I'll piece something together again and post it for you (maybe tomorrow). Atmo
  12. I probably being stupid again, and I suspect I have missed it already in the forums.. How do I test an object for the presence of an event handler? There seem to plenty of commands to add and remove them... I noticed @Larrow used !( isNil { _x getVariable "HitEH" } ) in a post recently.... Is that the same for all EHs? So reloaded would be "ReloadedEH"? I ask because I am transferring objects from servers to clients/HCs and I am not sure if they transfer with some or all of their respective EHs etc.... I am trying to test this but I would like to ask the community for a comprehensive answer before trying to test every single one.... Atmo
  13. @das attorney @Dwarden @pierremgi @killzone_kid Just to resurrect an old thread. I was still having a lot of trouble with this, but I think I have found the solution....(probably not knowing my luck) I know the wiki has been updated re deleteVehicle and deleteVehicleCrew but I think it should apply to everything, not just vehicles.... When deleting *anything* form the allDead collection you need to use deleteVehicleCrew - even if the class is a kind of man. I found that for some reason some objects have themselves as their own crew. This is especially so when the object is some type of ***.p3d. This makes them self-referential (as far as I understand - and when you use deleteVehicle _x, the next time it tries to find it, it can't find the crew object and so fails. (I reckon ) So when deleting anything... use: { {(vehicle _x) deleteVehicleCrew _x} foreach crew _x; deleteVehicle _x; } forEach allDead; for those who want to here is the output from a test mission where the code is: diag_log "****** DELETING DEADMEN *******"; { _netID = _x call BIS_fnc_netId; _object = _netID call BIS_fnc_objectFromNetID; diag_log format ["allDead: %1, class: %2, netID %3, object %4, crew %5, vehicle %6", _forEachIndex, typeOf _x, _netID, _object, crew _x, vehicle _x]; } forEach allDead; diag_log "****"; { {(vehicle _x) deleteVehicleCrew _x} foreach crew _x; deleteVehicle _x; } forEach allDead; { _netID = _x call BIS_fnc_netId; _object = _netID call BIS_fnc_objectFromNetID; diag_log format ["allDead: %1, class: %2, netID %3, object %4, crew %5, vehicle %6", _forEachIndex, typeOf _x, _netID, _object, crew _x, vehicle _x]; } forEach allDead; diag_log "******************************"; and the out put goes from each cycle.... "****** DELETING DEADMEN *******" "allDead: 0, class: B_Soldier_F, netID 2:1005, object B Alpha 4-1:2, crew [B Alpha 4-1:2], vehicle B Alpha 4-1:2" "allDead: 1, class: O_Soldier_F, netID 2:701, object O Alpha 2-6:2, crew [O Alpha 2-6:2], vehicle O Alpha 2-6:2" "allDead: 2, class: I_soldier_F, netID 2:729, object R Alpha 2-6:1, crew [R Alpha 2-6:1], vehicle R Alpha 2-6:1" "allDead: 3, class: O_Soldier_F, netID 2:1037, object O Alpha 4-1:2, crew [O Alpha 4-1:2], vehicle O Alpha 4-1:2" "allDead: 4, class: B_Soldier_F, netID 2:1053, object B Alpha 4-2:2, crew [B Alpha 4-2:2], vehicle B Alpha 4-2:2" "allDead: 5, class: O_Soldier_F, netID 2:1085, object O Alpha 4-2:2, crew [O Alpha 4-2:2], vehicle O Alpha 4-2:2" "allDead: 6, class: B_Soldier_F, netID 2:625, object B Alpha 2-5:3, crew [B Alpha 2-5:3], vehicle B Alpha 2-5:3" "allDead: 7, class: I_soldier_F, netID 2:298, object R Alpha 1-3:3, crew [R Alpha 1-3:3], vehicle R Alpha 1-3:3" "allDead: 8, class: O_Soldier_F, netID 2:841, object O Alpha 3-3:1, crew [O Alpha 3-3:1], vehicle O Alpha 3-3:1" "****" "allDead: 0, class: B_Soldier_F, netID 2:1005, object <NULL-object>, crew [21859d71400# 1814123: b_soldier_01.p3d], vehicle 21859d71400# 1814123: b_soldier_01.p3d" "allDead: 1, class: O_Soldier_F, netID 2:701, object <NULL-object>, crew [21856e50780# 1813952: o_soldier_01.p3d], vehicle 21856e50780# 1813952: o_soldier_01.p3d" "allDead: 2, class: I_soldier_F, netID 2:729, object <NULL-object>, crew [2185c5a1040# 1813967: ia_soldier_01.p3d], vehicle 2185c5a1040# 1813967: ia_soldier_01.p3d" "allDead: 3, class: O_Soldier_F, netID 2:1037, object <NULL-object>, crew [218565d51c0# 1814141: o_soldier_01.p3d], vehicle 218565d51c0# 1814141: o_soldier_01.p3d" "allDead: 4, class: B_Soldier_F, netID 2:1053, object <NULL-object>, crew [2185644d6c0# 1814150: b_soldier_01.p3d], vehicle 2185644d6c0# 1814150: b_soldier_01.p3d" "allDead: 5, class: O_Soldier_F, netID 2:1085, object <NULL-object>, crew [2185bae90c0# 1814173: o_soldier_01.p3d], vehicle 2185bae90c0# 1814173: o_soldier_01.p3d" "allDead: 6, class: B_Soldier_F, netID 2:625, object <NULL-object>, crew [2185c8f0b00# 1813910: b_soldier_01.p3d], vehicle 2185c8f0b00# 1813910: b_soldier_01.p3d" "allDead: 7, class: I_soldier_F, netID 2:298, object <NULL-object>, crew [21858c44500# 1813727: ia_soldier_01.p3d], vehicle 21858c44500# 1813727: ia_soldier_01.p3d" "allDead: 8, class: O_Soldier_F, netID 2:841, object <NULL-object>, crew [2185b1c5300# 1814030: o_soldier_01.p3d], vehicle 2185b1c5300# 1814030: o_soldier_01.p3d" "******************************" "****** DELETING DEADMEN *******" "allDead: 0, class: I_soldier_F, netID 2:737, object R Alpha 2-6:3, crew [R Alpha 2-6:3], vehicle R Alpha 2-6:3" "allDead: 1, class: B_Soldier_F, netID 2:961, object B Alpha 3-6:3, crew [B Alpha 3-6:3], vehicle B Alpha 3-6:3" "allDead: 2, class: I_soldier_F, netID 2:390, object 2185c0413c0# 1813778: ia_soldier_01.p3d, crew [2185c0413c0# 1813778: ia_soldier_01.p3d], vehicle 2185c0413c0# 1813778: ia_soldier_01.p3d" "allDead: 3, class: O_Soldier_F, netID 2:749, object O Alpha 3-1:2, crew [O Alpha 3-1:2], vehicle O Alpha 3-1:2" "allDead: 4, class: I_soldier_F, netID 2:929, object R Alpha 3-4:3, crew [R Alpha 3-4:3], vehicle R Alpha 3-4:3" "****" "allDead: 0, class: I_soldier_F, netID 2:737, object <NULL-object>, crew [2185c7b1040# 1813973: ia_soldier_01.p3d], vehicle 2185c7b1040# 1813973: ia_soldier_01.p3d" "allDead: 1, class: B_Soldier_F, netID 2:961, object <NULL-object>, crew [2185baf48c0# 1814099: b_soldier_01.p3d], vehicle 2185baf48c0# 1814099: b_soldier_01.p3d" "allDead: 2, class: I_soldier_F, netID 2:390, object <NULL-object>, crew [2185c0413c0# 1813778: ia_soldier_01.p3d], vehicle 2185c0413c0# 1813778: ia_soldier_01.p3d" "allDead: 3, class: O_Soldier_F, netID 2:749, object <NULL-object>, crew [2185c8aca80# 1813979: o_soldier_01.p3d], vehicle 2185c8aca80# 1813979: o_soldier_01.p3d" "allDead: 4, class: I_soldier_F, netID 2:929, object <NULL-object>, crew [2185ba1d240# 1814081: ia_soldier_01.p3d], vehicle 2185ba1d240# 1814081: ia_soldier_01.p3d" "******************************" "****** DELETING DEADMEN *******" "allDead: 0, class: O_Soldier_F, netID 2:354, object O Alpha 1-5:1, crew [O Alpha 1-5:1], vehicle O Alpha 1-5:1" "allDead: 1, class: I_soldier_F, netID 2:877, object R Alpha 3-3:2, crew [R Alpha 3-3:2], vehicle R Alpha 3-3:2" "****" "allDead: 0, class: O_Soldier_F, netID 2:354, object <NULL-object>, crew [218576fc8c0# 1813757: o_soldier_01.p3d], vehicle 218576fc8c0# 1813757: o_soldier_01.p3d" "allDead: 1, class: , netID , object <NULL-object>, crew [], vehicle <NULL-object>" "******************************" with none of the "Can't find object" spam in the log file.... and it seems to be able to delete a <NULL-object> type with out any problems..... In particular notice "allDead: 2, class: I_soldier_F, netID 2:390, object 2185c0413c0# 1813778: ia_soldier_01.p3d, crew [2185c0413c0# 1813778: ia_soldier_01.p3d], vehicle 2185c0413c0# 1813778: ia_soldier_01.p3d" where the .p3d object is it's own crew (and vehicle!)......you can now delete these if you delete the crew and then it becomes a <NULL-object> I'll set up a mission to test this thoroughly but I thought I would post for those interested. And I suspect this is no news at all to anyone! Atmo
  14. Ah, no hiddenselections[] on buildings...
×