Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// @description scrGetPathCells(path, cellSize, gridWidth);
- /// @param path The index of the path you want to get the cells of.
- /// @param cellSize The width/height of cells in your grid, in pixels.
- /// @param gridWidth The width of the mp_grid used to make path, in cells.
- /*
- This script takes a path index and turns an array of cells that
- make up that path.
- The value of each cell is returned as a value made using:
- cellValue = (cellY * gridWidth) + cellX;
- This contains both the X and Y of the cell, to save
- returning a 2D array from this script. To get the cell X
- and Y from this value, you have to do:
- cellX = cellValue % gridWidth;
- cellY = cellValue div gridWidth;
- Note that this will provide you with the cell coordinates! To
- get the room coordinates, you will have to multiply these values
- by your cell size value.
- */
- //-- Grab Args --//
- var _path = argument0;
- var _cellSize = argument1;
- var _gridWidth = argument2;
- //-- Array to be returned --//
- cellList = [];
- //-- Iterate and find cells --//
- for (var i = 0; i < path_get_number(_path); i++)
- {
- var cellX = path_get_point_x(_path, i) div _cellSize;
- var cellY = path_get_point_y(_path, i) div _cellSize;
- cellList[i] = (cellY * _gridWidth) + cellX;
- }
- //-- Return the list of cells --//
- return cellList;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement