Advertisement
Diffusion9

Grid Position Tracker

Oct 25th, 2015
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 6.13 KB | None | 0 0
  1.     //
  2.     //  tracker.sqf --by Diffusion9 2015-10
  3.     //  tracks [player] gridPOS every [x] seconds.
  4.     //  Currently called by: [] execVM "scripts\tracker.sqf"
  5.     //  This entire script is currently way more verbose than it needs to be (not including the RPT calls)
  6.     //  VisitedGrids and VisitedStatus need to be merged into one.
  7.     //
  8.    
  9. _gridPOS = mapGridPosition player;  //--output: 108106 // Get current Map Grid from target.
  10. if (_gridPOS in VisitedGrids) then {    // Check _gridPOS against [Array].
  11.     //
  12.     //EXISTING GRID -- CHECK STATUS
  13.     //The Map Grid already exists in the VisitedGrids array:
  14.     //This section is mostly for debug, except for _ageCheck, which is placeholder.
  15.     diag_log format ["%1","================================="];
  16.     diag_log format ["%1", "=====GATHERING GRID DATA ======="];
  17.     diag_log format ["%1 %2", "_gridPOS:",_gridPOS]; //--output: 108106 (players current map grid).
  18.     _res = [VisitedStatus,_gridPOS] call KK_fnc_findAll; //Find _gridPOS' index inside the VisitedStatus array.
  19.     diag_log format ["%1 %2", "_res:",_res]; //We need the index in the array so KK_fnc_findAllGetPath can do work.
  20.     _gridCords = [VisitedStatus,(_res select 0)] call KK_fnc_findAllGetPath; //using function to grab the actual output of the index.
  21.     diag_log format ["%1 %2", "_gridCords:",_gridCords]; //--output: 108106
  22.     _gridStatPosition = (_res select 0); //Array index, removed from nested Array. A bit redundant but whatever.
  23.     diag_log format ["%1 %2", "_gridStatPosition(0):",_gridStatPosition]; //--output: [0,0].
  24.     _gridStatPosition set [1, 1]; //<array> set [index, value] -- increments to the next index (status index).
  25.     diag_log format ["%1 %2", "_gridStatPosition(1,1):",_gridStatPosition];
  26.     _gridStatus = [VisitedStatus,(_gridStatPosition)] call KK_fnc_findAllGetPath;   //Gets the value of the Grid's status.
  27.     diag_log format ["%1 %2", "_gridStatus:",_gridStatus];  //--output: 1
  28.     _gridTimePosition = (_res select 0); //Getting the inner-array index for the grid. Redundant again.
  29.     diag_log format ["%1 %2", "_gridTimePosition (sel 0):",_gridTimePosition];
  30.     _gridTimePosition set [1, 2]; //<array> set [index, value]. -- incrementing the value of the index again.
  31.     diag_log format ["%1 %2", "_gridTimePosition(1,2):",_gridTimePosition];
  32.     _gridTime = [VisitedStatus,(_gridTimePosition)] call KK_fnc_findAllGetPath; //Gets the value of the Grid's Time of Entry.
  33.     diag_log format ["%1 %2", "_gridTime:",_gridTime];
  34.     _ageCheck = (time - _gridTime); // Determine the age of the grid. Bogus calculation currently.
  35.     diag_log format ["%1 %2", "_ageCheck:",_ageCheck];
  36.     diag_log format ["%1", "=========GRID DATA END========="];
  37.     diag_log format ["%1","================================"];
  38.     //
  39.     // GRID RESET
  40.     //If the grid [Fulfills Condition] it should be flipped back to Unsecure to keep the party going.
  41.     //Current ageCheck is bogus, used for test.
  42.     IF (_ageCheck <= 0) then {
  43.         diag_log format ["%1","================================"];
  44.         diag_log format ["%1","===========GRID RESET==========="];
  45.         diag_log format ["%1 %2", "Current Grid:",_gridPOS];    //--output: 108106
  46.         diag_log format ["%1 %2", "VisitedGrids (Incoming):",VisitedGrids]; //--output: [{108106},{MAP},{GRID}]
  47.         diag_log format ["%1 %2", "VisitedStatus (Incoming):",VisitedStatus];   //--output: [[Multi],[Dimensional],[Array]]
  48.         _res0 = ([VisitedStatus,_gridPOS] call KK_fnc_findAll) select 0 select 0; // Array index in VisitedStatus.
  49.         _res1 = ([VisitedGrids,_gridPOS] call KK_fnc_findAll) select 0 select 0; //Array index in VisitedGrids.
  50.         diag_log format ["%1 %2", "VisitedStatus _res0:",_res0]; //--output: [0,0] without nest.
  51.         diag_log format ["%1 %2", "VisitedGrids _res1:",_res1]; //--output: [0] without nest.
  52.         VisitedStatus deleteAt _res0; //Removes index from the array.
  53.         VisitedGrids deleteAt _res1; //Removes index from the array.
  54.         diag_log format ["%1 %2", "Updated VisitedStatus:",VisitedStatus];
  55.         diag_log format ["%1 %2", "Updated VisitedGrids:",VisitedGrids];
  56.         diag_log format ["%1","==========GRID RESET END========"];
  57.         diag_log format ["%1","================================"];
  58.     };
  59.     //
  60.     // MAP GRID IS CONTESTED(1)
  61.     IF (_gridStatus == 1) then {
  62.         diag_log format ["%1","==================================="];
  63.         diag_log format ["%1","====CONTESTED GRID STATUS START===="];
  64.         diag_log format ["%1 %2", "Current Grid:",_gridPOS];
  65.         diag_log format ["%1 %2", "Grid Status:", _gridStatus];
  66.         diag_log format ["%1 %2", "Grid Time:", _gridTime];
  67.         diag_log format ["%1 %2", "VisitedStatus:", VisitedStatus];
  68.         diag_log format ["%1 %2", "VisitedGrids:", VisitedGrids];
  69.         diag_log format ["%1","====CONTESTED STATUS GRID END======"];
  70.         diag_log format ["%1","==================================="];
  71.     };
  72. } else {
  73.     //
  74.     //NEW GRID
  75.     //This is a new grid that the player has not yet entered, and must be configured.
  76.     //Creates an array of 'settings' for this grid, and stores it to two arrays of 'visited' grids.
  77.     VisitedGrids pushBack _gridPOS; //Add to VisitedGrids - raw list grid list of all encountered map grids.
  78.     _gridLoc = _gridPOS;    //Set _gridLoc to the Map Grid (--ex: 108107).
  79.     _gridStatus = 1;    //Set the Grid Status to CONTESTED (1) - since it is a first-time encounter.
  80.     _gridTime = time;   //Store the time the grid was encountered (for use later).
  81.     _updateGridStatus = [_gridLoc,_gridStatus,_gridTime];   //Combine all three into an array for stowage.
  82.     VisitedStatus pushback _updateGridStatus;   //Add to the VisitedStatus array. Verbose but easy for me to understand right now.
  83.     if (21 > random 100) then { //21% chance to trigger.
  84.         hint "DEBUG: Spawn Chance"; //debug hint.
  85.         [] execVM "scripts\DynamicAISpawn.sqf"; //Spawn Enemy AI
  86.         };
  87.     //RPT DUMPS for debug.
  88.     diag_log format ["%1","================================"];
  89.     diag_log format ["%1","=====NEW GRID CONFIGURATION====="];
  90.     diag_log format ["%1 %2", "This is a new Grid", _gridLoc];
  91.     diag_log format ["%1 %2 %3 %4", "Grid", _gridLoc , "Set Status to:", _gridStatus];
  92.     diag_log format ["%1 %2 %3 %4", "Grid", _gridLoc , "Time:", _gridTime];
  93.     diag_log format ["%1 %2","Outgoing to VisitedStatus:",_updateGridStatus];
  94.     diag_log format ["%1","=========GRID CONFIG END========"];
  95.     diag_log format ["%1","================================"];
  96.     };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement