Advertisement
Guest User

scrGetPathCells

a guest
Feb 14th, 2019
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// @description scrGetPathCells(path, cellSize, gridWidth);
  2.  
  3. /// @param path      The index of the path you want to get the cells of.
  4. /// @param cellSize  The width/height of cells in your grid, in pixels.
  5. /// @param gridWidth The width of the mp_grid used to make path, in cells.
  6.  
  7. /*
  8.     This script takes a path index and turns an array of cells that
  9.     make up that path.
  10.    
  11.     The value of each cell is returned as a value made using:
  12.    
  13.     cellValue = (cellY * gridWidth) + cellX;
  14.    
  15.     This contains both the X and Y of the cell, to save
  16.     returning a 2D array from this script. To get the cell X
  17.     and Y from this value, you have to do:
  18.    
  19.     cellX = cellValue % gridWidth;
  20.     cellY = cellValue div gridWidth;
  21.    
  22.     Note that this will provide you with the cell coordinates! To
  23.     get the room coordinates, you will have to multiply these values
  24.     by your cell size value.
  25. */
  26.  
  27. //-- Grab Args --//
  28.     var _path      = argument0;
  29.     var _cellSize  = argument1;
  30.     var _gridWidth = argument2;
  31.    
  32. //-- Array to be returned --//
  33. cellList = [];
  34.    
  35. //-- Iterate and find cells --//
  36.     for (var i = 0; i < path_get_number(_path); i++)
  37.     {
  38.         var cellX   = path_get_point_x(_path, i) div _cellSize;
  39.         var cellY = path_get_point_y(_path, i) div _cellSize;
  40.        
  41.         cellList[i] = (cellY * _gridWidth) + cellX;
  42.     }
  43.    
  44. //-- Return the list of cells --//
  45. return cellList;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement